diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-06-29 20:08:27 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-06-29 20:08:27 +1200 |
commit | 5b458cd48ccca5009964240de301fed5dc819edb (patch) | |
tree | ac7de552c81f3fb7e4ca3ac709761c8c869024fe | |
parent | c8999bd1d9d1748feb032279aaeadd387007b7b9 (diff) | |
download | obnam-5b458cd48ccca5009964240de301fed5dc819edb.tar.gz |
Change Store.put_chunk to choose randomly only the first chunk id.
Subsequent chunks get successive ids.
-rw-r--r-- | obnamlib/store.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/obnamlib/store.py b/obnamlib/store.py index e23db388..a620826d 100644 --- a/obnamlib/store.py +++ b/obnamlib/store.py @@ -616,6 +616,7 @@ class Store(object): self.chunksums = ChecksumTree(fs, 'chunksums', len(self.checksum(''))) self.groupsums = ChecksumTree(fs, 'groupsums', len(self.checksum(''))) self.chunkgroups = ChunkGroupTree(fs) + self.prev_chunkid = None def checksum(self, data): '''Return checksum of data. @@ -861,11 +862,18 @@ class Store(object): ''' + max_chunkid = 2**64 - 1 + def random_chunkid(): + return random.randint(0, max_chunkid) + + if self.prev_chunkid is None: + self.prev_chunkid = random_chunkid() while True: - chunkid = random.randint(0, 2**64 - 1) + chunkid = (self.prev_chunkid + 1) % max_chunkid filename = self._chunk_filename(chunkid) if not self.fs.exists(filename): break + self.prev_chunkid = chunkid dirname = os.path.dirname(filename) if not self.fs.exists(dirname): self.fs.makedirs(dirname) |