Blame view

neo/storage/database/manager.py 21.3 KB
Aurel committed
1
#
Julien Muchembled committed
2
# Copyright (C) 2006-2015  Nexedi SA
Grégory Wisniewski committed
3
#
Aurel committed
4 5 6 7
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Grégory Wisniewski committed
8
#
Aurel committed
9 10 11 12 13 14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
Julien Muchembled committed
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Aurel committed
16

Julien Muchembled committed
17
from collections import defaultdict
Julien Muchembled committed
18
from functools import wraps
Julien Muchembled committed
19
from neo.lib import logging, util
Julien Muchembled committed
20
from neo.lib.protocol import ZERO_TID, BackendNotImplemented
Grégory Wisniewski committed
21

Julien Muchembled committed
22
def lazymethod(func):
Julien Muchembled committed
23 24 25 26
    def getter(self):
        cls = self.__class__
        name = func.__name__
        assert name not in cls.__dict__
Julien Muchembled committed
27 28 29 30 31 32
        setattr(cls, name, func(self))
        return getattr(self, name)
    return property(getter, doc=func.__doc__)

def fallback(func):
    def warn(self):
Julien Muchembled committed
33 34
        logging.info("Fallback to generic/slow implementation of %s."
            " It should be overridden by backend storage (%s).",
Julien Muchembled committed
35 36 37
            func.__name__, self.__class__.__name__)
        return func
    return lazymethod(wraps(func)(warn))
Julien Muchembled committed
38

Julien Muchembled committed
39 40 41 42 43 44
def splitOIDField(tid, oids):
    if len(oids) % 8:
        raise DatabaseFailure('invalid oids length for tid %s: %s'
            % (tid, len(oids)))
    return [oids[i:i+8] for i in xrange(0, len(oids), 8)]

Grégory Wisniewski committed
45 46 47
class CreationUndone(Exception):
    pass

Yoshinori Okuji committed
48 49 50
class DatabaseManager(object):
    """This class only describes an interface for database managers."""

Julien Muchembled committed
51 52 53
    ENGINES = ()

    def __init__(self, database, engine=None, wait=0):
Grégory Wisniewski committed
54 55 56
        """
            Initialize the object.
        """
Julien Muchembled committed
57 58 59 60 61
        if engine:
            if engine not in self.ENGINES:
                raise ValueError("Unsupported engine: %r not in %r"
                                 % (engine, self.ENGINES))
            self._engine = engine
Vincent Pelletier committed
62
        self._wait = wait
Vincent Pelletier committed
63 64
        self._parse(database)

Julien Muchembled committed
65 66 67 68 69 70 71 72 73
    def __getattr__(self, attr):
        if attr == "_getPartition":
            np = self.getNumPartitions()
            value = lambda x: x % np
        else:
            return self.__getattribute__(attr)
        setattr(self, attr, value)
        return value

Vincent Pelletier committed
74 75 76
    def _parse(self, database):
        """Called during instanciation, to process database parameter."""
        pass
Grégory Wisniewski committed
77

Julien Muchembled committed
78
    def setup(self, reset=0):
Julien Muchembled committed
79 80 81 82
        """Set up a database, discarding existing data first if reset is True
        """
        if reset:
            self.erase()
Julien Muchembled committed
83
        self._uncommitted_data = defaultdict(int)
Julien Muchembled committed
84
        self._setup()
Julien Muchembled committed
85

Julien Muchembled committed
86
    def _setup(self):
Julien Muchembled committed
87
        """To be overriden by the backend to set up a database
Julien Muchembled committed
88 89

        It must recover self._uncommitted_data from temporary object table.
Julien Muchembled committed
90 91 92
        _uncommitted_data is already instantiated and must be updated with
        refcounts to data of write-locked objects, except in case of undo,
        where the refcount is increased later, when the object is read-locked.
Julien Muchembled committed
93
        Keys are data ids and values are number of references.
Julien Muchembled committed
94
        """
