1 /* trans.c - bdb backend transaction routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
28 /* Congestion avoidance code
29 * for Deadlock Rollback
33 bdb_trans_backoff( int num_retries )
38 unsigned long key = 0;
39 unsigned long max_key = -1;
40 struct timeval timeout;
42 lutil_entropy( (unsigned char *) &key, sizeof( unsigned long ));
44 for ( i = 0; i < num_retries; i++ ) {
49 delay = 16384 * (key * (double) pow_retries / (double) max_key);
50 delay = delay ? delay : 1;
52 Debug( LDAP_DEBUG_TRACE, "delay = %d, num_retries = %d\n", delay, num_retries, 0 );
54 timeout.tv_sec = delay / 1000000;
55 timeout.tv_usec = delay % 1000000;
56 select( 0, NULL, NULL, NULL, &timeout );