from allmydata.immutable import encode
from allmydata.util import base32, dictutil, idlib, log, mathutil
from allmydata.util.happinessutil import servers_of_happiness, \
- shares_by_server, merge_peers, \
+ shares_by_server, merge_servers, \
failure_message
from allmydata.util.assertutil import precondition
from allmydata.util.rrefutil import add_version_to_remote_reference
def _loop(self):
if not self.homeless_shares:
- merged = merge_peers(self.preexisting_shares, self.use_trackers)
+ merged = merge_servers(self.preexisting_shares, self.use_trackers)
effective_happiness = servers_of_happiness(merged)
if self.servers_of_happiness <= effective_happiness:
msg = ("server selection successful for %s: %s: pretty_print_merged: %s, "
return self._loop()
else:
# no more servers. If we haven't placed enough shares, we fail.
- merged = merge_peers(self.preexisting_shares, self.use_trackers)
+ merged = merge_servers(self.preexisting_shares, self.use_trackers)
effective_happiness = servers_of_happiness(merged)
if effective_happiness < self.servers_of_happiness:
msg = failure_message(len(self.serverids_with_shares),
from allmydata.test.no_network import GridTestMixin
from allmydata.test.common_util import ShouldFailMixin
from allmydata.util.happinessutil import servers_of_happiness, \
- shares_by_server, merge_peers
+ shares_by_server, merge_servers
from allmydata.storage_client import StorageFarmBroker
from allmydata.storage.server import storage_index_to_dir
return d
- def test_merge_peers(self):
- # merge_peers merges a list of upload_servers and a dict of
+ def test_merge_servers(self):
+ # merge_servers merges a list of upload_servers and a dict of
# shareid -> serverid mappings.
shares = {
1 : set(["server1"]),
}
# if not provided with a upload_servers argument, it should just
# return the first argument unchanged.
- self.failUnlessEqual(shares, merge_peers(shares, set([])))
+ self.failUnlessEqual(shares, merge_servers(shares, set([])))
trackers = []
for (i, server) in [(i, "server%d" % i) for i in xrange(5, 9)]:
t = FakeServerTracker(server, [i])
7 : set(["server7"]),
8 : set(["server8"]),
}
- self.failUnlessEqual(expected, merge_peers(shares, set(trackers)))
+ self.failUnlessEqual(expected, merge_servers(shares, set(trackers)))
shares2 = {}
expected = {
5 : set(["server5"]),
7 : set(["server7"]),
8 : set(["server8"]),
}
- self.failUnlessEqual(expected, merge_peers(shares2, set(trackers)))
+ self.failUnlessEqual(expected, merge_servers(shares2, set(trackers)))
shares3 = {}
trackers = []
expected = {}
t = FakeServerTracker(server, [i])
trackers.append(t)
expected[i] = set([server])
- self.failUnlessEqual(expected, merge_peers(shares3, set(trackers)))
+ self.failUnlessEqual(expected, merge_servers(shares3, set(trackers)))
def test_servers_of_happiness_utility_function(self):
# should be 3 instead of 4.
happy = servers_of_happiness(test1)
self.failUnlessEqual(3, happy)
- # The second argument of merge_peers should be a set of objects with
+ # The second argument of merge_servers should be a set of objects with
# serverid and buckets as attributes. In actual use, these will be
# ServerTracker instances, but for testing it is fine to make a
# FakeServerTracker whose job is to hold those instance variables to
# = 3. Since there isn't any overlap between the shnum ->
# set([serverid]) correspondences in test1 and those in trackers,
# the result here should be 7.
- test2 = merge_peers(test1, set(trackers))
+ test2 = merge_servers(test1, set(trackers))
happy = servers_of_happiness(test2)
self.failUnlessEqual(7, happy)
# Now add an overlapping server to trackers. This is redundant,
# to change.
t = FakeServerTracker("server1", [1])
trackers.append(t)
- test2 = merge_peers(test1, set(trackers))
+ test2 = merge_servers(test1, set(trackers))
happy = servers_of_happiness(test2)
self.failUnlessEqual(7, happy)
test = {}
#
# and, since there are 5 edges in this matching, it should
# return 5.
- test2 = merge_peers(test, set(trackers))
+ test2 = merge_servers(test, set(trackers))
happy = servers_of_happiness(test2)
self.failUnlessEqual(5, happy)
# Zooko's first puzzle:
ret.setdefault(peerid, set()).add(shareid)
return ret
-def merge_peers(servermap, upload_trackers=None):
+def merge_servers(servermap, upload_trackers=None):
"""
- I accept a dict of shareid -> set(peerid) mappings, and optionally a
- set of PeerTrackers. If no set of PeerTrackers is provided, I return
+ I accept a dict of shareid -> set(serverid) mappings, and optionally a
+ set of ServerTrackers. If no set of ServerTrackers is provided, I return
my first argument unmodified. Otherwise, I update a copy of my first
- argument to include the shareid -> peerid mappings implied in the
- set of PeerTrackers, returning the resulting dict.
+ argument to include the shareid -> serverid mappings implied in the
+ set of ServerTrackers, 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