]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Convert backend and upstream management to use CIRCLEQ.
authorOndřej Kuzník <ondra@mistotebe.net>
Wed, 10 May 2017 15:00:32 +0000 (16:00 +0100)
committerOndřej Kuzník <okuznik@symas.com>
Tue, 17 Nov 2020 17:55:46 +0000 (17:55 +0000)
This alone doesn't make the server do a round robin.

servers/lloadd/backend.c
servers/lloadd/config.c
servers/lloadd/connection.c
servers/lloadd/daemon.c
servers/lloadd/slap.h
servers/lloadd/upstream.c

index c5fbeda858b050692fc6986073c657f5d147555b..b1ad7a31191c05fba205819c59e6439d1ecbc324 100644 (file)
@@ -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 );
index e3cb01cf6fe52703e427a78c1be15fd5fe9ad4b7..e81cadae34640c2a4c91105b2efc4b4accfca76f 100644 (file)
@@ -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;
index 1eb92c0a929dc3096dbdcc081a9ed386464732d6..9174412d6b271a938c02e92c518285cf4334ce70 100644 (file)
@@ -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 );
index 19a7f17c0870de3d2f1b2f8bb900612e0a3858b0..dd20c9db0fcc64a6b9ae5523125dd16241725e77 100644 (file)
@@ -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 );
 
index 3d7d208fe53fc121408bfa352c04c7acf90ed1e4..e60aaa5e0dcf675590ad1d6a348a2cb82420497d 100644 (file)
@@ -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;
 };
index ca75fe4e03c7293d206d83136d6c52ad13a68504..3e72a55427ce208a4ad7d6fc5cb2b9d351fd351d 100644 (file)
@@ -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;