view tests/test-bisect.t @ 26623:5a95fe44121d

clonebundles: support for seeding clones from pre-generated bundles Cloning can be an expensive operation for servers because the server generates a bundle from existing repository data at request time. For a large repository like mozilla-central, this consumes 4+ minutes of CPU time on the server. It also results in significant network utilization. Multiplied by hundreds or even thousands of clients and the ensuing load can result in difficulties scaling the Mercurial server. Despite generation of bundles being deterministic until the next changeset is added, the generation of bundles to service a clone request is not cached. Each clone thus performs redundant work. This is wasteful. This patch introduces the "clonebundles" extension and related client-side functionality to help alleviate this deficiency. The client-side feature is behind an experimental flag and is not enabled by default. It works as follows: 1) Server operator generates a bundle and makes it available on a server (likely HTTP). 2) Server operator defines the URL of a bundle file in a .hg/clonebundles.manifest file. 3) Client `hg clone`ing sees the server is advertising bundle URLs. 4) Client fetches and applies the advertised bundle. 5) Client performs equivalent of `hg pull` to fetch changes made since the bundle was created. Essentially, the server performs the expensive work of generating a bundle once and all subsequent clones fetch a static file from somewhere. Scaling static file serving is a much more manageable problem than scaling a Python application like Mercurial. Assuming your repository grows less than 1% per day, the end result is 99+% of CPU and network load from clones is eliminated, allowing Mercurial servers to scale more easily. Serving static files also means data can be transferred to clients as fast as they can consume it, rather than as fast as servers can generate it. This makes clones faster. Mozilla has implemented similar functionality of this patch on hg.mozilla.org using a custom extension. We are hosting bundle files in Amazon S3 and CloudFront (a CDN) and have successfully offloaded >1 TB/day in data transfer from hg.mozilla.org, freeing up significant bandwidth and CPU resources. The positive impact has been stellar and I believe it has proved its value to be included in Mercurial core. I feel it is important for the client-side support to be enabled in core by default because it means that clients will get faster, more reliable clones and will enable server operators to reduce load without requiring any client-side configuration changes (assuming clients are up to date, of course). The scope of this feature is narrowly and specifically tailored to cloning, despite "serve pulls from pre-generated bundles" being a valid and useful feature. I would eventually like for Mercurial servers to support transferring *all* repository data via statically hosted files. You could imagine a server that siphons all pushed data to bundle files and instructs clients to apply a stream of bundles to reconstruct all repository data. This feature, while useful and powerful, is significantly more work to implement because it requires the server component have awareness of discovery and a mapping of which changesets are in which files. Full, clone bundles, by contrast, are much simpler. The wire protocol command is named "clonebundles" instead of something more generic like "staticbundles" to leave the door open for a new, more powerful and more generic server-side component with minimal backwards compatibility implications. The name "bundleclone" is used by Mozilla's extension and would cause problems since there are subtle differences in Mozilla's extension. Mozilla's experience with this idea has taught us that some form of "content negotiation" is required. Not all clients will support all bundle formats or even URLs (advanced TLS requirements, etc). To ensure the highest uptake possible, a server needs to advertise multiple versions of bundles and clients need to be able to choose the most appropriate from that list one. The "attributes" in each server-advertised entry facilitate this filtering and sorting. Their use will become apparent in subsequent patches. Initial inspiration and credit for the idea of cloning from static files belongs to Augie Fackler and his "lookaside clone" extension proof of concept.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 09 Oct 2015 11:22:01 -0700
parents 6084926366b9
children d83ca854fa21
line wrap: on
line source

  $ hg init


