Back to index

openldap  2.4.31
trans.c
Go to the documentation of this file.
00001 /* trans.c - bdb backend transaction routines */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 #include <ac/string.h>
00021 
00022 #include "back-bdb.h"
00023 #include "lber_pvt.h"
00024 #include "lutil.h"
00025 
00026 
00027 /* Congestion avoidance code
00028  * for Deadlock Rollback
00029  */
00030 
00031 void
00032 bdb_trans_backoff( int num_retries )
00033 {
00034        int i;
00035        int delay = 0;
00036        int pow_retries = 1;
00037        unsigned long key = 0;
00038        unsigned long max_key = -1;
00039        struct timeval timeout;
00040 
00041        lutil_entropy( (unsigned char *) &key, sizeof( unsigned long ));
00042 
00043        for ( i = 0; i < num_retries; i++ ) {
00044               if ( i >= 5 ) break;
00045               pow_retries *= 4;
00046        }
00047 
00048        delay = 16384 * (key * (double) pow_retries / (double) max_key);
00049        delay = delay ? delay : 1;
00050 
00051        Debug( LDAP_DEBUG_TRACE,  "delay = %d, num_retries = %d\n", delay, num_retries, 0 );
00052 
00053        timeout.tv_sec = delay / 1000000;
00054        timeout.tv_usec = delay % 1000000;
00055        select( 0, NULL, NULL, NULL, &timeout );
00056 }