Commit 5bc1e1a3 authored by Jong Hyuk Choi's avatar Jong Hyuk Choi
Browse files

Berkeley DB congestion avoidance

parent 9deac09c
......@@ -6,12 +6,12 @@ SRCS = init.c tools.c config.c \
add.c bind.c compare.c delete.c modify.c modrdn.c search.c \
extended.c passwd.c referral.c operational.c \
attr.c index.c key.c dbcache.c filterindex.c \
dn2entry.c dn2id.c error.c id2entry.c idl.c nextid.c cache.c
dn2entry.c dn2id.c error.c id2entry.c idl.c nextid.c cache.c trans.c
OBJS = init.lo tools.lo config.lo \
add.lo bind.lo compare.lo delete.lo modify.lo modrdn.lo search.lo \
extended.lo passwd.lo referral.lo operational.lo \
attr.lo index.lo key.lo dbcache.lo filterindex.lo \
dn2entry.lo dn2id.lo error.lo id2entry.lo idl.lo nextid.lo cache.lo
dn2entry.lo dn2id.lo error.lo id2entry.lo idl.lo nextid.lo cache.lo trans.lo
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
......
......@@ -33,6 +33,8 @@ bdb_add(Operation *op, SlapReply *rs )
DB_LOCK lock;
int noop = 0;
int num_retries = 0;
#ifdef LDAP_SYNC
Operation* ps_list;
#endif
......@@ -96,6 +98,7 @@ retry: /* transaction retry */
rs->sr_text = "internal error";
goto return_results;
}
bdb_trans_backoff( ++num_retries );
ldap_pvt_thread_yield();
}
......
......@@ -33,6 +33,8 @@ bdb_delete( Operation *op, SlapReply *rs )
int noop = 0;
int num_retries = 0;
#ifdef LDAP_SYNC
Operation* ps_list;
#endif
......@@ -66,6 +68,7 @@ retry: /* transaction retry */
rs->sr_text = "internal error";
goto return_results;
}
bdb_trans_backoff( ++num_retries );
ldap_pvt_thread_yield();
}
......
......@@ -304,6 +304,8 @@ bdb_modify( Operation *op, SlapReply *rs )
int noop = 0;
int num_retries = 0;
#ifdef LDAP_SYNC
Operation* ps_list;
struct psid_entry *pm_list, *pm_prev;
......@@ -347,6 +349,7 @@ retry: /* transaction retry */
rs->sr_text = "internal error";
goto return_results;
}
bdb_trans_backoff( ++num_retries );
ldap_pvt_thread_yield();
}
......
......@@ -51,6 +51,8 @@ bdb_modrdn( Operation *op, SlapReply *rs )
int noop = 0;
int num_retries = 0;
#ifdef LDAP_SYNC
Operation *ps_list;
struct psid_entry *pm_list, *pm_prev;
......@@ -105,6 +107,7 @@ retry: /* transaction retry */
rs->sr_text = "internal error";
goto return_results;
}
bdb_trans_backoff( ++num_retries );
ldap_pvt_thread_yield();
}
......
......@@ -36,6 +36,8 @@ bdb_exop_passwd( Operation *op, SlapReply *rs )
u_int32_t locker = 0;
DB_LOCK lock;
int num_retries = 0;
assert( ber_bvcmp( &slap_EXOP_MODIFY_PASSWD, &op->oq_extended.rs_reqoid ) == 0 );
rc = slap_passwd_parse( op->oq_extended.rs_reqdata,
......@@ -118,6 +120,7 @@ retry: /* transaction retry */
rs->sr_text = "internal error";
goto done;
}
bdb_trans_backoff( ++num_retries );
ldap_pvt_thread_yield();
}
......
......@@ -540,6 +540,12 @@ bdb_send_ldap_intermediate(
struct berval *cookie );
#endif
/*
* trans.c
*/
void
bdb_trans_backoff( int num_retries );
LDAP_END_DECL
......
/* trans.c - bdb backend transaction routines */
/* $OpenLDAP$ */
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include "back-bdb.h"
#include "external.h"
#include "lber_pvt.h"
/* Congestion avoidance code
* for Deadlock Rollback
*/
void
bdb_trans_backoff( int num_retries )
{
int i;
int delay = 0;
int pow_retries = 1;
unsigned long key = 0;
unsigned long max_key = -1;
struct timeval timeout;
lutil_entropy( &key, sizeof( unsigned long ));
for ( i = 0; i < num_retries; i++ ) {
if ( i >= 5 ) break;
pow_retries *= 4;
}
delay = 16384 * (key * (double) pow_retries / (double) max_key);
delay = delay ? delay : 1;
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR, "delay = %d, num_retries = %d\n", delay, num_retries, 0 );
#else
Debug( LDAP_DEBUG_TRACE, "delay = %d, num_retries = %d\n", delay, num_retries, 0 );
#endif
timeout.tv_sec = delay / 1000000;
timeout.tv_usec = delay % 1000000;
select( 0, NULL, NULL, NULL, &timeout );
}
......@@ -1112,6 +1112,8 @@ LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) passwd_mutex;
#endif
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) gmtime_mutex;
LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) rand_mutex;
LDAP_SLAPD_V (AccessControl *) global_acl;
LDAP_SLAPD_V (ber_socket_t) dtblsize;
......
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