committing changes

  $ count=0
  $ echo > a
  $ while test $count -lt 32 ; do
  >     echo 'a' >> a
  >     test $count -eq 0 && hg add
  >     hg ci -m "msg $count" -d "$count 0"
  >     count=`expr $count + 1`
  > done
  adding a


  $ hg log
  changeset:   31:58c80a7c8a40
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:31 1970 +0000
  summary:     msg 31
  
  changeset:   30:ed2d2f24b11c
  user:        test
  date:        Thu Jan 01 00:00:30 1970 +0000
  summary:     msg 30
  
  changeset:   29:b5bd63375ab9
  user:        test
  date:        Thu Jan 01 00:00:29 1970 +0000
  summary:     msg 29
  
  changeset:   28:8e0c2264c8af
  user:        test
  date:        Thu Jan 01 00:00:28 1970 +0000
  summary:     msg 28
  
  changeset:   27:288867a866e9
  user:        test
  date:        Thu Jan 01 00:00:27 1970 +0000
  summary:     msg 27
  
  changeset:   26:3efc6fd51aeb
  user:        test
  date:        Thu Jan 01 00:00:26 1970 +0000
  summary:     msg 26
  
  changeset:   25:02a84173a97a
  user:        test
  date:        Thu Jan 01 00:00:25 1970 +0000
  summary:     msg 25
  
  changeset:   24:10e0acd3809e
  user:        test
  date:        Thu Jan 01 00:00:24 1970 +0000
  summary:     msg 24
  
  changeset:   23:5ec79163bff4
  user:        test
  date:        Thu Jan 01 00:00:23 1970 +0000
  summary:     msg 23
  
  changeset:   22:06c7993750ce
  user:        test
  date:        Thu Jan 01 00:00:22 1970 +0000
  summary:     msg 22
  
  changeset:   21:e5db6aa3fe2a
  user:        test
  date:        Thu Jan 01 00:00:21 1970 +0000
  summary:     msg 21
  
  changeset:   20:7128fb4fdbc9
  user:        test
  date:        Thu Jan 01 00:00:20 1970 +0000
  summary:     msg 20
  
  changeset:   19:52798545b482
  user:        test
  date:        Thu Jan 01 00:00:19 1970 +0000
  summary:     msg 19
  
  changeset:   18:86977a90077e
  user:        test
  date:        Thu Jan 01 00:00:18 1970 +0000
  summary:     msg 18
  
  changeset:   17:03515f4a9080
  user:        test
  date:        Thu Jan 01 00:00:17 1970 +0000
  summary:     msg 17
  
  changeset:   16:a2e6ea4973e9
  user:        test
  date:        Thu Jan 01 00:00:16 1970 +0000
  summary:     msg 16
  
  changeset:   15:e7fa0811edb0
  user:        test
  date:        Thu Jan 01 00:00:15 1970 +0000
  summary:     msg 15
  
  changeset:   14:ce8f0998e922
  user:        test
  date:        Thu Jan 01 00:00:14 1970 +0000
  summary:     msg 14
  
  changeset:   13:9d7d07bc967c
  user:        test
  date:        Thu Jan 01 00:00:13 1970 +0000
  summary:     msg 13
  
  changeset:   12:1941b52820a5
  user:        test
  date:        Thu Jan 01 00:00:12 1970 +0000
  summary:     msg 12
  
  changeset:   11:7b4cd9578619
  user:        test
  date:        Thu Jan 01 00:00:11 1970 +0000
  summary:     msg 11
  
  changeset:   10:7c5eff49a6b6
  user:        test
  date:        Thu Jan 01 00:00:10 1970 +0000
  summary:     msg 10
  
  changeset:   9:eb44510ef29a
  user:        test
  date:        Thu Jan 01 00:00:09 1970 +0000
  summary:     msg 9
  
  changeset:   8:453eb4dba229
  user:        test
  date:        Thu Jan 01 00:00:08 1970 +0000
  summary:     msg 8
  
  changeset:   7:03750880c6b5
  user:        test
  date:        Thu Jan 01 00:00:07 1970 +0000
  summary:     msg 7
  
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  
  changeset:   5:7874a09ea728
  user:        test
  date:        Thu Jan 01 00:00:05 1970 +0000
  summary:     msg 5
  
  changeset:   4:9b2ba8336a65
  user:        test
  date:        Thu Jan 01 00:00:04 1970 +0000
  summary:     msg 4
  
  changeset:   3:b53bea5e2fcb
  user:        test
  date:        Thu Jan 01 00:00:03 1970 +0000
  summary:     msg 3
  
  changeset:   2:db07c04beaca
  user:        test
  date:        Thu Jan 01 00:00:02 1970 +0000
  summary:     msg 2
  
  changeset:   1:5cd978ea5149
  user:        test
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     msg 1
  
  changeset:   0:b99c7b9c8e11
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     msg 0
  

  $ hg up -C
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved

