[Zodb-checkins] CVS: ZODB3/ZODB - fspack.py:1.1

Jeremy Hylton jeremy at zope.com
Thu May 1 14:09:13 EDT 2003


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv10359

Added Files:
	fspack.py 
Log Message:
New pack for FileStorage.


=== Added File ZODB3/ZODB/fspack.py === (731/831 lines abridged)
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""FileStorage helper to perform pack.

A storage contains an ordered set of object revisions.  When a storage
is packed, object revisions that are not reachable as of the pack time
are deleted.  The notion of reachability is complicated by
backpointers -- object revisions that point to earlier revisions of
the same object.

An object revisions is reachable at a certain time if it is reachable
from the revision of the root at that time or if it is reachable from
a backpointer after that time.
"""

# This module contains code backported from ZODB4 from the
# zodb.storage.file package.  It's been edited heavily to work with
# ZODB3 code and storage layout.

import os
import struct

from ZODB.referencesf import referencesf
from ZODB.utils import p64, u64, z64
from zLOG import LOG, BLATHER, WARNING, ERROR, PANIC

try:
    from ZODB.fsIndex import fsIndex
except ImportError:
    def fsIndex():
        return {}

# XXX errors
##from zodb.storage.file.errors import CorruptedError
##from zodb.storage.file.errors import CorruptedError, FileStorageFormatError

class CorruptedError(Exception):
    pass


[-=- -=- -=- 731 lines omitted -=- -=- -=-]

        if h.version:
            h.pnv = self.index.get(h.oid, 0)
            h.vprev = self.vindex.get(h.version, 0)
            self.vindex[h.version] = pos
        self.index[h.oid] = pos
        if h.version:
            self.vindex[h.version] = pos
        self._tfile.write(h.asString())
        self._tfile.write(data)
        if not data:
            # Packed records never have backpointers (?).
            # If there is no data, write a z64 backpointer.
            # This is a George Bailey event.
            self._tfile.write(z64)

    def copyRest(self, ipos):
        # After the pack time, all data records are copied.
        # Copy one txn at a time, using copy() for data.

        while ipos < self.file_end:
            th = self._read_txn_header(ipos)
            pos = self._tfile.tell()
            self._copier.setTxnPos(pos)
            self._tfile.write(th.asString())
            tend = ipos + th.tlen
            ipos += th.headerlen()

            while ipos < tend:
                h = self._read_data_header(ipos)
                ipos += h.recordlen()
                prev_txn = None
                if h.plen:
                    data = self._file.read(h.plen)
                else:
                    data = self.fetchBackpointer(h.oid, h.back)
                    if h.back:
                        prev_txn = self.getTxnFromData(h.oid, h.back)

                self._copier.copy(h.oid, h.serial, data, h.version,
                                  prev_txn, pos, self._tfile.tell())

            tlen = self._tfile.tell() - pos
            assert tlen == th.tlen
            self._tfile.write(p64(tlen))
            ipos += 8

            self.index.update(self.tindex)
            self.tindex.clear()
            self.vindex.update(self.tvindex)
            self.tvindex.clear()




More information about the Zodb-checkins mailing list