This file is indexed.

/usr/lib/python2.7/dist-packages/ZODB/tests/MVCCMappingStorage.py is in python-zodb 1:3.10.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
##############################################################################
#
# Copyright (c) Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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
#
##############################################################################
"""An extension of MappingStorage that depends on polling.

Each Connection has its own view of the database.  Polling updates each
connection's view.
"""

import ZODB.utils
import ZODB.POSException
from ZODB.interfaces import IMVCCStorage
from ZODB.MappingStorage import MappingStorage
from zope.interface import implements


class MVCCMappingStorage(MappingStorage):
    implements(IMVCCStorage)

    def __init__(self, name="MVCC Mapping Storage"):
        MappingStorage.__init__(self, name=name)
        # _polled_tid contains the transaction ID at the last poll.
        self._polled_tid = b''
        self._data_snapshot = None  # {oid->(state, tid)}
        self._main_lock_acquire = self._lock_acquire
        self._main_lock_release = self._lock_release

    def new_instance(self):
        """Returns a storage instance that is a view of the same data.
        """
        inst = MVCCMappingStorage(name=self.__name__)
        # All instances share the same OID data, transaction log, commit lock,
        # and OID sequence.
        inst._data = self._data
        inst._transactions = self._transactions
        inst._commit_lock = self._commit_lock
        inst.new_oid = self.new_oid
        inst.pack = self.pack
        inst._main_lock_acquire = self._lock_acquire
        inst._main_lock_release = self._lock_release
        return inst

    @ZODB.utils.locked(MappingStorage.opened)
    def sync(self, force=False):
        self._data_snapshot = None

    def release(self):
        pass

    @ZODB.utils.locked(MappingStorage.opened)
    def load(self, oid, version=''):
        assert not version, "Versions are not supported"
        if self._data_snapshot is None:
            self.poll_invalidations()
        info = self._data_snapshot.get(oid)
        if info:
            return info
        raise ZODB.POSException.POSKeyError(oid)

    def poll_invalidations(self):
        """Poll the storage for changes by other connections.
        """
        # prevent changes to _transactions and _data during analysis
        self._main_lock_acquire()
        try:

            if self._transactions:
                new_tid = self._transactions.maxKey()
            else:
                new_tid = b''

            # Copy the current data into a snapshot. This is obviously
            # very inefficient for large storages, but it's good for
            # tests.
            self._data_snapshot = {}
            for oid, tid_data in self._data.items():
                if tid_data:
                    tid = tid_data.maxKey()
                    self._data_snapshot[oid] = tid_data[tid], tid

            if self._polled_tid:
                if not self._transactions.has_key(self._polled_tid):
                    # This connection is so old that we can no longer enumerate
                    # all the changes.
                    self._polled_tid = new_tid
                    return None

            changed_oids = set()
            for tid, txn in self._transactions.items(
                    self._polled_tid, new_tid,
                    excludemin=True, excludemax=False):
                if txn.status == 'p':
                    # This transaction has been packed, so it is no longer
                    # possible to enumerate all changed oids.
                    self._polled_tid = new_tid
                    return None
                if tid == self._ltid:
                    # ignore the transaction committed by this connection
                    continue
                changed_oids.update(txn.data.keys())

        finally:
            self._main_lock_release()

        self._polled_tid = new_tid
        return list(changed_oids)

    def tpc_finish(self, transaction, func = lambda tid: None):
        self._data_snapshot = None
        MappingStorage.tpc_finish(self, transaction, func)

    def tpc_abort(self, transaction):
        self._data_snapshot = None
        MappingStorage.tpc_abort(self, transaction)

    def pack(self, t, referencesf, gc=True):
        # prevent all concurrent commits during packing
        self._commit_lock.acquire()
        try:
            MappingStorage.pack(self, t, referencesf, gc)
        finally:
            self._commit_lock.release()