Commit a029fbbb authored by Barry Warsaw's avatar Barry Warsaw

For alignment with ZODB4, renaming these storages for ZODB3 3.2.

bsddb3Storage becomes BDBStorage
Full becomes BDBFullStorage
Minimal becomes BDBMinimalStorage

Removing MinimalReplicated.py, Packless.py, and base.py
parent 65150b33
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"""Berkeley storage with full undo and versioning support. """Berkeley storage with full undo and versioning support.
""" """
__version__ = '$Revision: 1.61 $'.split()[-2:][0] __version__ = '$Revision: 1.62 $'.split()[-2:][0]
import time import time
import cPickle as pickle import cPickle as pickle
...@@ -64,7 +64,7 @@ except NameError: ...@@ -64,7 +64,7 @@ except NameError:
class Full(BerkeleyBase, ConflictResolvingStorage): class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
def _setupDBs(self): def _setupDBs(self):
# Data Type Assumptions: # Data Type Assumptions:
# #
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"""Berkeley storage without undo or versioning. """Berkeley storage without undo or versioning.
""" """
__version__ = '$Revision: 1.22 $'[-2:][0] __version__ = '$Revision: 1.23 $'[-2:][0]
# This uses the Dunn/Kuchling PyBSDDB v3 extension module available from # This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
# http://pybsddb.sourceforge.net. It is compatible with release 3.4 of # http://pybsddb.sourceforge.net. It is compatible with release 3.4 of
...@@ -45,7 +45,7 @@ except NameError: ...@@ -45,7 +45,7 @@ except NameError:
class Minimal(BerkeleyBase, ConflictResolvingStorage): class BDBMinimalStorage(BerkeleyBase, ConflictResolvingStorage):
def _setupDBs(self): def _setupDBs(self):
# Data Type Assumptions: # Data Type Assumptions:
# #
......
This diff is collapsed.
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from base import Base
from bsddb3 import db
from struct import pack, unpack
class Minimal(Base):
def _setupDbs(self):
# Supports Base framework
self._index=self._setupDB('current')
self._setupDB('pickle')
def load(self, oid, version):
self._lock_acquire()
try:
s=self._index[oid]
p=self._pickle[oid]
return p, s # pickle, serial
finally: self._lock_release()
def store(self, oid, serial, data, version, transaction):
if transaction is not self._transaction:
raise POSException.StorageTransactionError(self, transaction)
if version:
raise POSException.Unsupported, "Versions aren't supported"
self._lock_acquire()
try:
if self._index.has_key(oid):
oserial=self._index[oid]
if serial != oserial:
raise POSException.ConflictError(serials=(oserial, serial))
serial=self._serial
self._tmp.write(oid+pack(">I", len(data)))
self._tmp.write(data)
finally: self._lock_release()
return serial
def _finish(self, tid, u, d, e):
txn = self._env.txn_begin()
try:
serial_put=self._index.put
pickle_put=self._pickle.put
serial=self._serial
tmp=self._tmp
s=tmp.tell()
tmp.seek(0)
read=tmp.read
l=0
while l < s:
oid, ldata = unpack(">8sI", read(12))
data=read(ldata)
l=l+ldata+12
if ldata > s:
raise 'Temporary file corrupted'
serial_put(oid, serial, txn)
pickle_put(oid, data, txn)
tmp.seek(0)
if s > 999999: tmp.truncate()
except:
txn.abort()
raise
else:
txn.commit()
def pack(self, t, referencesf):
self._lock_acquire()
try:
# Build an index of *only* those objects reachable
# from the root.
index=self._pickle
rootl=['\0\0\0\0\0\0\0\0']
pop=rootl.pop
pindex={}
referenced=pindex.has_key
while rootl:
oid=pop()
if referenced(oid): continue
# Scan non-version pickle for references
p=index[oid]
pindex[oid]=1
referencesf(p, rootl)
# Now delete any unreferenced entries:
for oid in index.keys():
if not referenced(oid): del index[oid]
finally: self._lock_release()
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
""" Base module for BerkeleyStorage implementations """
__version__ ='$Revision: 1.6 $'[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. 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):
def __init__(self, name='', env=0, prefix="zodb_"):
if type(env) is type(''):
env=envFromString(env)
if not name: name=env
elif not name: name='bsddb3'
BaseStorage.__init__(self, name)
self._env=env
self._prefix=prefix
self._setupDbs()
self._tmp=tempfile.TemporaryFile()
self._tempdir = tempfile.tempdir
self._init_oid()
def _setupDB(self, name, flags=0):
"""Open an individual database and assign to an "_" attribute.
"""
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)
return d
def _setupDbs(self):
"""Set up the storages databases, typically using '_setupDB'.
"""
def _init_oid(self):
c=self._index.cursor()
v=c.get(db.DB_LAST)
if v: self._oid=v[0]
else: self._oid='\0\0\0\0\0\0\0\0'
_len=-1
def __len__(self):
l=self._len
if l < 0:
l=self._len=len(self._index)
return l
def new_oid(self, last=None):
# increment the cached length:
l=self._len
if l >= 0: self._len=l+1
return BaseStorage.new_oid(self, last)
def getSize(self):
# TBD
return 0
def _clear_temp(self):
self._tmp.seek(0)
def close(self):
"""Close the storage
by closing the databases it uses and closing it's environment.
"""
for name in self._dbnames():
getattr(self, '_'+name).close()
delattr(self, '_'+name)
self._env.close()
del self._env
def _dbnames(self):
"""Return a list of the names of the databases used by the storage.
"""
return ("index",)
def envFromString(name):
try:
if not os.path.exists(name): os.mkdir(name)
except:
raise "Error creating BerkeleyDB environment dir: %s" % name
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 DBError, msg:
raise BerkeleyDBError, "%s (%s)" % (BerkeleyDBError.__doc__, msg)
return e
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
# #
############################################################################## ##############################################################################
# Basic test framework class for both the Full and Minimal Berkeley storages # Basic test framework class for both the BDBFullStorage and BDBMinimalStorage
# Berkeley storages
import os import os
import errno import errno
from bsddb3Storage.BerkeleyBase import BerkeleyConfig from BDBStorage.BerkeleyBase import BerkeleyConfig
from ZODB.tests.StorageTestBase import StorageTestBase from ZODB.tests.StorageTestBase import StorageTestBase
DBHOME = 'test-db' DBHOME = 'test-db'
...@@ -63,10 +64,10 @@ class BerkeleyTestBase(StorageTestBase): ...@@ -63,10 +64,10 @@ class BerkeleyTestBase(StorageTestBase):
class MinimalTestBase(BerkeleyTestBase): class MinimalTestBase(BerkeleyTestBase):
from bsddb3Storage import Minimal from BDBStorage import BDBMinimalStorage
ConcreteStorage = Minimal.Minimal ConcreteStorage = BDBMinimalStorage.BDBMinimalStorage
class FullTestBase(BerkeleyTestBase): class FullTestBase(BerkeleyTestBase):
from bsddb3Storage import Full from BDBStorage import BDBFullStorage
ConcreteStorage = Full.Full ConcreteStorage = BDBFullStorage.BDBFullStorage
...@@ -18,7 +18,7 @@ import os ...@@ -18,7 +18,7 @@ import os
import errno import errno
from ZODB import DB from ZODB import DB
from bsddb3Storage.tests.BerkeleyTestBase import BerkeleyTestBase from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
DBHOME = 'test-db' DBHOME = 'test-db'
......
...@@ -21,10 +21,10 @@ from ZODB.referencesf import referencesf ...@@ -21,10 +21,10 @@ from ZODB.referencesf import referencesf
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from Persistence import Persistent from Persistence import Persistent
from bsddb3Storage.Full import Full from BDBStorage.BDBFullStorage import BDBFullStorage
from bsddb3Storage.Minimal import Minimal from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
from bsddb3Storage.BerkeleyBase import BerkeleyConfig from BDBStorage.BerkeleyBase import BerkeleyConfig
from bsddb3Storage.tests.BerkeleyTestBase import BerkeleyTestBase from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
ZERO = '\0'*8 ZERO = '\0'*8
...@@ -60,7 +60,7 @@ class TestAutopackBase(BerkeleyTestBase): ...@@ -60,7 +60,7 @@ class TestAutopackBase(BerkeleyTestBase):
class TestAutopack(TestAutopackBase): class TestAutopack(TestAutopackBase):
ConcreteStorage = Full ConcreteStorage = BDBFullStorage
def checkAutopack(self): def checkAutopack(self):
unless = self.failUnless unless = self.failUnless
...@@ -93,7 +93,7 @@ class TestAutopack(TestAutopackBase): ...@@ -93,7 +93,7 @@ class TestAutopack(TestAutopackBase):
class TestAutomaticClassicPack(TestAutopackBase): class TestAutomaticClassicPack(TestAutopackBase):
ConcreteStorage = Full ConcreteStorage = BDBFullStorage
def _config(self): def _config(self):
config = BerkeleyConfig() config = BerkeleyConfig()
...@@ -174,7 +174,7 @@ class TestAutomaticClassicPack(TestAutopackBase): ...@@ -174,7 +174,7 @@ class TestAutomaticClassicPack(TestAutopackBase):
class TestMinimalPack(TestAutopackBase): class TestMinimalPack(TestAutopackBase):
ConcreteStorage = Minimal ConcreteStorage = BDBMinimalStorage
def _config(self): def _config(self):
config = BerkeleyConfig() config = BerkeleyConfig()
......
...@@ -18,9 +18,9 @@ import os ...@@ -18,9 +18,9 @@ import os
import time import time
import unittest import unittest
from bsddb3Storage.BerkeleyBase import BerkeleyConfig from BDBStorage.BerkeleyBase import BerkeleyConfig
from bsddb3Storage.tests import BerkeleyTestBase from BDBStorage.tests import BerkeleyTestBase
from bsddb3Storage.Full import Full from BDBStorage.BDBFullStorage import BDBFullStorage
...@@ -97,9 +97,9 @@ class OpenRecoveryTest(BerkeleyTestBase.FullTestBase): ...@@ -97,9 +97,9 @@ class OpenRecoveryTest(BerkeleyTestBase.FullTestBase):
# This instance won't have the necessary attributes, so the creation # This instance won't have the necessary attributes, so the creation
# will fail. We want to be sure that everything gets cleaned up # will fail. We want to be sure that everything gets cleaned up
# enough to fix that and create a proper storage. # enough to fix that and create a proper storage.
self.assertRaises(AttributeError, Full, self._dir, config=c) self.assertRaises(AttributeError, BDBFullStorage, self._dir, config=c)
c = BerkeleyConfig() c = BerkeleyConfig()
s = Full(self._dir, config=c) s = BDBFullStorage(self._dir, config=c)
s.close() s.close()
......
...@@ -34,13 +34,13 @@ class InsertMixin: ...@@ -34,13 +34,13 @@ class InsertMixin:
class FullNewInsertsTest(ZODBTestBase, InsertMixin): class FullNewInsertsTest(ZODBTestBase, InsertMixin):
from bsddb3Storage import Full from BDBStorage import BDBFullStorage
ConcreteStorage = Full.Full ConcreteStorage = BDBFullStorage.BDBFullStorage
class MinimalNewInsertsTest(ZODBTestBase, InsertMixin): class MinimalNewInsertsTest(ZODBTestBase, InsertMixin):
from bsddb3Storage import Minimal from BDBStorage import BDBMinimalStorage
ConcreteStorage = Minimal.Minimal ConcreteStorage = BDBMinimalStorage.BDBMinimalStorage
......
...@@ -19,10 +19,10 @@ import unittest ...@@ -19,10 +19,10 @@ import unittest
from ZODB.utils import U64 from ZODB.utils import U64
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle from ZODB.tests.StorageTestBase import zodb_unpickle
from bsddb3Storage.Minimal import Minimal from BDBStorage.BDBMinimalStorage import BDBMinimalStorage
from bsddb3Storage.Full import Full from BDBStorage.BDBFullStorage import BDBFullStorage
from bsddb3Storage.tests.BerkeleyTestBase import BerkeleyTestBase from BDBStorage.tests.BerkeleyTestBase import BerkeleyTestBase
from bsddb3Storage.tests.ZODBTestBase import ZODBTestBase from BDBStorage.tests.ZODBTestBase import ZODBTestBase
from Persistence import Persistent from Persistence import Persistent
...@@ -36,7 +36,7 @@ class Object(Persistent): ...@@ -36,7 +36,7 @@ class Object(Persistent):
class WhiteboxLowLevelMinimal(BerkeleyTestBase): class WhiteboxLowLevelMinimal(BerkeleyTestBase):
ConcreteStorage = Minimal ConcreteStorage = BDBMinimalStorage
def checkTableConsistencyAfterCommit(self): def checkTableConsistencyAfterCommit(self):
unless = self.failIf unless = self.failIf
...@@ -80,7 +80,7 @@ class WhiteboxLowLevelMinimal(BerkeleyTestBase): ...@@ -80,7 +80,7 @@ class WhiteboxLowLevelMinimal(BerkeleyTestBase):
class WhiteboxHighLevelMinimal(ZODBTestBase): class WhiteboxHighLevelMinimal(ZODBTestBase):
ConcreteStorage = Minimal ConcreteStorage = BDBMinimalStorage
def checkReferenceCounting(self): def checkReferenceCounting(self):
eq = self.assertEqual eq = self.assertEqual
...@@ -167,7 +167,7 @@ class WhiteboxHighLevelMinimal(ZODBTestBase): ...@@ -167,7 +167,7 @@ class WhiteboxHighLevelMinimal(ZODBTestBase):
class WhiteboxHighLevelFull(ZODBTestBase): class WhiteboxHighLevelFull(ZODBTestBase):
ConcreteStorage = Full ConcreteStorage = BDBFullStorage
def checkReferenceCounting(self): def checkReferenceCounting(self):
eq = self.assertEqual eq = self.assertEqual
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
# #
############################################################################## ##############################################################################
# Test some simple ZODB level stuff common to both the Minimal and Full # Test some simple ZODB level stuff common to both the BDBMinimalStorage and
# storages, like transaction aborts and commits, changing objects, etc. # BDBFullStorage storages, like transaction aborts and commits, changing
# Doesn't test undo, versions, or packing. # objects, etc. Doesn't test undo, versions, or packing.
import time import time
import unittest import unittest
...@@ -69,13 +69,13 @@ class CommitAndRead: ...@@ -69,13 +69,13 @@ class CommitAndRead:
class MinimalCommitAndRead(ZODBTestBase, CommitAndRead): class MinimalCommitAndRead(ZODBTestBase, CommitAndRead):
from bsddb3Storage import Minimal from BDBStorage import BDBMinimalStorage
ConcreteStorage = Minimal.Minimal ConcreteStorage = BDBMinimalStorage.BDBMinimalStorage
class FullCommitAndRead(ZODBTestBase, CommitAndRead): class FullCommitAndRead(ZODBTestBase, CommitAndRead):
from bsddb3Storage import Full from BDBStorage import BDBFullStorage
ConcreteStorage = Full.Full ConcreteStorage = BDBFullStorage.BDBFullStorage
......
...@@ -65,7 +65,7 @@ from bsddb3 import db ...@@ -65,7 +65,7 @@ from bsddb3 import db
from ZODB import utils from ZODB import utils
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from bsddb3Storage.Full import Full from BDBStorage.BDBFullStorage import BDBFullStorage
PROGRAM = sys.argv[0] PROGRAM = sys.argv[0]
ZERO = '\0'*8 ZERO = '\0'*8
...@@ -157,7 +157,7 @@ def main(): ...@@ -157,7 +157,7 @@ def main():
# #
print >>sys.stderr, 'Opening destination BDB...' print >>sys.stderr, 'Opening destination BDB...'
t0 = time.time() t0 = time.time()
dstdb = Full(options.dest) dstdb = BDBFullStorage(options.dest)
t1 = time.time() t1 = time.time()
print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0) print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0)
......
...@@ -65,7 +65,7 @@ from bsddb3 import db ...@@ -65,7 +65,7 @@ from bsddb3 import db
from ZODB import utils from ZODB import utils
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from bsddb3Storage.Full import Full from BDBStorage.BDBFullStorage import BDBFullStorage
PROGRAM = sys.argv[0] PROGRAM = sys.argv[0]
ZERO = '\0'*8 ZERO = '\0'*8
...@@ -157,7 +157,7 @@ def main(): ...@@ -157,7 +157,7 @@ def main():
# #
print >>sys.stderr, 'Opening destination BDB...' print >>sys.stderr, 'Opening destination BDB...'
t0 = time.time() t0 = time.time()
## dstdb = Full(options.dest) ## dstdb = BDBFullStorage(options.dest)
dstdb = None dstdb = None
t1 = time.time() t1 = time.time()
print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0) print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0)
......
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