Grégory Wisniewski committed
95
        raise NotImplementedError
Grégory Wisniewski committed
96

Julien Muchembled committed
97 98 99
    def doOperation(self, app):
        pass

Julien Muchembled committed
100 101 102
    def commit(self):
        pass

Grégory Wisniewski committed
103 104 105 106
    def getConfiguration(self, key):
        """
            Return a configuration value, returns None if not found or not set
        """
Grégory Wisniewski committed
107
        raise NotImplementedError
Yoshinori Okuji committed
108

Grégory Wisniewski committed
109 110 111 112
    def setConfiguration(self, key, value):
        """
            Set a configuration value
        """
Julien Muchembled committed
113 114
        self._setConfiguration(key, value)
        self.commit()
Grégory Wisniewski committed
115 116

    def _setConfiguration(self, key, value):
Grégory Wisniewski committed
117
        raise NotImplementedError
Yoshinori Okuji committed
118

Grégory Wisniewski committed
119 120
    def getUUID(self):
        """
Julien Muchembled committed
121
            Load a NID from a database.
Grégory Wisniewski committed
122
        """
Julien Muchembled committed
123 124 125
        nid = self.getConfiguration('nid')
        if nid is not None:
            return int(nid)
Grégory Wisniewski committed
126

Julien Muchembled committed
127
    def setUUID(self, nid):
Grégory Wisniewski committed
128
        """
Julien Muchembled committed
129
            Store a NID into a database.
Grégory Wisniewski committed
130
        """
Julien Muchembled committed
131
        self.setConfiguration('nid', str(nid))
Grégory Wisniewski committed
132

Yoshinori Okuji committed
133
    def getNumPartitions(self):
Grégory Wisniewski committed
134 135 136 137 138 139
        """
            Load the number of partitions from a database.
        """
        n = self.getConfiguration('partitions')
        if n is not None:
            return int(n)
Yoshinori Okuji committed
140 141

    def setNumPartitions(self, num_partitions):
Grégory Wisniewski committed
142 143 144 145
        """
            Store the number of partitions into a database.
        """
        self.setConfiguration('partitions', num_partitions)
Julien Muchembled committed
146
        try:
Julien Muchembled committed
147
            del self._getPartition
Julien Muchembled committed
148 149
        except AttributeError:
            pass
Yoshinori Okuji committed
150

Aurel committed
151
    def getNumReplicas(self):
Grégory Wisniewski committed
152 153 154 155 156 157 158 159 160 161 162 163
        """
            Load the number of replicas from a database.
        """
        n = self.getConfiguration('replicas')
        if n is not None:
            return int(n)

    def setNumReplicas(self, num_replicas):
        """
            Store the number of replicas into a database.
        """
        self.setConfiguration('replicas', num_replicas)
Aurel committed
164

Yoshinori Okuji committed
165
    def getName(self):
Grégory Wisniewski committed
166 167 168 169
        """
            Load a name from a database.
        """
        return self.getConfiguration('name')
Yoshinori Okuji committed
170 171

    def setName(self, name):
Grégory Wisniewski committed
172 173 174 175
        """
            Store a name into a database.
        """
        self.setConfiguration('name', name)
Yoshinori Okuji committed
176 177

    def getPTID(self):
Grégory Wisniewski committed
178 179 180
        """
            Load a Partition Table ID from a database.
        """
Julien Muchembled committed
181 182
        ptid = self.getConfiguration('ptid')
        if ptid is not None:
Julien Muchembled committed
183
            return int(ptid)
Yoshinori Okuji committed
184 185

    def setPTID(self, ptid):
Grégory Wisniewski committed
186 187 188
        """
            Store a Partition Table ID into a database.
        """
Grégory Wisniewski committed
189 190 191 192
        if ptid is not None:
            assert isinstance(ptid, (int, long)), ptid
            ptid = str(ptid)
        self.setConfiguration('ptid', ptid)
Grégory Wisniewski committed
193

