Commit 407659d6 authored by Barry Warsaw's avatar Barry Warsaw

__init__(): Argument env must now be either None or a string. It did

    not work to pass in a DBEnv object, and that isn't the right way
    to increase the lock size anyway (should use a DB_CONFIG file as
    per the BerkeleyDB specs).
parent 20fff0d3
...@@ -25,7 +25,7 @@ from bsddb3 import db ...@@ -25,7 +25,7 @@ from bsddb3 import db
from ZODB import POSException from ZODB import POSException
from ZODB.BaseStorage import BaseStorage from ZODB.BaseStorage import BaseStorage
# $Revision: 1.8 $ # $Revision: 1.9 $
__version__ = '0.1' __version__ = '0.1'
...@@ -33,24 +33,22 @@ __version__ = '0.1' ...@@ -33,24 +33,22 @@ __version__ = '0.1'
class BerkeleyBase(BaseStorage): class BerkeleyBase(BaseStorage):
"""Base storage for Minimal and Full Berkeley implementations.""" """Base storage for Minimal and Full Berkeley implementations."""
def __init__(self, name, env=None, prefix="zodb_"): def __init__(self, name, env=None, prefix='zodb_'):
"""Create a new storage. """Create a new storage.
name is an arbitrary name for this storage. It is returned by the name is an arbitrary name for this storage. It is returned by the
getName() method. getName() method.
env is the database environment name, used to handle more advanced Optional env is the database environment name, essentially the name of
BSDDB functionality such as transactions. If env is a non-empty a directory into which BerkeleyDB will store all its supporting files.
string, it is passed directly to DbEnv().open(), which in turn is If env is a non-empty string, it is passed directly to DbEnv().open(),
passed to the BSDDB function DBEnv->open() as the db_home parameter. which in turn is passed to the BerkeleyDB function
DBEnv->open() as the db_home parameter.
If env is not a string, it must be an already existing DbEnv() Optional prefix is the string to prepend to name when passed to
object. DB.open() as the dbname parameter. IOW, prefix+name is passed to the
BerkeleyDb function DB->open() as the database parameter. It defaults
prefix is the string to prepend to name when passed to DB.open() as to "zodb_".
the dbname parameter. IOW, prefix+name is passed to the BSDDB
function DB->open() as the database parameter. It defaults to
"zodb_".
""" """
# sanity check arguments # sanity check arguments
...@@ -60,17 +58,21 @@ class BerkeleyBase(BaseStorage): ...@@ -60,17 +58,21 @@ class BerkeleyBase(BaseStorage):
if env is None: if env is None:
env = name env = name
if isinstance(env, StringType): if env == '':
if env == '': raise TypeError, 'environment name is empty'
raise TypeError, 'environment name is empty' elif not isinstance(env, StringType):
env = env_from_string(env) # We used to test isinstance(env, db.DBEnv) but that isn't a valid
elif not isinstance(env, db.DBEnv): # test since db.DBEnv() is a factory function, not a class.
raise TypeError, 'env must be a string or DBEnv instance: %s' % env # AFAIK, there's no way to pass an existing DBEnv into this
# constructor. Note that the most likely reason for wanting to do
# this is to increase the lock size of the environment. Use a
# DB_CONFIG file for that instead (see www.sleepycat.com).
raise TypeError, 'env must be a string: %s' % env
BaseStorage.__init__(self, name) BaseStorage.__init__(self, name)
# Initialize a few other things # Initialize a few other things
self._env = env self._env = env_from_string(env)
self._prefix = prefix self._prefix = prefix
self._commitlog = None self._commitlog = None
# Give the subclasses a chance to interpose into the database setup # Give the subclasses a chance to interpose into the database setup
...@@ -85,8 +87,8 @@ class BerkeleyBase(BaseStorage): ...@@ -85,8 +87,8 @@ class BerkeleyBase(BaseStorage):
# JF: unlinking might be too inefficient. JH: might use mmap # JF: unlinking might be too inefficient. JH: might use mmap
# files. BAW: maybe just truncate the file, or write a length # files. BAW: maybe just truncate the file, or write a length
# into the headers and just zero out the length. # into the headers and just zero out the length.
self._commitlog.close(unlink=1) ## self._commitlog.close(unlink=1)
self._commitlog = None ## self._commitlog = None
def _setupDB(self, name, flags=0): def _setupDB(self, name, flags=0):
"""Open an individual database with the given flags. """Open an individual database with the given flags.
......
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