openldap/servers/slapd/back-bdb/trans.c

57 lines
1.3 KiB
C
Raw Normal View History

2003-07-01 19:55:18 +08:00
/* trans.c - bdb backend transaction routines */
/* $OpenLDAP$ */
2003-11-29 05:08:20 +08:00
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2008-01-08 08:19:56 +08:00
* Copyright 2000-2008 The OpenLDAP Foundation.
2003-11-29 05:08:20 +08:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
2003-07-01 19:55:18 +08:00
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include "back-bdb.h"
#include "lber_pvt.h"
#include "lutil.h"
2003-07-01 19:55:18 +08:00
/* 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( (unsigned char *) &key, sizeof( unsigned long ));
2003-07-01 19:55:18 +08:00
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;
Debug( LDAP_DEBUG_TRACE, "delay = %d, num_retries = %d\n", delay, num_retries, 0 );
timeout.tv_sec = delay / 1000000;
timeout.tv_usec = delay % 1000000;
select( 0, NULL, NULL, NULL, &timeout );
}