]> git.sur5r.net Git - openldap/commitdiff
Berkeley DB congestion avoidance
authorJong Hyuk Choi <jongchoi@openldap.org>
Tue, 1 Jul 2003 11:55:18 +0000 (11:55 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Tue, 1 Jul 2003 11:55:18 +0000 (11:55 +0000)
servers/slapd/back-bdb/Makefile.in
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-bdb/passwd.c
servers/slapd/back-bdb/proto-bdb.h
servers/slapd/back-bdb/trans.c [new file with mode: 0644]
servers/slapd/proto-slap.h

index 47a6d9a57bab3c3ca9ed7337e2f1ed353fc6caef..1ff4dbe15bcdb6fd1ed2a4a83aef6b35ca736a42 100644 (file)
@@ -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
index fd128d146a19adfccd7a91b1bf64fbebfe283b6f..c2df351f8756b327839674ce6453ca602ac08fb6 100644 (file)
@@ -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();
        }
 
index 824de2e67d1dffd025adfed571bf533948bedd07..3d382a2e42f2456a32c35892fdf534944a350a5b 100644 (file)
@@ -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();
        }
 
index 7844ce02614ef11e028d764e1c94248c281f0a6d..089808a92694fe023eaf9ba1b05439b9a1cae62a 100644 (file)
@@ -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();
        }
 
index 3e2f2a86c3b511f0762359c6909936e54b48d75d..9c390b3810646e063aed57eb5735f0785a554105 100644 (file)
@@ -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();
        }
 
index 1c96ace4286a30a86d529a4f489787f1518ad6ab..d847cd3ef5ebd8b3a219f310355ec6bb3a511c60 100644 (file)
@@ -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();
        }
 
index c99f9da36b8187b6a08322df22073dcddd9d9a94..1d3a55a31f4c5b53abbf5445bbb65df59c9bfcd6 100644 (file)
@@ -540,6 +540,12 @@ bdb_send_ldap_intermediate(
        struct berval *cookie );
 #endif
 
+/*
+ * trans.c
+ */
+
+void
+bdb_trans_backoff( int num_retries );
 
 LDAP_END_DECL
 
diff --git a/servers/slapd/back-bdb/trans.c b/servers/slapd/back-bdb/trans.c
new file mode 100644 (file)
index 0000000..51fecf4
--- /dev/null
@@ -0,0 +1,47 @@
+/* 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 );
+}
index e94158bf4448eef876e7b2d06c58684943c867ff..3148cd0ef992cd753bfd938af2b3203221dcc4b0 100644 (file)
@@ -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;