Julien Muchembled committed
194 195 196 197
    def getBackupTID(self):
        return util.bin(self.getConfiguration('backup_tid'))

    def setBackupTID(self, backup_tid):
Julien Muchembled committed
198 199 200
        tid = util.dump(backup_tid)
        logging.debug('backup_tid = %s', tid)
        return self.setConfiguration('backup_tid', tid)
Julien Muchembled committed
201

Julien Muchembled committed
202 203 204 205 206 207 208 209 210
    def _setPackTID(self, tid):
        self._setConfiguration('_pack_tid', tid)

    def _getPackTID(self):
        try:
            return int(self.getConfiguration('_pack_tid'))
        except TypeError:
            return -1

Yoshinori Okuji committed
211
    def getPartitionTable(self):
Julien Muchembled committed
212
        """Return a whole partition table as a sequence of rows. Each row
Julien Muchembled committed
213
        is again a tuple of an offset (row ID), the NID of a storage
Yoshinori Okuji committed
214
        node, and a cell state."""
Grégory Wisniewski committed
215
        raise NotImplementedError
Yoshinori Okuji committed
216

Julien Muchembled committed
217 218 219 220 221 222 223 224
    def getLastTID(self, max_tid):
        """Return greatest tid in trans table that is <= given 'max_tid'

        Required only to import a DB using Importer backend.
        max_tid must be in unpacked format.
        """
        raise NotImplementedError

Julien Muchembled committed
225
    def _getLastIDs(self):
Grégory Wisniewski committed
226
        raise NotImplementedError
Yoshinori Okuji committed
227

Julien Muchembled committed
228
    def getLastIDs(self):
Julien Muchembled committed
229
        trans, obj, oid = self._getLastIDs()
Julien Muchembled committed
230 231 232 233 234 235
        if trans:
            tid = max(trans.itervalues())
            if obj:
                tid = max(tid, max(obj.itervalues()))
        else:
            tid = max(obj.itervalues()) if obj else None
Julien Muchembled committed
236 237 238 239 240 241
        # TODO: Replication can't be resumed from the tids in 'trans' and 'obj'
        #       because outdated cells are writable and may contain recently
        #       committed data. We must save somewhere where replication was
        #       interrupted and return this information. For the moment, we
        #       tell the replicator to resume from the beginning.
        trans = obj = {}
Julien Muchembled committed
242
        return tid, trans, obj, oid
Julien Muchembled committed
243

Julien Muchembled committed
244
    def _getUnfinishedTIDDict(self):
Grégory Wisniewski committed
245
        raise NotImplementedError
Yoshinori Okuji committed
246

Julien Muchembled committed
247 248 249 250 251 252 253
    def getUnfinishedTIDDict(self):
        trans, obj = self._getUnfinishedTIDDict()
        obj = dict.fromkeys(obj)
        obj.update(trans)
        p64 = util.p64
        return {p64(ttid): None if tid is None else p64(tid)
                for ttid, tid in obj.iteritems()}
Yoshinori Okuji committed
254

Julien Muchembled committed
255 256 257 258 259 260
    @fallback
    def getLastObjectTID(self, oid):
        """Return the latest tid of given oid or None if it does not exist"""
        r = self.getObject(oid)
        return r and r[0]

Julien Muchembled committed
261 262 263 264 265 266 267 268 269 270 271 272 273
    def _getNextTID(self, partition, oid, tid):
        """
        partition (int)
            Must be the result of (oid % self.getPartition(oid))
        oid (int)
            Identifier of object to retrieve.
        tid (int)
            Exact serial to retrieve.

        If tid is the last revision of oid, None is returned.
        """
        raise NotImplementedError

Vincent Pelletier committed
274 275 276 277 278 279 280 281 282 283
    def _getObject(self, oid, tid=None, before_tid=None):
        """
        oid (int)
            Identifier of object to retrieve.
        tid (int, None)
            Exact serial to retrieve.
        before_tid (packed, None)
            Serial to retrieve is the highest existing one strictly below this
            value.
        """
