1 /* trans.c - bdb backend transaction routines */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-bdb/trans.c,v 1.8.2.3 2008/02/11 23:26:46 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 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>
27 /* Congestion avoidance code
28 * for Deadlock Rollback
32 bdb_trans_backoff( int num_retries
)
37 unsigned long key
= 0;
38 unsigned long max_key
= -1;
39 struct timeval timeout
;
41 lutil_entropy( (unsigned char *) &key
, sizeof( unsigned long ));
43 for ( i
= 0; i
< num_retries
; i
++ ) {
48 delay
= 16384 * (key
* (double) pow_retries
/ (double) max_key
);
49 delay
= delay
? delay
: 1;
51 Debug( LDAP_DEBUG_TRACE
, "delay = %d, num_retries = %d\n", delay
, num_retries
, 0 );
53 timeout
.tv_sec
= delay
/ 1000000;
54 timeout
.tv_usec
= delay
% 1000000;
55 select( 0, NULL
, NULL
, NULL
, &timeout
);