bisect test

  $ hg bisect -r
  $ hg bisect -b
  $ hg summary
  parent: 31:58c80a7c8a40 tip
   msg 31
  branch: default
  commit: (clean)
  update: (current)
  phases: 32 draft
  $ hg bisect -g 1
  Testing changeset 16:a2e6ea4973e9 (30 changesets remaining, ~4 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  Testing changeset 23:5ec79163bff4 (15 changesets remaining, ~3 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

skip

  $ hg bisect -s
  Testing changeset 24:10e0acd3809e (15 changesets remaining, ~3 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  Testing changeset 27:288867a866e9 (7 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  Testing changeset 29:b5bd63375ab9 (4 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -b
  Testing changeset 28:8e0c2264c8af (2 changesets remaining, ~1 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  The first bad revision is:
  changeset:   29:b5bd63375ab9
  user:        test
  date:        Thu Jan 01 00:00:29 1970 +0000
  summary:     msg 29
  

mark revsets instead of single revs

  $ hg bisect -r
  $ hg bisect -b "0::3"
  $ hg bisect -s "13::16"
  $ hg bisect -g "26::tip"
  Testing changeset 12:1941b52820a5 (23 changesets remaining, ~4 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ cat .hg/bisect.state
  bad b99c7b9c8e11558adef3fad9af211c58d46f325b
  bad 5cd978ea51499179507ee7b6f340d2dbaa401185
  bad db07c04beaca44cf24832541e7f4a2346a95275b
  bad b53bea5e2fcb30d3e00bd3409507a5659ce0fd8b
  current 1941b52820a544549596820a8ae006842b0e2c64
  good 3efc6fd51aeb8594398044c6c846ca59ae021203
  good 288867a866e9adb7a29880b66936c874b80f4651
  good 8e0c2264c8af790daf3585ada0669d93dee09c83
  good b5bd63375ab9a290419f2024b7f4ee9ea7ce90a8
  good ed2d2f24b11c368fa8aa0da9f4e1db580abade59
  good 58c80a7c8a4025a94cedaf7b4a4e3124e8909a96
  skip 9d7d07bc967ca98ad0600c24953fd289ad5fa991
  skip ce8f0998e922c179e80819d5066fbe46e2998784
  skip e7fa0811edb063f6319531f0d0a865882138e180
  skip a2e6ea4973e9196ddd3386493b0c214b41fd97d3

bisect reverse test

  $ hg bisect -r
  $ hg bisect -b null
  $ hg bisect -g tip
  Testing changeset 15:e7fa0811edb0 (32 changesets remaining, ~5 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  Testing changeset 7:03750880c6b5 (16 changesets remaining, ~4 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved

skip

  $ hg bisect -s
  Testing changeset 6:a3d5c6fdf0d3 (16 changesets remaining, ~4 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  Testing changeset 2:db07c04beaca (7 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  Testing changeset 0:b99c7b9c8e11 (3 changesets remaining, ~1 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -b
  Testing changeset 1:5cd978ea5149 (2 changesets remaining, ~1 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  The first good revision is:
  changeset:   1:5cd978ea5149
  user:        test
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     msg 1
  

  $ hg bisect -r
  $ hg bisect -g tip
  $ hg bisect -b tip
  abort: inconsistent state, 31:58c80a7c8a40 is good and bad
  [255]

  $ hg bisect -r
  $ hg bisect -g null
  $ hg bisect -bU tip
  Testing changeset 15:e7fa0811edb0 (32 changesets remaining, ~5 tests)
  $ hg id
  5cd978ea5149


Issue1228: hg bisect crashes when you skip the last rev in bisection
Issue1182: hg bisect exception

  $ hg bisect -r
  $ hg bisect -b 4
  $ hg bisect -g 0
  Testing changeset 2:db07c04beaca (4 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Testing changeset 1:5cd978ea5149 (4 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Testing changeset 3:b53bea5e2fcb (4 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Due to skipped revisions, the first bad revision could be any of:
  changeset:   1:5cd978ea5149
  user:        test
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     msg 1
  
  changeset:   2:db07c04beaca
  user:        test
  date:        Thu Jan 01 00:00:02 1970 +0000
  summary:     msg 2
  
  changeset:   3:b53bea5e2fcb
  user:        test
  date:        Thu Jan 01 00:00:03 1970 +0000
  summary:     msg 3
  
  changeset:   4:9b2ba8336a65
  user:        test
  date:        Thu Jan 01 00:00:04 1970 +0000
  summary:     msg 4
  


reproduce non converging bisect, issue1182

  $ hg bisect -r
  $ hg bisect -g 0
  $ hg bisect -b 2
  Testing changeset 1:5cd978ea5149 (2 changesets remaining, ~1 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Due to skipped revisions, the first bad revision could be any of:
  changeset:   1:5cd978ea5149
  user:        test
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     msg 1
  
  changeset:   2:db07c04beaca
  user:        test
  date:        Thu Jan 01 00:00:02 1970 +0000
  summary:     msg 2
  


test no action

  $ hg bisect -r
  $ hg bisect
  abort: cannot bisect (no known good revisions)
  [255]


reproduce AssertionError, issue1445

  $ hg bisect -r
  $ hg bisect -b 6
  $ hg bisect -g 0
  Testing changeset 3:b53bea5e2fcb (6 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Testing changeset 2:db07c04beaca (6 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Testing changeset 4:9b2ba8336a65 (6 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Testing changeset 1:5cd978ea5149 (6 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -s
  Testing changeset 5:7874a09ea728 (6 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect -g
  The first bad revision is:
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  
  $ hg log -r "bisect(good)"
  changeset:   0:b99c7b9c8e11
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     msg 0
  
  changeset:   5:7874a09ea728
  user:        test
  date:        Thu Jan 01 00:00:05 1970 +0000
  summary:     msg 5
  
  $ hg log -r "bisect(bad)"
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  
  $ hg log -r "bisect(current)"
  changeset:   5:7874a09ea728
  user:        test
  date:        Thu Jan 01 00:00:05 1970 +0000
  summary:     msg 5
  
  $ hg log -r "bisect(skip)"
  changeset:   1:5cd978ea5149
  user:        test
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     msg 1
  
  changeset:   2:db07c04beaca
  user:        test
  date:        Thu Jan 01 00:00:02 1970 +0000
  summary:     msg 2
  
  changeset:   3:b53bea5e2fcb
  user:        test
  date:        Thu Jan 01 00:00:03 1970 +0000
  summary:     msg 3
  
  changeset:   4:9b2ba8336a65
  user:        test
  date:        Thu Jan 01 00:00:04 1970 +0000
  summary:     msg 4
  

test legacy bisected() keyword

  $ hg log -r "bisected(bad)"
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  

  $ set +e

test invalid command
assuming that the shell returns 127 if command not found ...

  $ hg bisect -r
  $ hg bisect --command 'exit 127'
  abort: failed to execute exit 127
  [255]


test bisecting command

  $ cat > script.py <<EOF
  > #!/usr/bin/env python
  > import sys
  > from mercurial import ui, hg
  > repo = hg.repository(ui.ui(), '.')
  > if repo['.'].rev() < 6:
  >     sys.exit(1)
  > EOF
  $ chmod +x script.py
  $ hg bisect -r
  $ hg up -qr tip
  $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
  changeset 31:58c80a7c8a40: good
  abort: cannot bisect (no known bad revisions)
  [255]
  $ hg up -qr 0
  $ hg bisect --command "python \"$TESTTMP/script.py\" and some parameters"
  changeset 0:b99c7b9c8e11: bad
  changeset 15:e7fa0811edb0: good
  changeset 7:03750880c6b5: good
  changeset 3:b53bea5e2fcb: bad
  changeset 5:7874a09ea728: bad
  changeset 6:a3d5c6fdf0d3: good
  The first good revision is:
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  


test bisecting via a command without updating the working dir, and
ensure that the bisect state file is updated before running a test
command

  $ hg update null
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
  $ cat > script.sh <<'EOF'
  > #!/bin/sh
  > test -n "$HG_NODE" || (echo HG_NODE missing; exit 127)
  > current="`hg log -r \"bisect(current)\" --template {node}`"
  > test "$current" = "$HG_NODE" || (echo current is bad: $current; exit 127)
  > rev="`hg log -r $HG_NODE --template {rev}`"
  > test "$rev" -ge 6
  > EOF
  $ chmod +x script.sh
  $ hg bisect -r
  $ hg bisect --good tip --noupdate
  $ hg bisect --bad 0 --noupdate
  Testing changeset 15:e7fa0811edb0 (31 changesets remaining, ~4 tests)
  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params" --noupdate
  changeset 15:e7fa0811edb0: good
  changeset 7:03750880c6b5: good
  changeset 3:b53bea5e2fcb: bad
  changeset 5:7874a09ea728: bad
  changeset 6:a3d5c6fdf0d3: good
  The first good revision is:
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  

ensure that we still don't have a working dir

  $ hg parents


test the same case, this time with updating

  $ cat > script.sh <<'EOF'
  > #!/bin/sh
  > test -n "$HG_NODE" || (echo HG_NODE missing; exit 127)
  > current="`hg log -r \"bisect(current)\" --template {node}`"
  > test "$current" = "$HG_NODE" || (echo current is bad: $current; exit 127)
  > rev="`hg log -r . --template {rev}`"
  > test "$rev" -ge 6
  > EOF
  $ chmod +x script.sh
  $ hg bisect -r
  $ hg up -qr tip
  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params"
  changeset 31:58c80a7c8a40: good
  abort: cannot bisect (no known bad revisions)
  [255]
  $ hg up -qr 0
  $ hg bisect --command "sh \"$TESTTMP/script.sh\" and some params"
  changeset 0:b99c7b9c8e11: bad
  changeset 15:e7fa0811edb0: good
  changeset 7:03750880c6b5: good
  changeset 3:b53bea5e2fcb: bad
  changeset 5:7874a09ea728: bad
  changeset 6:a3d5c6fdf0d3: good
  The first good revision is:
  changeset:   6:a3d5c6fdf0d3
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     msg 6
  


Check that bisect does not break on obsolete changesets
=========================================================

  $ cat >> $HGRCPATH << EOF
  > [experimental]
  > evolution=createmarkers
  > EOF

tip is obsolete
---------------------

  $ hg debugobsolete `hg id --debug -i -r tip`
  $ hg bisect --reset
  $ hg bisect --good 15
  $ hg bisect --bad 30
  Testing changeset 22:06c7993750ce (15 changesets remaining, ~3 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect --command true
  changeset 22:06c7993750ce: good
  changeset 26:3efc6fd51aeb: good
  changeset 28:8e0c2264c8af: good
  changeset 29:b5bd63375ab9: good
  The first bad revision is:
  changeset:   30:ed2d2f24b11c
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:30 1970 +0000
  summary:     msg 30
  

Changeset in the bad:good range is obsolete
---------------------------------------------

  $ hg up 30
  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo 'a' >> a
  $ hg ci -m "msg 32" -d "32 0"
  $ hg bisect --reset
  $ hg bisect --good .
  $ hg bisect --bad 25
  Testing changeset 28:8e0c2264c8af (6 changesets remaining, ~2 tests)
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg bisect --command true
  changeset 28:8e0c2264c8af: good
  changeset 26:3efc6fd51aeb: good
  The first good revision is:
  changeset:   26:3efc6fd51aeb
  user:        test
  date:        Thu Jan 01 00:00:26 1970 +0000
  summary:     msg 26