Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-bdb / trans.c
blobdf8365122a4dbdf73762f0dfd5e148ec3d683663
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.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
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>.
17 #include "portable.h"
19 #include <stdio.h>
20 #include <ac/string.h>
22 #include "back-bdb.h"
23 #include "lber_pvt.h"
24 #include "lutil.h"
27 /* Congestion avoidance code
28 * for Deadlock Rollback
31 void
32 bdb_trans_backoff( int num_retries )
34 int i;
35 int delay = 0;
36 int pow_retries = 1;
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++ ) {
44 if ( i >= 5 ) break;
45 pow_retries *= 4;
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 );