Commit 4acb7afa authored by Chris McDonough's avatar Chris McDonough

Merge from PacklessBerkeley3Storage branch.

parent cd119fc0
......@@ -88,9 +88,9 @@ counting garbage-collection strategy which necessitates packing only when
the stored data has cyclically-referenced garbage.
"""
__version__ ='$Revision: 1.4 $'[11:-2]
__version__ ='$Revision: 1.5 $'[11:-2]
from base import Base
from base import Base, DBError
from base import BerkeleyDBError
from bsddb3 import db
from struct import pack, unpack
......@@ -129,6 +129,9 @@ class Packless(Base):
"""
return 'current', 'referenceCount', 'oreferences', 'opickle'
def _abort(self):
pass
def load(self, oid, version):
self._lock_acquire()
try:
......@@ -136,7 +139,7 @@ class Packless(Base):
s=self._index[oid]
p=self._opickle[oid]
return p, s # pickle, serial
except db.error, msg:
except DBError, msg:
raise BerkeleyDBError, (
"%s (%s)" % (BerkeleyDBError.__doc__, msg)
)
......@@ -200,8 +203,8 @@ class Packless(Base):
referenced=references.has_key
# Create refcnt
if not referenceCount_get(oid, txn):
referenceCount_put(oid, '\0'*intlen, txn)
if not referenceCount_get(oid, txn=txn):
referenceCount_put(oid, '\0'*intlen, txn=txn)
# zeros[oid]=1
# ^^^^^^^^^^^^
# this should happen when ZODB import is fixed
......@@ -228,7 +231,7 @@ class Packless(Base):
c.delete()
# decrement refcnt:
rc=unpack(">i",
referenceCount_get(roid, txn))[0]
referenceCount_get(roid,txn=txn))[0]
rc=rc-1
if rc < 0:
# This should never happen
......@@ -248,7 +251,7 @@ class Packless(Base):
oreferences_put(oid, roid, txn)
# Create/update refcnt
rcs=referenceCount_get(roid, txn)
rcs=referenceCount_get(roid, txn=txn)
if rcs:
rc=unpack(">i", rcs)[0]
if rc==0:
......@@ -275,7 +278,7 @@ class Packless(Base):
tmp.seek(0)
if fsize > MAXTEMPFSIZE: tmp.truncate()
except db.error, msg:
except DBError, msg:
try:
txn.abort()
except db.error, msg:
......@@ -310,7 +313,7 @@ class Packless(Base):
roid=roid[1]
# decrement refcnt:
rc=referenceCount_get(roid, txn)
rc=referenceCount_get(roid, txn=txn)
if rc:
rc=unpack(">i", rc)[0]-1
if rc < 0:
......
......@@ -84,19 +84,29 @@
##############################################################################
""" Base module for BerkeleyStorage implementations """
__version__ ='$Revision: 1.4 $'[11:-2]
__version__ ='$Revision: 1.5 $'[11:-2]
from ZODB.BaseStorage import BaseStorage
from ZODB import POSException
from bsddb3 import db
import os, tempfile
try:
DB = db.DB
DBEnv = db.DBEnv
DBError = db.DBError
except:
DB = db.Db
DBEnv = db.DbEnv
DBError = db.error
class BerkeleyDBError(POSException.POSError):
""" A BerkeleyDB exception occurred. This probably indicates that
there is a low memory condition, a tempfile space shortage, or
a space shortage in the directory which houses the BerkeleyDB log
files. Check available tempfile space, logfile space, and RAM and
restart the server process."""
restart the server process. This error could have additionally
been caused by too few locks available to BerkeleyDB for the
transaction size you were attempting to commit."""
class Base(BaseStorage):
......@@ -118,7 +128,7 @@ class Base(BaseStorage):
def _setupDB(self, name, flags=0):
"""Open an individual database and assign to an "_" attribute.
"""
d=db.Db(self._env)
d=DB(self._env)
if flags: d.set_flags(flags)
d.open(self._prefix+name, db.DB_BTREE, db.DB_CREATE)
setattr(self, '_'+name, d)
......@@ -152,12 +162,6 @@ class Base(BaseStorage):
# TBD
return 0
def _finish(self, tid, user, desc, ext):
self._txn.commit()
def _abort(self, tid, user, desc, ext):
self._txn.abort()
def _clear_temp(self):
self._tmp.seek(0)
......@@ -182,12 +186,13 @@ def envFromString(name):
if not os.path.exists(name): os.mkdir(name)
except:
raise "Error creating BerkeleyDB environment dir: %s" % name
e=db.DbEnv()
e=DBEnv()
e.set_lk_max(10000) # this can be overridden in the DB_CONFIG file
try:
e.open(name,
db.DB_CREATE | db.DB_RECOVER
| db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_TXN
)
except db.error, msg:
except DBError, msg:
raise BerkeleyDBError, "%s (%s)" % (BerkeleyDBError.__doc__, msg)
return e
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment