]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Initial extension to upstream selection
authorOndřej Kuzník <ondra@mistotebe.net>
Wed, 13 Dec 2017 15:56:10 +0000 (15:56 +0000)
committerOndřej Kuzník <okuznik@symas.com>
Tue, 17 Nov 2020 17:58:14 +0000 (17:58 +0000)
servers/lloadd/backend.c
servers/lloadd/bind.c
servers/lloadd/client.c
servers/lloadd/proto-lload.h

index 549cda89361220b76632da4e8ee724d531d7cae0..110b90d905def44eefc527f7d78647ae78054176 100644 (file)
@@ -176,7 +176,7 @@ fail:
 }
 
 LloadConnection *
-backend_select( LloadOperation *op )
+backend_select( LloadOperation *op, int *res )
 {
     LloadBackend *b, *first, *next;
 
@@ -184,6 +184,8 @@ backend_select( LloadOperation *op )
     first = b = current_backend;
     ldap_pvt_thread_mutex_unlock( &backend_mutex );
 
+    *res = LDAP_UNAVAILABLE;
+
     if ( !first ) {
         return NULL;
     }
@@ -203,6 +205,7 @@ backend_select( LloadOperation *op )
                     b->b_uri.bv_val );
             ldap_pvt_thread_mutex_unlock( &b->b_mutex );
             b = next;
+            *res = LDAP_BUSY;
             continue;
         }
 
@@ -215,6 +218,9 @@ backend_select( LloadOperation *op )
         } else {
             head = &b->b_conns;
         }
+        if ( !LDAP_CIRCLEQ_EMPTY( head ) ) {
+            *res = LDAP_BUSY;
+        }
 
         LDAP_CIRCLEQ_FOREACH ( c, head, c_next ) {
             ldap_pvt_thread_mutex_lock( &c->c_io_mutex );
@@ -243,6 +249,7 @@ backend_select( LloadOperation *op )
                 CONNECTION_UNLOCK_INCREF(c);
 
                 ldap_pvt_thread_mutex_unlock( &b->b_mutex );
+                *res = LDAP_SUCCESS;
                 return c;
             }
             CONNECTION_UNLOCK(c);
index 84d6a51160b58e62ff940eceb8faddadcfb6a5da..612e53d498bac8cfe10e1568956005166fa44162 100644 (file)
@@ -263,7 +263,7 @@ int
 request_bind( LloadConnection *client, LloadOperation *op )
 {
     LloadConnection *upstream;
-    int rc = LDAP_SUCCESS;
+    int res, rc = LDAP_SUCCESS;
 
     /* protect the Bind operation */
     op->o_client_refcnt++;
@@ -278,13 +278,12 @@ request_bind( LloadConnection *client, LloadOperation *op )
     assert( rc == LDAP_SUCCESS );
     CONNECTION_UNLOCK_INCREF(client);
 
-    upstream = backend_select( op );
+    upstream = backend_select( op, &res );
     if ( !upstream ) {
         Debug( LDAP_DEBUG_STATS, "client_bind: "
                 "connid=%lu, msgid=%d no available connection found\n",
                 op->o_client_connid, op->o_client_msgid );
-        operation_send_reject(
-                op, LDAP_UNAVAILABLE, "no connections available", 1 );
+        operation_send_reject( op, res, "no connections available", 1 );
         CONNECTION_LOCK_DECREF(client);
         op->o_client_refcnt--;
         operation_destroy_from_client( op );
index dc0bf388e50d85094da15fef6e53a4dd1f1b23f7..122a26d432a0401e8a2c97259fca645114d7d06b 100644 (file)
@@ -86,19 +86,18 @@ request_process( LloadConnection *client, LloadOperation *op )
     BerElement *output;
     LloadConnection *upstream;
     ber_int_t msgid;
-    int rc = LDAP_SUCCESS;
+    int res, rc = LDAP_SUCCESS;
 
     op->o_client_refcnt++;
     CONNECTION_UNLOCK_INCREF(client);
 
-    upstream = backend_select( op );
+    upstream = backend_select( op, &res );
     if ( !upstream ) {
         Debug( LDAP_DEBUG_STATS, "request_process: "
                 "connid=%lu, msgid=%d no available connection found\n",
                 op->o_client_connid, op->o_client_msgid );
 
-        operation_send_reject(
-                op, LDAP_UNAVAILABLE, "no connections available", 1 );
+        operation_send_reject( op, res, "no connections available", 1 );
         goto fail;
     }
     op->o_upstream = upstream;
index f3cecd4c739b380fc34b2215f96a90b499f20bbc..61b901317c61d7e336b9dd4a8ba2d378adcfeb4f 100644 (file)
@@ -43,7 +43,7 @@ struct config_reply_s; /* config.h */
 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 );
+LDAP_SLAPD_F (LloadConnection *) backend_select( LloadOperation *op, int *res );
 LDAP_SLAPD_F (void) backends_destroy( void );
 
 /*