# HG changeset patch # User Pierre-Yves David # Date 1420661391 28800 # Node ID b681d3a2bf04ad135de5b09e2918ac0da3fdc593 # Parent 9ca2eb881b53656bf7b763dddb12a1510c5c8a2f setdiscovery: randomly pick between heads and sample when taking full sample Before this changeset, the discovery protocol was too heads-centric. Heads of the undiscovered set were always sent for discovery and any room remaining in the sample were filled with exponential samples (and random ones if any room remained). This behaved extremely poorly when the number of heads exceeded the sample size, because we keep just asking about the existence of heads, then their direct parent and so on. As a result, the 'O(log(len(repo)))' discovery turns into a 'O(len(repo))' one. As a solution we take a random sample of the heads plus exponential samples. This way we ensure some exponential sampling is achieved, bringing back some logarithmic convergence of the discovery again. This patch only applies this principle in one place. More places will be updated in future patches. One test is impacted because the random sample happen to be different. By chance, it helps a bit in this case. diff -r 9ca2eb881b53 -r b681d3a2bf04 mercurial/setdiscovery.py --- a/mercurial/setdiscovery.py Tue Jan 06 17:02:32 2015 -0800 +++ b/mercurial/setdiscovery.py Wed Jan 07 12:09:51 2015 -0800 @@ -113,11 +113,11 @@ # update from roots _updatesample(dag.inverse(), nodes, sample, always) assert sample - sample = _limitsample(sample, desiredlen) - if len(sample) < desiredlen: - more = desiredlen - len(sample) - sample.update(random.sample(list(nodes - sample - always), more)) sample.update(always) + sample = _limitsample(sample, size) + if len(sample) < size: + more = size - len(sample) + sample.update(random.sample(list(nodes - sample), more)) return sample def _limitsample(sample, desiredlen): diff -r 9ca2eb881b53 -r b681d3a2bf04 tests/test-setdiscovery.t --- a/tests/test-setdiscovery.t Tue Jan 06 17:02:32 2015 -0800 +++ b/tests/test-setdiscovery.t Wed Jan 07 12:09:51 2015 -0800 @@ -326,7 +326,7 @@ query 6; still undecided: 540, sample size is: 200 sampling from both directions searching: 7 queries - query 7; still undecided: 44, sample size is: 44 + query 7; still undecided: 37, sample size is: 37 7 total queries common heads: 3ee37d65064a