[Python-checkins] python/dist/src/Lib/bsddb dbtables.py,1.2,1.3 dbutils.py,1.1,1.2
loewis@users.sourceforge.net
loewis@users.sourceforge.net
Sat, 23 Nov 2002 03:26:09 -0800
Update of /cvsroot/python/python/dist/src/Lib/bsddb
In directory sc8-pr-cvs1:/tmp/cvs-serv21585/Lib/bsddb
Modified Files:
dbtables.py dbutils.py
Log Message:
Merge with bsddb3 2002.11.23.10.42.36
Index: dbtables.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/bsddb/dbtables.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dbtables.py 19 Nov 2002 17:48:49 -0000 1.2
--- dbtables.py 23 Nov 2002 11:26:06 -0000 1.3
***************
*** 2,5 ****
--- 2,6 ----
#
# Copyright (C) 2000, 2001 by Autonomous Zone Industries
+ # Copyright (C) 2002 Gregory P. Smith
#
# License: This is free software. You may use this software for any
***************
*** 55,58 ****
--- 56,66 ----
return s[:len(self.prefix)] == self.prefix
+ class PostfixCond(Cond):
+ """Acts as a condition function for matching a string postfix"""
+ def __init__(self, postfix):
+ self.postfix = postfix
+ def __call__(self, s):
+ return s[-len(self.postfix):] == self.postfix
+
class LikeCond(Cond):
"""
***************
*** 524,538 ****
# succeeds, add row to our match list.
if not condition or condition(data) :
! # only create new entries in matcing_rowids on
! # the first pass, otherwise reject the
! # rowid as it must not have matched
! # the previous passes
! if column_num == 0 :
! if not matching_rowids.has_key(rowid) :
! matching_rowids[rowid] = {}
! if savethiscolumndata :
! matching_rowids[rowid][column] = data
! else :
! rejected_rowids[rowid] = rowid
else :
if matching_rowids.has_key(rowid) :
--- 532,539 ----
# succeeds, add row to our match list.
if not condition or condition(data) :
! if not matching_rowids.has_key(rowid) :
! matching_rowids[rowid] = {}
! if savethiscolumndata :
! matching_rowids[rowid][column] = data
else :
if matching_rowids.has_key(rowid) :
Index: dbutils.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/bsddb/dbutils.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** dbutils.py 19 Nov 2002 08:09:52 -0000 1.1
--- dbutils.py 23 Nov 2002 11:26:07 -0000 1.2
***************
*** 1,10 ****
#------------------------------------------------------------------------
#
- # In my performance tests, using this (as in dbtest.py test4) is
- # slightly slower than simply compiling _db.c with MYDB_THREAD
- # undefined to prevent multithreading support in the C module.
- # Using NoDeadlockDb also prevent deadlocks from mutliple processes
- # accessing the same database.
- #
# Copyright (C) 2000 Autonomous Zone Industries
#
--- 1,4 ----
***************
*** 19,23 ****
#
# Note: I don't know how useful this is in reality since when a
! # DBDeadlockError happens the current transaction is supposed to be
# aborted. If it doesn't then when the operation is attempted again
# the deadlock is still happening...
--- 13,17 ----
#
# Note: I don't know how useful this is in reality since when a
! # DBLockDeadlockError happens the current transaction is supposed to be
# aborted. If it doesn't then when the operation is attempted again
# the deadlock is still happening...
***************
*** 35,43 ****
del sleep
! import _db
! _deadlock_MinSleepTime = 1.0/64 # always sleep at least N seconds between retrys
! _deadlock_MaxSleepTime = 1.0 # never sleep more than N seconds between retrys
def DeadlockWrap(function, *_args, **_kwargs):
--- 29,39 ----
del sleep
! import _bsddb
! _deadlock_MinSleepTime = 1.0/64 # always sleep at least N seconds between retrys
! _deadlock_MaxSleepTime = 3.14159 # never sleep more than N seconds between retrys
+ _deadlock_VerboseFile = None # Assign a file object to this for a "sleeping"
+ # message to be written to it each retry
def DeadlockWrap(function, *_args, **_kwargs):
***************
*** 45,51 ****
function in case of a database deadlock.
! This is a DeadlockWrapper method which DB calls can be made using to
! preform infinite retrys with sleeps in between when a DBLockDeadlockError
! exception is raised in a database call:
d = DB(...)
--- 41,50 ----
function in case of a database deadlock.
! This is a function intended to be used to wrap database calls such
! that they perform retrys with exponentially backing off sleeps in
! between when a DBLockDeadlockError exception is raised.
!
! A 'max_retries' parameter may optionally be passed to prevent it
! from retrying forever (in which case the exception will be reraised).
d = DB(...)
***************
*** 54,62 ****
"""
sleeptime = _deadlock_MinSleepTime
! while (1) :
try:
return apply(function, _args, _kwargs)
except _db.DBLockDeadlockError:
! print 'DeadlockWrap sleeping ', sleeptime
_sleep(sleeptime)
# exponential backoff in the sleep time
--- 53,65 ----
"""
sleeptime = _deadlock_MinSleepTime
! max_retries = _kwargs.get('max_retries', -1)
! if _kwargs.has_key('max_retries'):
! del _kwargs['max_retries']
! while 1:
try:
return apply(function, _args, _kwargs)
except _db.DBLockDeadlockError:
! if _deadlock_VerboseFile:
! _deadlock_VerboseFile.write('dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime)
_sleep(sleeptime)
# exponential backoff in the sleep time
***************
*** 64,67 ****
--- 67,73 ----
if sleeptime > _deadlock_MaxSleepTime :
sleeptime = _deadlock_MaxSleepTime
+ max_retries = max_retries - 1
+ if max_retries == -1:
+ raise