]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
immutable: when downloading an immutable file, use primary shares if they are available
authorZooko O'Whielacronx <zooko@zooko.com>
Sat, 20 Dec 2008 14:14:56 +0000 (07:14 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Sat, 20 Dec 2008 14:14:56 +0000 (07:14 -0700)
Primary shares require no erasure decoding so the more primary shares you have, the less CPU is used.

src/allmydata/immutable/download.py

index da1d40c40481a27e56df64f0cae1ea3b1e23a9c6..fcf5c42223a0ca9daf28c638dd6fb2142526bebc 100644 (file)
@@ -875,8 +875,13 @@ class FileDownloader(log.PrefixingLogMixin):
             potential_shnums = list(available_shnums - handled_shnums)
             if not potential_shnums:
                 raise NotEnoughSharesError
-            # choose a random share
-            shnum = random.choice(potential_shnums)
+            # For the next share, choose a primary share if available, else a randomly chosen
+            # secondary share.
+            potential_shnums.sort()
+            if potential_shnums[0] < self._uri.needed_shares:
+                shnum = potential_shnums[0]
+            else:
+                shnum = random.choice(potential_shnums)
             # and a random bucket that will provide it
             validated_bucket = random.choice(list(self._share_vbuckets[shnum]))
             self.active_buckets[shnum] = validated_bucket