Commit 5c618e89 authored by Barry Warsaw's avatar Barry Warsaw

Get ZERO from the package.

Remove __version__

ZODB4 will have two new methods in the storage api:

    get_version() -> string
    set_version(string)

Prepare for this now by changing the packtime table into an info
table, which is just a key/value mapping for meta-information about
the storage.  For now, the only key we define is `packtime' although
we're reserving `version' for ZODB4.
parent be790b50
############################################################################## ##############################################################################
# #
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. # Copyright (c) 2001 Zope Corporation and Contributors.
# All Rights Reserved. # All Rights Reserved.
# #
# This software is subject to the provisions of the Zope Public License, # This software is subject to the provisions of the Zope Public License,
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
############################################################################## ##############################################################################
"""Berkeley storage with full undo and versioning support. """Berkeley storage with full undo and versioning support.
"""
__version__ = '$Revision: 1.63 $'.split()[-2:][0] $Revision: 1.64 $
"""
import time import time
import cPickle as pickle import cPickle as pickle
...@@ -27,13 +27,12 @@ from ZODB.referencesf import referencesf ...@@ -27,13 +27,12 @@ from ZODB.referencesf import referencesf
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
from ZODB.ConflictResolution import ConflictResolvingStorage, ResolvedSerial from ZODB.ConflictResolution import ConflictResolvingStorage, ResolvedSerial
from BDBStorage import db from BDBStorage import db, ZERO
from BDBStorage.BerkeleyBase import BerkeleyBase, PackStop, _WorkThread from BDBStorage.BerkeleyBase import BerkeleyBase, PackStop, _WorkThread
ABORT = 'A' ABORT = 'A'
COMMIT = 'C' COMMIT = 'C'
PRESENT = 'X' PRESENT = 'X'
ZERO = '\0'*8
# Special flag for uncreated objects (i.e. Does Not Exist) # Special flag for uncreated objects (i.e. Does Not Exist)
DNE = '\377'*8 DNE = '\377'*8
...@@ -178,9 +177,15 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage): ...@@ -178,9 +177,15 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
# pending table is empty, the oids, pvids, and prevrevids tables # pending table is empty, the oids, pvids, and prevrevids tables
# must also be empty. # must also be empty.
# #
# packtime -- tid # info -- {key -> value}
# The time of the last pack. It is illegal to undo to before the # This table contains storage metadata information. The keys and
# last pack time. # values are simple strings of variable length. Here are the
# valid keys:
#
# packtime - time of the last pack. It is illegal to undo to
# before the last pack time.
#
# version - the version of the database (reserved for ZODB4)
# #
# objrevs -- {newserial+oid -> oldserial} # objrevs -- {newserial+oid -> oldserial}
# This table collects object revision information for packing # This table collects object revision information for packing
...@@ -223,7 +228,7 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage): ...@@ -223,7 +228,7 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
# Tables to support packing. # Tables to support packing.
self._objrevs = self._setupDB('objrevs', db.DB_DUP) self._objrevs = self._setupDB('objrevs', db.DB_DUP)
self._packmark = self._setupDB('packmark') self._packmark = self._setupDB('packmark')
self._packtime = self._setupDB('packtime') self._info = self._setupDB('info')
self._oidqueue = self._setupDB('oidqueue', 0, db.DB_QUEUE, 8) self._oidqueue = self._setupDB('oidqueue', 0, db.DB_QUEUE, 8)
self._delqueue = self._setupDB('delqueue', 0, db.DB_QUEUE, 8) self._delqueue = self._setupDB('delqueue', 0, db.DB_QUEUE, 8)
# Do recovery and consistency checks # Do recovery and consistency checks
...@@ -1032,13 +1037,7 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage): ...@@ -1032,13 +1037,7 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
self._lock_release() self._lock_release()
def _last_packtime(self): def _last_packtime(self):
packtimes = self._packtime.keys() return self._info.get('packtime', ZERO)
if len(packtimes) == 1:
return packtimes[0]
elif len(packtimes) == 0:
return ZERO
else:
assert False, 'too many packtimes'
def lastTransaction(self): def lastTransaction(self):
"""Return transaction id for last committed transaction""" """Return transaction id for last committed transaction"""
...@@ -1306,11 +1305,10 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage): ...@@ -1306,11 +1305,10 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
finally: finally:
self._lock_release() self._lock_release()
#
# Packing # Packing
# #
# There are two types of pack operations, the classic pack and the # There are two types of pack operations, the classic pack and the
# autopack. Autopack's sole job is to periodically delete non-current # autopack. Autopack's primary job is to periodically delete non-current
# object revisions. It runs in a thread and has an `autopack time' which # object revisions. It runs in a thread and has an `autopack time' which
# is essentially just a time in the past at which to autopack to. For # is essentially just a time in the past at which to autopack to. For
# example, you might set up autopack to run once per hour, packing away # example, you might set up autopack to run once per hour, packing away
...@@ -1333,7 +1331,6 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage): ...@@ -1333,7 +1331,6 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
# acquisition as granularly as possible so that packing doesn't block # acquisition as granularly as possible so that packing doesn't block
# other operations for too long. But remember we don't use Berkeley locks # other operations for too long. But remember we don't use Berkeley locks
# so we have to be careful about our application level locks. # so we have to be careful about our application level locks.
#
# First, the public API for classic pack # First, the public API for classic pack
def pack(self, t, zreferencesf): def pack(self, t, zreferencesf):
...@@ -1471,10 +1468,9 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage): ...@@ -1471,10 +1468,9 @@ class BDBFullStorage(BerkeleyBase, ConflictResolvingStorage):
if co: co.close() if co: co.close()
if ct: ct.close() if ct: ct.close()
# Note that before we commit this Berkeley transaction, we also need # Note that before we commit this Berkeley transaction, we also need
# to update the packtime table, so we can't have the possibility of a # to update the last packtime entry, so we can't have the possibility
# race condition with undoLog(). # of a race condition with undoLog().
self._packtime.truncate(txn) self._info.put('packtime', packtid, txn=txn)
self._packtime.put(packtid, PRESENT, txn=txn)
def _decrefPickle(self, oid, lrevid, txn): def _decrefPickle(self, oid, lrevid, txn):
if lrevid == DNE: if lrevid == DNE:
......
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