Commit 66f06f3f authored by Ondřej Kuzník's avatar Ondřej Kuzník Committed by Ondřej Kuzník
Browse files

Initial extension to upstream selection

parent c91d61cf
......@@ -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);
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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 );
/*
......
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