Grégory Wisniewski committed
284
        raise NotImplementedError
Yoshinori Okuji committed
285

Julien Muchembled committed
286
    def getObject(self, oid, tid=None, before_tid=None):
Vincent Pelletier committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
        """
        oid (packed)
            Identifier of object to retrieve.
        tid (packed, None)
            Exact serial to retrieve.
        before_tid (packed, None)
            Serial to retrieve is the highest existing one strictly below this
            value.

        Return value:
            None: Given oid doesn't exist in database.
            False: No record found, but another one exists for given oid.
            6-tuple: Record content.
                - record serial (packed)
                - serial or next record modifying object (packed, None)
                - compression (boolean-ish, None)
                - checksum (integer, None)
                - data (binary string, None)
                - data_serial (packed, None)
        """
        u64 = util.u64
Julien Muchembled committed
308 309 310 311 312 313 314 315 316 317 318
        r = self._getObject(u64(oid), tid and u64(tid),
                            before_tid and u64(before_tid))
        try:
            serial, next_serial, compression, checksum, data, data_serial = r
        except TypeError:
            # See if object exists at all
            return (tid or before_tid) and self.getLastObjectTID(oid) and False
        return (util.p64(serial),
                None if next_serial is None else util.p64(next_serial),
                compression, checksum, data,
                None if data_serial is None else util.p64(data_serial))
Vincent Pelletier committed
319

Julien Muchembled committed
320
    def changePartitionTable(self, ptid, cell_list, reset=False):
Yoshinori Okuji committed
321 322
        """Change a part of a partition table. The list of cells is
        a tuple of tuples, each of which consists of an offset (row ID),
Julien Muchembled committed
323
        the NID of a storage node, and a cell state. The Partition
Julien Muchembled committed
324 325
        Table ID must be stored as well. If reset is True, existing data
        is first thrown away."""
Grégory Wisniewski committed
326
        raise NotImplementedError
Yoshinori Okuji committed
327

Julien Muchembled committed
328
    def dropPartitions(self, offset_list):
Julien Muchembled committed
329 330
        """Delete all data for specified partitions"""
        raise NotImplementedError
Grégory Wisniewski committed
331

Yoshinori Okuji committed
332 333
    def dropUnfinishedData(self):
        """Drop any unfinished data from a database."""
Grégory Wisniewski committed
334
        raise NotImplementedError
Yoshinori Okuji committed
335

Yoshinori Okuji committed
336 337 338 339
    def storeTransaction(self, tid, object_list, transaction, temporary = True):
        """Store a transaction temporarily, if temporary is true. Note
        that this transaction is not finished yet. The list of objects
        contains tuples, each of which consists of an object ID,
Julien Muchembled committed
340
        a data_id and object serial.
Yoshinori Okuji committed
341
        The transaction is either None or a tuple of the list of OIDs,
Vincent Pelletier committed
342 343
        user information, a description, extension information and transaction
        pack state (True for packed)."""
Grégory Wisniewski committed
344
        raise NotImplementedError
Yoshinori Okuji committed
345

Julien Muchembled committed
346
    def _pruneData(self, data_id_list):
Julien Muchembled committed
347 348 349 350 351
        """To be overriden by the backend to delete any unreferenced data

        'unreferenced' means:
        - not in self._uncommitted_data
        - and not referenced by a fully-committed object (storage should have
Julien Muchembled committed
352
          an index or a refcount of all data ids of all objects)
Julien Muchembled committed
353 354 355
        """
        raise NotImplementedError

Julien Muchembled committed
356
    def storeData(self, checksum, data, compression):
Julien Muchembled committed
357 358 359 360 361 362 363
        """To be overriden by the backend to store object raw data

        If same data was already stored, the storage only has to check there's
        no hash collision.
        """
        raise NotImplementedError

Julien Muchembled committed
364
    def holdData(self, checksum_or_id, *args):
