Commit 58a880bc authored by Ondřej Kuzník's avatar Ondřej Kuzník Committed by Ondřej Kuzník
Browse files

Convert backend and upstream management to use CIRCLEQ.

This alone doesn't make the server do a round robin.
parent 643194e7
......@@ -97,7 +97,7 @@ backend_select( Operation *op )
/* TODO: Two runs, one with trylock, then one actually locked if we don't
* find anything? */
LDAP_STAILQ_FOREACH ( b, &backend, b_next ) {
LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) {
struct ConnSt *head;
Connection *c;
......@@ -118,10 +118,7 @@ backend_select( Operation *op )
head = &b->b_conns;
}
/* TODO: Use CIRCLEQ so that we can do a natural round robin over the
* backend's connections? */
LDAP_LIST_FOREACH( c, head, c_next )
{
LDAP_CIRCLEQ_FOREACH ( c, head, c_next ) {
ldap_pvt_thread_mutex_lock( &c->c_io_mutex );
CONNECTION_LOCK(c);
if ( c->c_state == SLAP_C_READY && !c->c_pendingber &&
......@@ -284,25 +281,25 @@ backend_connect_task( void *ctx, void *arg )
void
backends_destroy( void )
{
Backend *b;
while ( (b = LDAP_STAILQ_FIRST( &backend )) ) {
Connection *c;
while ( !LDAP_CIRCLEQ_EMPTY( &backend ) ) {
Backend *b = LDAP_CIRCLEQ_FIRST( &backend );
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying backend uri='%s', numconns=%d, numbindconns=%d\n",
b->b_bindconf.sb_uri.bv_val, b->b_numconns, b->b_numbindconns );
while ( (c = LDAP_LIST_FIRST( &b->b_bindconns )) ) {
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_bindconns ) ) {
Connection *c = LDAP_CIRCLEQ_FIRST( &b->b_bindconns );
CONNECTION_LOCK(c);
UPSTREAM_DESTROY(c);
}
while ( (c = LDAP_LIST_FIRST( &b->b_conns )) ) {
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_conns ) ) {
Connection *c = LDAP_CIRCLEQ_FIRST( &b->b_conns );
CONNECTION_LOCK(c);
UPSTREAM_DESTROY(c);
}
LDAP_STAILQ_REMOVE_HEAD( &backend, b_next );
LDAP_CIRCLEQ_REMOVE( &backend, b, b_next );
ldap_pvt_thread_mutex_destroy( &b->b_mutex );
event_del( b->b_retry_event );
......
......@@ -112,7 +112,7 @@ static ConfigDriver config_tls_option;
static ConfigDriver config_tls_config;
#endif
slap_b_head backend = LDAP_STAILQ_HEAD_INITIALIZER(backend);
slap_b_head backend = LDAP_CIRCLEQ_HEAD_INITIALIZER(backend);
enum {
CFG_ACL = 1,
......@@ -462,8 +462,8 @@ config_backend( ConfigArgs *c )
b = ch_calloc( 1, sizeof(Backend) );
LDAP_LIST_INIT( &b->b_conns );
LDAP_LIST_INIT( &b->b_bindconns );
LDAP_CIRCLEQ_INIT( &b->b_conns );
LDAP_CIRCLEQ_INIT( &b->b_bindconns );
b->b_numconns = 1;
b->b_numbindconns = 1;
......@@ -595,7 +595,7 @@ done:
if ( rc ) {
ch_free( b );
} else {
LDAP_STAILQ_INSERT_TAIL( &backend, b, b_next );
LDAP_CIRCLEQ_INSERT_TAIL( &backend, b, b_next );
}
return rc;
......
......@@ -155,7 +155,7 @@ connection_init( ber_socket_t s, const char *peername, int flags )
c->c_next_msgid = 1;
c->c_refcnt = c->c_live = 1;
LDAP_LIST_ENTRY_INIT( c, c_next );
LDAP_CIRCLEQ_ENTRY_INIT( c, c_next );
ldap_pvt_thread_mutex_init( &c->c_mutex );
ldap_pvt_thread_mutex_init( &c->c_io_mutex );
......
......@@ -1313,7 +1313,7 @@ slapd_daemon( struct event_base *daemon_base )
}
}
LDAP_STAILQ_FOREACH ( b, &backend, b_next ) {
LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) {
struct event *retry_event =
evtimer_new( daemon_base, backend_connect, b );
......
......@@ -121,7 +121,7 @@ typedef union Sockaddr {
extern int slap_inet4or6;
#endif
typedef LDAP_STAILQ_HEAD(BeSt, Backend) slap_b_head;
typedef LDAP_CIRCLEQ_HEAD(BeSt, Backend) slap_b_head;
LDAP_SLAPD_V (slap_b_head) backend;
......@@ -253,12 +253,12 @@ struct Backend {
int b_numconns, b_numbindconns;
int b_bindavail, b_active, b_opening;
LDAP_LIST_HEAD(ConnSt, Connection) b_conns, b_bindconns;
LDAP_CIRCLEQ_HEAD(ConnSt, Connection) b_conns, b_bindconns;
long b_max_pending, b_max_conn_pending;
long b_n_ops_executing;
LDAP_STAILQ_ENTRY(Backend) b_next;
LDAP_CIRCLEQ_ENTRY(Backend) b_next;
};
typedef int (*OperationHandler)( Operation *op, BerElement *ber );
......@@ -393,7 +393,7 @@ struct Connection {
long c_n_ops_completed; /* num of ops completed */
/* Upstream: Protected by its backend's mutex */
LDAP_LIST_ENTRY( Connection ) c_next;
LDAP_CIRCLEQ_ENTRY( Connection ) c_next;
void *c_private;
};
......
......@@ -845,11 +845,11 @@ upstream_init( ber_socket_t s, Backend *b )
}
if ( is_bindconn ) {
LDAP_LIST_INSERT_HEAD( &b->b_bindconns, c, c_next );
LDAP_CIRCLEQ_INSERT_HEAD( &b->b_bindconns, c, c_next );
c->c_type = SLAP_C_BIND;
b->b_bindavail++;
} else {
LDAP_LIST_INSERT_HEAD( &b->b_conns, c, c_next );
LDAP_CIRCLEQ_INSERT_HEAD( &b->b_conns, c, c_next );
b->b_active++;
}
......@@ -899,10 +899,11 @@ upstream_destroy( Connection *c )
}
ldap_pvt_thread_mutex_lock( &b->b_mutex );
LDAP_LIST_REMOVE( c, c_next );
if ( c->c_type == SLAP_C_BIND ) {
LDAP_CIRCLEQ_REMOVE( &b->b_bindconns, c, c_next );
b->b_bindavail--;
} else {
LDAP_CIRCLEQ_REMOVE( &b->b_conns, c, c_next );
b->b_active--;
}
b->b_n_ops_executing -= c->c_n_ops_executing;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment