1/* $NetBSD$ */ 2 3/* trans.c - bdb backend transaction routines */ 4/* OpenLDAP: pkg/ldap/servers/slapd/back-bdb/trans.c,v 1.8.2.5 2010/04/13 20:23:26 kurt Exp */ 5/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2000-2010 The OpenLDAP Foundation. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted only as authorized by the OpenLDAP 12 * Public License. 13 * 14 * A copy of this license is available in the file LICENSE in the 15 * top-level directory of the distribution or, alternatively, at 16 * <http://www.OpenLDAP.org/license.html>. 17 */ 18 19#include "portable.h" 20 21#include <stdio.h> 22#include <ac/string.h> 23 24#include "back-bdb.h" 25#include "lber_pvt.h" 26#include "lutil.h" 27 28 29/* Congestion avoidance code 30 * for Deadlock Rollback 31 */ 32 33void 34bdb_trans_backoff( int num_retries ) 35{ 36 int i; 37 int delay = 0; 38 int pow_retries = 1; 39 unsigned long key = 0; 40 unsigned long max_key = -1; 41 struct timeval timeout; 42 43 lutil_entropy( (unsigned char *) &key, sizeof( unsigned long )); 44 45 for ( i = 0; i < num_retries; i++ ) { 46 if ( i >= 5 ) break; 47 pow_retries *= 4; 48 } 49 50 delay = 16384 * (key * (double) pow_retries / (double) max_key); 51 delay = delay ? delay : 1; 52 53 Debug( LDAP_DEBUG_TRACE, "delay = %d, num_retries = %d\n", delay, num_retries, 0 ); 54 55 timeout.tv_sec = delay / 1000000; 56 timeout.tv_usec = delay % 1000000; 57 select( 0, NULL, NULL, NULL, &timeout ); 58} 59