Julien Muchembled committed
365
        """Store raw data of temporary object
Julien Muchembled committed
366

Julien Muchembled committed
367 368 369
        If 'checksum_or_id' is a checksum, it must be the result of
        makeChecksum(data) and extra parameters must be (data, compression)
        where 'compression' indicates if 'data' is compressed.
Julien Muchembled committed
370
        A volatile reference is set to this data until 'releaseData' is called
Julien Muchembled committed
371
        with this checksum.
Julien Muchembled committed
372 373
        If called with only an id, it only increment the volatile
        reference to the data matching the id.
Julien Muchembled committed
374
        """
Julien Muchembled committed
375 376 377
        if args:
            checksum_or_id = self.storeData(checksum_or_id, *args)
        self._uncommitted_data[checksum_or_id] += 1
Julien Muchembled committed
378
        return checksum_or_id
Julien Muchembled committed
379

Julien Muchembled committed
380 381
    def releaseData(self, data_id_list, prune=False):
        """Release 1 volatile reference to given list of data ids
Julien Muchembled committed
382 383 384 385 386

        If 'prune' is true, any data that is not referenced anymore (either by
        a volatile reference or by a fully-committed object) is deleted.
        """
        refcount = self._uncommitted_data
Julien Muchembled committed
387 388
        for data_id in data_id_list:
            count = refcount[data_id] - 1
Julien Muchembled committed
389
            if count:
Julien Muchembled committed
390
                refcount[data_id] = count
Julien Muchembled committed
391
            else:
Julien Muchembled committed
392
                del refcount[data_id]
Julien Muchembled committed
393
        if prune:
Julien Muchembled committed
394 395
            self._pruneData(data_id_list)
            self.commit()
Julien Muchembled committed
396

Julien Muchembled committed
397
    @fallback
Vincent Pelletier committed
398 399 400 401 402 403
    def _getDataTID(self, oid, tid=None, before_tid=None):
        """
        Return a 2-tuple:
        tid (int)
            tid corresponding to received parameters
        serial
Julien Muchembled committed
404
            data tid of the found record
Vincent Pelletier committed
405

Julien Muchembled committed
406 407 408 409 410
        (None, None) is returned if requested object and transaction
        could not be found.

        This method only exists for performance reasons, by not returning data:
        _getObject already returns these values but it is slower.
Vincent Pelletier committed
411
        """
Julien Muchembled committed
412
        r = self._getObject(oid, tid, before_tid)
Julien Muchembled committed
413
        return (r[0], r[-1]) if r else (None, None)
Vincent Pelletier committed
414

Vincent Pelletier committed
415
    def findUndoTID(self, oid, tid, ltid, undone_tid, transaction_object):
Vincent Pelletier committed
416 417 418 419 420
        """
        oid
            Object OID
        tid
            Transation doing the undo
Vincent Pelletier committed
421 422 423
        ltid
            Upper (exclued) bound of transactions visible to transaction doing
            the undo.
Vincent Pelletier committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
        undone_tid
            Transaction to undo
        transaction_object
            Object data from memory, if it was modified by running
            transaction.
            None if is was not modified by running transaction.

        Returns a 3-tuple:
        current_tid (p64)
            TID of most recent version of the object client's transaction can
            see. This is used later to detect current conflicts (eg, another
            client modifying the same object in parallel)
        data_tid (int)
            TID containing (without indirection) the data prior to undone
            transaction.
            None if object doesn't exist prior to transaction being undone
              (its creation is being undone).
        is_current (bool)
            False if object was modified by later transaction (ie, data_tid is
            not current), True otherwise.
Vincent Pelletier committed
444
        """
Vincent Pelletier committed
445 446 447 448
        u64 = util.u64
        p64 = util.p64
        oid = u64(oid)
        tid = u64(tid)
Julien Muchembled committed
449 450
        if ltid:
            ltid = u64(ltid)
Vincent Pelletier committed
451
        undone_tid = u64(undone_tid)
