bsddb.*open() methods cachesize parameter wouldn't work (raised an
internal bsddb.db exception when it was given).  The set_cachesize
call needed to be moved from the DB object to the DBEnv since the env
was introduced to allow for threading.

(will backport to 2.4)
This commit is contained in:
Gregory P. Smith 2006-04-12 20:35:02 +00:00
parent 14c6b4626f
commit 64029986bc
2 changed files with 10 additions and 8 deletions

View File

@ -287,10 +287,9 @@ def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
cachesize=None, lorder=None, hflags=0):
flags = _checkflag(flag, file)
e = _openDBEnv()
e = _openDBEnv(cachesize)
d = db.DB(e)
d.set_flags(hflags)
if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
if ffactor is not None: d.set_h_ffactor(ffactor)
@ -305,9 +304,8 @@ def btopen(file, flag='c', mode=0666,
pgsize=None, lorder=None):
flags = _checkflag(flag, file)
e = _openDBEnv()
e = _openDBEnv(cachesize)
d = db.DB(e)
if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
d.set_flags(btflags)
@ -324,9 +322,8 @@ def rnopen(file, flag='c', mode=0666,
rlen=None, delim=None, source=None, pad=None):
flags = _checkflag(flag, file)
e = _openDBEnv()
e = _openDBEnv(cachesize)
d = db.DB(e)
if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
d.set_flags(rnflags)
@ -339,8 +336,13 @@ def rnopen(file, flag='c', mode=0666,
#----------------------------------------------------------------------
def _openDBEnv():
def _openDBEnv(cachesize):
e = db.DBEnv()
if cachesize is not None:
if cachesize >= 20480:
e.set_cachesize(0, cachesize)
else:
raise error, "cachesize must be >= 20480"
e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL)
return e

View File

@ -14,7 +14,7 @@ class TestBSDDB(unittest.TestCase):
openflag = 'c'
def setUp(self):
self.f = self.openmethod[0](self.fname, self.openflag)
self.f = self.openmethod[0](self.fname, self.openflag, cachesize=32768)
self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='')
for k, v in self.d.iteritems():
self.f[k] = v