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 ...@@ -88,9 +88,9 @@ counting garbage-collection strategy which necessitates packing only when
the stored data has cyclically-referenced garbage. 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 base import BerkeleyDBError
from bsddb3 import db from bsddb3 import db
from struct import pack, unpack from struct import pack, unpack
...@@ -129,6 +129,9 @@ class Packless(Base): ...@@ -129,6 +129,9 @@ class Packless(Base):
""" """
return 'current', 'referenceCount', 'oreferences', 'opickle' return 'current', 'referenceCount', 'oreferences', 'opickle'
def _abort(self):
pass
def load(self, oid, version): def load(self, oid, version):
self._lock_acquire() self._lock_acquire()
try: try:
...@@ -136,7 +139,7 @@ class Packless(Base): ...@@ -136,7 +139,7 @@ class Packless(Base):
s=self._index[oid] s=self._index[oid]
p=self._opickle[oid] p=self._opickle[oid]
return p, s # pickle, serial return p, s # pickle, serial
except db.error, msg: except DBError, msg:
raise BerkeleyDBError, ( raise BerkeleyDBError, (
"%s (%s)" % (BerkeleyDBError.__doc__, msg) "%s (%s)" % (BerkeleyDBError.__doc__, msg)
) )
...@@ -200,8 +203,8 @@ class Packless(Base): ...@@ -200,8 +203,8 @@ class Packless(Base):
referenced=references.has_key referenced=references.has_key
# Create refcnt # Create refcnt
if not referenceCount_get(oid, txn): if not referenceCount_get(oid, txn=txn):
referenceCount_put(oid, '\0'*intlen, txn) referenceCount_put(oid, '\0'*intlen, txn=txn)
# zeros[oid]=1 # zeros[oid]=1
# ^^^^^^^^^^^^ # ^^^^^^^^^^^^
# this should happen when ZODB import is fixed # this should happen when ZODB import is fixed
...@@ -228,7 +231,7 @@ class Packless(Base): ...@@ -228,7 +231,7 @@ class Packless(Base):
c.delete() c.delete()
# decrement refcnt: # decrement refcnt:
rc=unpack(">i", rc=unpack(">i",
referenceCount_get(roid, txn))[0] referenceCount_get(roid,txn=txn))[0]
rc=rc-1 rc=rc-1
if rc < 0: if rc < 0:
# This should never happen # This should never happen
...@@ -248,7 +251,7 @@ class Packless(Base): ...@@ -248,7 +251,7 @@ class Packless(Base):
oreferences_put(oid, roid, txn) oreferences_put(oid, roid, txn)
# Create/update refcnt # Create/update refcnt
rcs=referenceCount_get(roid, txn) rcs=referenceCount_get(roid, txn=txn)
if rcs: if rcs:
rc=unpack(">i", rcs)[0] rc=unpack(">i", rcs)[0]
if rc==0: if rc==0:
...@@ -275,7 +278,7 @@ class Packless(Base): ...@@ -275,7 +278,7 @@ class Packless(Base):
tmp.seek(0) tmp.seek(0)
if fsize > MAXTEMPFSIZE: tmp.truncate() if fsize > MAXTEMPFSIZE: tmp.truncate()
except db.error, msg: except DBError, msg:
try: try:
txn.abort() txn.abort()
except db.error, msg: except db.error, msg:
...@@ -310,7 +313,7 @@ class Packless(Base): ...@@ -310,7 +313,7 @@ class Packless(Base):
roid=roid[1] roid=roid[1]
# decrement refcnt: # decrement refcnt:
rc=referenceCount_get(roid, txn) rc=referenceCount_get(roid, txn=txn)
if rc: if rc:
rc=unpack(">i", rc)[0]-1 rc=unpack(">i", rc)[0]-1
if rc < 0: if rc < 0:
......
...@@ -84,19 +84,29 @@ ...@@ -84,19 +84,29 @@
############################################################################## ##############################################################################
""" Base module for BerkeleyStorage implementations """ """ Base module for BerkeleyStorage implementations """
__version__ ='$Revision: 1.4 $'[11:-2] __version__ ='$Revision: 1.5 $'[11:-2]
from ZODB.BaseStorage import BaseStorage from ZODB.BaseStorage import BaseStorage
from ZODB import POSException from ZODB import POSException
from bsddb3 import db from bsddb3 import db
import os, tempfile 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): class BerkeleyDBError(POSException.POSError):
""" A BerkeleyDB exception occurred. This probably indicates that """ A BerkeleyDB exception occurred. This probably indicates that
there is a low memory condition, a tempfile space shortage, or there is a low memory condition, a tempfile space shortage, or
a space shortage in the directory which houses the BerkeleyDB log a space shortage in the directory which houses the BerkeleyDB log
files. Check available tempfile space, logfile space, and RAM and 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): class Base(BaseStorage):
...@@ -118,7 +128,7 @@ class Base(BaseStorage): ...@@ -118,7 +128,7 @@ class Base(BaseStorage):
def _setupDB(self, name, flags=0): def _setupDB(self, name, flags=0):
"""Open an individual database and assign to an "_" attribute. """Open an individual database and assign to an "_" attribute.
""" """
d=db.Db(self._env) d=DB(self._env)
if flags: d.set_flags(flags) if flags: d.set_flags(flags)
d.open(self._prefix+name, db.DB_BTREE, db.DB_CREATE) d.open(self._prefix+name, db.DB_BTREE, db.DB_CREATE)
setattr(self, '_'+name, d) setattr(self, '_'+name, d)
...@@ -152,12 +162,6 @@ class Base(BaseStorage): ...@@ -152,12 +162,6 @@ class Base(BaseStorage):
# TBD # TBD
return 0 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): def _clear_temp(self):
self._tmp.seek(0) self._tmp.seek(0)
...@@ -182,12 +186,13 @@ def envFromString(name): ...@@ -182,12 +186,13 @@ def envFromString(name):
if not os.path.exists(name): os.mkdir(name) if not os.path.exists(name): os.mkdir(name)
except: except:
raise "Error creating BerkeleyDB environment dir: %s" % name 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: try:
e.open(name, e.open(name,
db.DB_CREATE | db.DB_RECOVER db.DB_CREATE | db.DB_RECOVER
| db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_TXN | 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) raise BerkeleyDBError, "%s (%s)" % (BerkeleyDBError.__doc__, msg)
return e 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