Julien Muchembled committed
452
        def getDataTID(tid=None, before_tid=None):
Julien Muchembled committed
453 454 455 456 457 458 459 460 461 462 463
            tid, data_tid = self._getDataTID(oid, tid, before_tid)
            current_tid = tid
            while data_tid:
                if data_tid < tid:
                    tid, data_tid = self._getDataTID(oid, data_tid)
                    if tid is not None:
                        continue
                logging.error("Incorrect data serial for oid %s at tid %s",
                              oid, current_tid)
                return current_tid, current_tid
            return current_tid, tid
Julien Muchembled committed
464 465
        if transaction_object:
            current_tid = current_data_tid = u64(transaction_object[2])
Vincent Pelletier committed
466
        else:
Julien Muchembled committed
467
            current_tid, current_data_tid = getDataTID(before_tid=ltid)
Vincent Pelletier committed
468 469
        if current_tid is None:
            return (None, None, False)
Julien Muchembled committed
470
        found_undone_tid, undone_data_tid = getDataTID(tid=undone_tid)
Vincent Pelletier committed
471 472 473 474 475
        assert found_undone_tid is not None, (oid, undone_tid)
        is_current = undone_data_tid in (current_data_tid, tid)
        # Load object data as it was before given transaction.
        # It can be None, in which case it means we are undoing object
        # creation.
Julien Muchembled committed
476
        _, data_tid = getDataTID(before_tid=undone_tid)
Vincent Pelletier committed
477 478 479
        if data_tid is not None:
            data_tid = p64(data_tid)
        return p64(current_tid), data_tid, is_current
Vincent Pelletier committed
480

Julien Muchembled committed
481 482 483 484 485 486 487 488 489
    def lockTransaction(self, tid, ttid):
        """Mark voted transaction 'ttid' as committed with given 'tid'"""
        raise NotImplementedError

    def unlockTransaction(self, tid, ttid):
        """Finalize a transaction by moving data to a finished area."""
        raise NotImplementedError

    def abortTransaction(self, ttid):
Grégory Wisniewski committed
490
        raise NotImplementedError
Yoshinori Okuji committed
491

Julien Muchembled committed
492
    def deleteTransaction(self, tid):
Grégory Wisniewski committed
493
        raise NotImplementedError
Yoshinori Okuji committed
494

Vincent Pelletier committed
495 496 497 498 499
    def deleteObject(self, oid, serial=None):
        """Delete given object. If serial is given, only delete that serial for
        given oid."""
        raise NotImplementedError

Julien Muchembled committed
500 501 502
    def _deleteRange(self, partition, min_tid=None, max_tid=None):
        """Delete all objects and transactions between given min_tid (excluded)
        and max_tid (included)"""
Vincent Pelletier committed
503 504
        raise NotImplementedError

Julien Muchembled committed
505 506
    def truncate(self, tid):
        assert tid not in (None, ZERO_TID), tid
Julien Muchembled committed
507
        assert self.getBackupTID()
Julien Muchembled committed
508
        self.setBackupTID(None) # XXX
Julien Muchembled committed
509 510 511
        for partition in xrange(self.getNumPartitions()):
            self._deleteRange(partition, tid)
        self.commit()
Julien Muchembled committed
512

Yoshinori Okuji committed
513 514 515 516 517 518
    def getTransaction(self, tid, all = False):
        """Return a tuple of the list of OIDs, user information,
        a description, and extension information, for a given transaction
        ID. If there is no such transaction ID in a database, return None.
        If all is true, the transaction must be searched from a temporary
        area as well."""
Grégory Wisniewski committed
519
        raise NotImplementedError
Yoshinori Okuji committed
520

Julien Muchembled committed
521
    def getObjectHistory(self, oid, offset, length):
Yoshinori Okuji committed
522
        """Return a list of serials and sizes for a given object ID.
Vincent Pelletier committed
523 524 525
        The length specifies the maximum size of such a list. Result starts
        with latest serial, and the list must be sorted in descending order.
        If there is no such object ID in a database, return None."""
