def __init__(self, file, eof, packtime): self._file = file self._name = file.name self.eof = eof self.packtime = packtime # packpos: position of first txn header after pack time self.packpos = None self.oid2curpos = fsIndex() # maps oid to current data record position self.oid2verpos = fsIndex() # maps oid to current version data # The set of reachable revisions of each object. # # This set as managed using two data structures. The first is # an fsIndex mapping oids to one data record pos. Since only # a few objects will have more than one revision, we use this # efficient data structure to handle the common case. The # second is a dictionary mapping objects to lists of # positions; it is used to handle the same number of objects # for which we must keep multiple revisions. self.reachable = fsIndex() self.reach_ex = {} # keep ltid for consistency checks during initial scan self.ltid = z64
def __init__(self, path, stop, la, lr, cla, clr, current_size): self._name = path # We open our own handle on the storage so that much of pack can # proceed in parallel. It's important to close this file at every # return point, else on Windows the caller won't be able to rename # or remove the storage file. self._file = open(path, "rb") self._path = path self._stop = stop self.locked = 0 self.file_end = current_size self.gc = GC(self._file, self.file_end, self._stop) # The packer needs to acquire the parent's commit lock # during the copying stage, so the two sets of lock acquire # and release methods are passed to the constructor. self._lock_acquire = la self._lock_release = lr self._commit_lock_acquire = cla self._commit_lock_release = clr # The packer will use several indexes. # index: oid -> pos # vindex: version -> pos # tindex: oid -> pos, for current txn # tvindex: version -> pos, for current txn # oid2tid: not used by the packer self.index = fsIndex() self.vindex = {} self.tindex = {} self.tvindex = {} self.oid2tid = {} self.toid2tid = {} self.toid2tid_delete = {} # Index for non-version data. This is a temporary structure # to reduce I/O during packing self.nvindex = fsIndex()
def testInserts(self): index=fsIndex() for i in range(200): index[p64(i*1000)]=(i*1000L+1) for i in range(0,200): self.assertEqual((i,index[p64(i*1000)]), (i,(i*1000L+1))) self.assertEqual(len(index), 200) key=p64(2000) self.assertEqual(index.get(key), 2001) key=p64(2001) self.assertEqual(index.get(key), None) self.assertEqual(index.get(key, ''), '')
def testUpdate(self): index=fsIndex() d={} for i in range(200): d[p64(i*1000)]=(i*1000L+1) index.update(d) for i in range(400,600): d[p64(i*1000)]=(i*1000L+1) index.update(d) for i in range(100, 500): d[p64(i*1000)]=(i*1000L+2) index.update(d) self.assertEqual(index.get(p64(2000)), 2001) self.assertEqual(index.get(p64(599000)), 599001) self.assertEqual(index.get(p64(399000)), 399002) self.assertEqual(len(index), 600)
def setUp(self): self.index = fsIndex() for i in range(200): self.index[p64(i * 1000)] = (i * 1000L + 1)