Commit bf9f99dd authored by Ondřej Kuzník's avatar Ondřej Kuzník
Browse files

Split backend destruction from resetting it

parent 7f22bac4
......@@ -433,71 +433,92 @@ backend_connect_task( void *ctx, void *arg )
}
void
backends_destroy( void )
backend_reset( LloadBackend *b )
{
while ( !LDAP_CIRCLEQ_EMPTY( &backend ) ) {
LloadBackend *b = LDAP_CIRCLEQ_FIRST( &backend );
while ( !LDAP_LIST_EMPTY( &b->b_connecting ) ) {
LloadPendingConnection *pending = LDAP_LIST_FIRST( &b->b_connecting );
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying backend uri='%s', numconns=%d, numbindconns=%d\n",
b->b_uri.bv_val, b->b_numconns, b->b_numbindconns );
Debug( LDAP_DEBUG_CONNS, "backend_reset: "
"destroying socket pending connect() fd=%d\n",
pending->fd );
while ( !LDAP_LIST_EMPTY( &b->b_connecting ) ) {
LloadPendingConnection *pending =
LDAP_LIST_FIRST( &b->b_connecting );
event_free( pending->event );
evutil_closesocket( pending->fd );
LDAP_LIST_REMOVE( pending, next );
ch_free( pending );
}
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_preparing ) ) {
LloadConnection *c = LDAP_CIRCLEQ_FIRST( &b->b_preparing );
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying socket pending connect() fd=%d\n",
pending->fd );
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "backend_reset: "
"destroying connection being set up connid=%lu\n",
c->c_connid );
event_free( pending->event );
evutil_closesocket( pending->fd );
LDAP_LIST_REMOVE( pending, next );
ch_free( pending );
}
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_preparing ) ) {
LloadConnection *c = LDAP_CIRCLEQ_FIRST( &b->b_preparing );
assert( c->c_live );
CONNECTION_DESTROY(c);
assert( !c );
}
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_bindconns ) ) {
LloadConnection *c = LDAP_CIRCLEQ_FIRST( &b->b_bindconns );
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying connection being set up connid=%lu\n",
c->c_connid );
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "backend_reset: "
"destroying bind connection connid=%lu, pending ops=%ld\n",
c->c_connid, c->c_n_ops_executing );
assert( c->c_live );
CONNECTION_DESTROY(c);
}
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_bindconns ) ) {
LloadConnection *c = LDAP_CIRCLEQ_FIRST( &b->b_bindconns );
assert( c->c_live );
CONNECTION_DESTROY(c);
assert( !c );
}
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_conns ) ) {
LloadConnection *c = LDAP_CIRCLEQ_FIRST( &b->b_conns );
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying bind connection connid=%lu, pending ops=%ld\n",
c->c_connid, c->c_n_ops_executing );
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "backend_reset: "
"destroying regular connection connid=%lu, pending ops=%ld\n",
c->c_connid, c->c_n_ops_executing );
assert( c->c_live );
CONNECTION_DESTROY(c);
}
while ( !LDAP_CIRCLEQ_EMPTY( &b->b_conns ) ) {
LloadConnection *c = LDAP_CIRCLEQ_FIRST( &b->b_conns );
assert( c->c_live );
CONNECTION_DESTROY(c);
assert( !c );
}
}
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying regular connection connid=%lu, pending "
"ops=%ld\n",
c->c_connid, c->c_n_ops_executing );
void
lload_backend_destroy( LloadBackend *b )
{
LloadBackend *next = LDAP_CIRCLEQ_LOOP_NEXT( &backend, b, b_next );
assert( c->c_live );
CONNECTION_DESTROY(c);
}
Debug( LDAP_DEBUG_CONNS, "lload_backend_destroy: "
"destroying backend uri='%s', numconns=%d, numbindconns=%d\n",
b->b_uri.bv_val, b->b_numconns, b->b_numbindconns );
backend_reset( b );
LDAP_CIRCLEQ_REMOVE( &backend, b, b_next );
if ( b == next ) {
current_backend = NULL;
} else {
current_backend = next;
}
ldap_pvt_thread_mutex_destroy( &b->b_mutex );
LDAP_CIRCLEQ_REMOVE( &backend, b, b_next );
ldap_pvt_thread_mutex_destroy( &b->b_mutex );
event_del( b->b_retry_event );
event_free( b->b_retry_event );
event_del( b->b_retry_event );
event_free( b->b_retry_event );
ch_free( b->b_host );
ch_free( b->b_uri.bv_val );
ch_free( b );
}
void
lload_backends_destroy( void )
{
while ( !LDAP_CIRCLEQ_EMPTY( &backend ) ) {
LloadBackend *b = LDAP_CIRCLEQ_FIRST( &backend );
ch_free( b->b_host );
ch_free( b->b_uri.bv_val );
ch_free( b );
lload_backend_destroy( b );
}
}
......@@ -1367,7 +1367,7 @@ lloadd_daemon( struct event_base *daemon_base )
t );
}
ldap_pvt_thread_pool_close( &connection_pool, 1 );
backends_destroy();
lload_backends_destroy();
clients_destroy();
lload_bindconf_free( &bindconf );
evdns_base_free( dnsbase, 0 );
......
......@@ -41,7 +41,9 @@ LDAP_SLAPD_F (void) backend_connect( evutil_socket_t s, short what, void *arg );
LDAP_SLAPD_F (void *) backend_connect_task( void *ctx, void *arg );
LDAP_SLAPD_F (void) backend_retry( LloadBackend *b );
LDAP_SLAPD_F (LloadConnection *) backend_select( LloadOperation *op, int *res );
LDAP_SLAPD_F (void) backends_destroy( void );
LDAP_SLAPD_F (void) backend_reset( LloadBackend *b );
LDAP_SLAPD_F (void) lload_backend_destroy( LloadBackend *b );
LDAP_SLAPD_F (void) lload_backends_destroy( void );
/*
* bind.c
......
Markdown is supported
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