Julien Muchembled committed
526
        raise BackendNotImplemented(self.getObjectHistory)
Yoshinori Okuji committed
527

Julien Muchembled committed
528 529 530 531
    def getReplicationObjectList(self, min_tid, max_tid, length, partition,
            min_oid):
        """Return a dict of length oids grouped by serial at (or above)
        min_tid and min_oid and below max_tid, for given partition,
Vincent Pelletier committed
532
        sorted in ascending order."""
Vincent Pelletier committed
533 534
        raise NotImplementedError

Julien Muchembled committed
535
    def getTIDList(self, offset, length, partition_list):
Vincent Pelletier committed
536 537 538
        """Return a list of TIDs in ascending order from an offset,
        at most the specified length. The list of partitions are passed
        to filter out non-applicable TIDs."""
Julien Muchembled committed
539
        raise BackendNotImplemented(self.getTIDList)
Vincent Pelletier committed
540

Julien Muchembled committed
541
    def getReplicationTIDList(self, min_tid, max_tid, length, partition):
Vincent Pelletier committed
542
        """Return a list of TIDs in ascending order from an initial tid value,
Vincent Pelletier committed
543 544
        at most the specified length up to max_tid. The partition number is
        passed to filter out non-applicable TIDs."""
Grégory Wisniewski committed
545
        raise NotImplementedError
Yoshinori Okuji committed
546

Vincent Pelletier committed
547 548 549 550 551 552 553 554 555 556 557 558
    def pack(self, tid, updateObjectDataForPack):
        """Prune all non-current object revisions at given tid.
        updateObjectDataForPack is a function called for each deleted object
        and revision with:
        - OID
        - packed TID
        - new value_serial
            If object data was moved to an after-pack-tid revision, this
            parameter contains the TID of that revision, allowing to backlink
            to it.
        - getObjectData function
            To call if value_serial is None and an object needs to be updated.
Julien Muchembled committed
559
            Takes no parameter, returns a 3-tuple: compression, data_id,
Vincent Pelletier committed
560 561
            value
        """
Vincent Pelletier committed
562
        raise NotImplementedError
Vincent Pelletier committed
563

Julien Muchembled committed
564
    def checkTIDRange(self, partition, length, min_tid, max_tid):
Vincent Pelletier committed
565 566 567 568 569 570 571 572 573
        """
        Generate a diggest from transaction list.
        min_tid (packed)
            TID at which verification starts.
        length (int)
            Maximum number of records to include in result.

        Returns a 3-tuple:
            - number of records actually found
Julien Muchembled committed
574 575
            - a SHA1 computed from record's TID
              ZERO_HASH if no record found
Vincent Pelletier committed
576 577 578 579 580
            - biggest TID found (ie, TID of last record read)
              ZERO_TID if not record found
        """
        raise NotImplementedError

Julien Muchembled committed
581
    def checkSerialRange(self, partition, length, min_tid, max_tid, min_oid):
Vincent Pelletier committed
582 583 584 585
        """
        Generate a diggest from object list.
        min_oid (packed)
            OID at which verification starts.
Julien Muchembled committed
586
        min_tid (packed)
Vincent Pelletier committed
587 588 589 590 591 592
            Serial of min_oid object at which search should start.
        length
            Maximum number of records to include in result.

        Returns a 5-tuple:
            - number of records actually found
Julien Muchembled committed
593 594
            - a SHA1 computed from record's OID
              ZERO_HASH if no record found
Vincent Pelletier committed
595 596
            - biggest OID found (ie, OID of last record read)
              ZERO_OID if no record found
Julien Muchembled committed
597 598
            - a SHA1 computed from record's serial
              ZERO_HASH if no record found
Vincent Pelletier committed
599 600 601 602 603 604
            - biggest serial found for biggest OID found (ie, serial of last
              record read)
              ZERO_TID if no record found
        """
        raise NotImplementedError