[Zodb-checkins] CVS: ZODB4/BDBStorage - BDBFullStorage.py:2.0

Barry Warsaw barry@wooz.org
Wed, 4 Dec 2002 14:41:52 -0500


Update of /cvs-repository/ZODB4/BDBStorage
In directory cvs.zope.org:/tmp/cvs-serv16693

Modified Files:
      Tag: 2.0
	BDBFullStorage.py 
Log Message:
Get rid of some pre-Python 2.2.2 b/c cruft.


=== Added File ZODB4/BDBStorage/BDBFullStorage.py === (1761/1861 lines abridged)
##############################################################################
#
# 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
#
##############################################################################

"""Berkeley storage with full undo and versioning support.
"""

__version__ = '$Revision: 2.0 $'.split()[-2:][0]

import sys
import time
import threading
import cPickle as pickle
from struct import pack, unpack

# This uses the Dunn/Kuchling PyBSDDB v3 extension module available from
# http://pybsddb.sourceforge.net.  It is compatible with release 3.4 of
# PyBSDDB3.  The only recommended version of BerkeleyDB is 4.0.14.
from bsddb3 import db

from ZODB import POSException
from ZODB.utils import p64, u64
from ZODB.Serialize import findrefs
from ZODB.TimeStamp import TimeStamp
from ZODB.ConflictResolution import ConflictResolvingStorage, ResolvedSerial

# BerkeleyBase.BerkeleyBase class provides some common functionality for both
# the Full and Minimal implementations.  It in turn inherits from
# ZODB.BaseStorage.BaseStorage which itself provides some common storage
# functionality.
from BDBStorage.BerkeleyBase import BerkeleyBase, PackStop, _WorkThread
from BDBStorage._helper import incr

ABORT = 'A'
COMMIT = 'C'
PRESENT = 'X'
ZERO = '\0'*8

# Special flag for uncreated objects (i.e. Does Not Exist)
DNE = '\377'*8

[-=- -=- -=- 1761 lines omitted -=- -=- -=-]

        returned.
        """
        # Let IndexError percolate up
        oid = self._oids.pop()
        data, version, lrevid = self._storage._loadSerialEx(oid, self.tid)
        return _Record(oid, self.tid, version, data, lrevid)



class _Record:
    # Object Id
    oid = None
    # Object serial number (i.e. revision id)
    serial = None
    # Version string
    version = None
    # Data pickle
    data = None
    # The pointer to the transaction containing the pickle data, if not None
    data_txn = None

    def __init__(self, oid, serial, version, data, data_txn):
        self.oid = oid
        self.serial = serial
        self.version = version
        self.data = data
        self.data_txn = data_txn



class _Autopack(_WorkThread):
    def __init__(self, storage, frequency, packtime, classicpack,
                 lastpacktime):
        _WorkThread.__init__(self, storage, frequency, 'autopacking')
        self._packtime = packtime
        self._classicpack = classicpack
        # Bookkeeping
        self._stop = False
        self._lastclassic = 0

    def _dowork(self, now):
        # Should we do a classic pack this time?
        if self._classicpack <= 0:
            classicp = False
        else:
            v = (self._lastclassic + 1) % self._classicpack
            self._lastclassic = v
            classicp = not v
        # Run the autopack phase
        self._storage.autopack(now - self._packtime, classicp)