From 13b5e44fbc2effd09f97307540783fbbd47acebe Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Mon, 19 Jul 2010 00:54:26 -0700 Subject: [PATCH] immutable: fix bug in which preexisting_shares and merged were shallowly referencing the same sets This bug had the effect of making uploads sometimes (rarely) appear to succeed when they had actually not distributed the shares well enough to achieve the desired servers-of-happiness level. --- src/allmydata/util/happinessutil.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/allmydata/util/happinessutil.py b/src/allmydata/util/happinessutil.py index 4c711290..9e5b3705 100644 --- a/src/allmydata/util/happinessutil.py +++ b/src/allmydata/util/happinessutil.py @@ -3,6 +3,8 @@ I contain utilities useful for calculating servers_of_happiness, and for reporting it in messages """ +from copy import deepcopy + def failure_message(peer_count, k, happy, effective_happy): # If peer_count < needed_shares, this error message makes more # sense than any of the others, so use it. @@ -60,16 +62,16 @@ def merge_peers(servermap, used_peers=None): argument to include the shareid -> peerid mappings implied in the set of PeerTrackers, returning the resulting dict. """ + # Since we mutate servermap, and are called outside of a + # context where it is okay to do that, make a copy of servermap and + # work with it. + servermap = deepcopy(servermap) if not used_peers: return servermap assert(isinstance(servermap, dict)) assert(isinstance(used_peers, set)) - # Since we mutate servermap, and are called outside of a - # context where it is okay to do that, make a copy of servermap and - # work with it. - servermap = servermap.copy() for peer in used_peers: for shnum in peer.buckets: servermap.setdefault(shnum, set()).add(peer.peerid) -- 2.45.2