changeset 42685:863e9e7f8850

merge with stable
author Yuya Nishihara <yuya@tcha.org>
date Sun, 04 Aug 2019 20:59:21 +0900
parents bbb002b378f3 (current diff) 9e0f1c80cddb (diff)
children 3364b4da5271
files mercurial/localrepo.py tests/test-bookmarks-corner-case.t
diffstat 6 files changed, 153 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/automation/hgautomation/linux.py	Fri Aug 02 16:17:02 2019 +0200
+++ b/contrib/automation/hgautomation/linux.py	Sun Aug 04 20:59:21 2019 +0900
@@ -485,7 +485,9 @@
             'python2.7', str(hg_bin),
             '--config', 'ui.ssh=ssh -F %s' % ssh_config,
             '--config', 'ui.remotecmd=/hgdev/venv-bootstrap/bin/hg',
-            'push', '-f', '-r', full_revision,
+            # Also ensure .hgtags changes are present so auto version
+            # calculation works.
+            'push', '-f', '-r', full_revision, '-r', 'file(.hgtags)',
             'ssh://%s//hgwork/src' % public_ip,
         ]
 
--- a/contrib/automation/hgautomation/windows.py	Fri Aug 02 16:17:02 2019 +0200
+++ b/contrib/automation/hgautomation/windows.py	Sun Aug 04 20:59:21 2019 +0900
@@ -176,7 +176,9 @@
             'python2.7', hg_bin,
             '--config', 'ui.ssh=ssh -F %s' % ssh_config,
             '--config', 'ui.remotecmd=c:/hgdev/venv-bootstrap/Scripts/hg.exe',
-            'push', '-f', '-r', full_revision,
+            # Also ensure .hgtags changes are present so auto version
+            # calculation works.
+            'push', '-f', '-r', full_revision, '-r', 'file(.hgtags)',
             'ssh://%s/c:/hgdev/src' % public_ip,
         ]
 
--- a/mercurial/localrepo.py	Fri Aug 02 16:17:02 2019 +0200
+++ b/mercurial/localrepo.py	Sun Aug 04 20:59:21 2019 +0900
@@ -1227,6 +1227,55 @@
     @mixedrepostorecache(('bookmarks', 'plain'), ('bookmarks.current', 'plain'),
                          ('bookmarks', ''), ('00changelog.i', ''))
     def _bookmarks(self):
+        # Since the multiple files involved in the transaction cannot be
+        # written atomically (with current repository format), there is a race
+        # condition here.
+        #
+        # 1) changelog content A is read
+        # 2) outside transaction update changelog to content B
+        # 3) outside transaction update bookmark file referring to content B
+        # 4) bookmarks file content is read and filtered against changelog-A
+        #
+        # When this happens, bookmarks against nodes missing from A are dropped.
+        #
+        # Having this happening during read is not great, but it become worse
+        # when this happen during write because the bookmarks to the "unknown"
+        # nodes will be dropped for good. However, writes happen within locks.
+        # This locking makes it possible to have a race free consistent read.
+        # For this purpose data read from disc before locking  are
+        # "invalidated" right after the locks are taken. This invalidations are
+        # "light", the `filecache` mechanism keep the data in memory and will
+        # reuse them if the underlying files did not changed. Not parsing the
+        # same data multiple times helps performances.
+        #
+        # Unfortunately in the case describe above, the files tracked by the
+        # bookmarks file cache might not have changed, but the in-memory
+        # content is still "wrong" because we used an older changelog content
+        # to process the on-disk data. So after locking, the changelog would be
+        # refreshed but `_bookmarks` would be preserved.
+        # Adding `00changelog.i` to the list of tracked file is not
+        # enough, because at the time we build the content for `_bookmarks` in
+        # (4), the changelog file has already diverged from the content used
+        # for loading `changelog` in (1)
+        #
+        # To prevent the issue, we force the changelog to be explicitly
+        # reloaded while computing `_bookmarks`. The data race can still happen
+        # without the lock (with a narrower window), but it would no longer go
+        # undetected during the lock time refresh.
+        #
+        # The new schedule is as follow
+        #
+        # 1) filecache logic detect that `_bookmarks` needs to be computed
+        # 2) cachestat for `bookmarks` and `changelog` are captured (for book)
+        # 3) We force `changelog` filecache to be tested
+        # 4) cachestat for `changelog` are captured (for changelog)
+        # 5) `_bookmarks` is computed and cached
+        #
+        # The step in (3) ensure we have a changelog at least as recent as the
+        # cache stat computed in (1). As a result at locking time:
+        #  * if the changelog did not changed since (1) -> we can reuse the data
+        #  * otherwise -> the bookmarks get refreshed.
+        self._refreshchangelog()
         return bookmarks.bmstore(self)
 
     def _refreshchangelog(self):
--- a/mercurial/repair.py	Fri Aug 02 16:17:02 2019 +0200
+++ b/mercurial/repair.py	Sun Aug 04 20:59:21 2019 +0900
@@ -109,6 +109,9 @@
     repo = repo.unfiltered()
     repo.destroying()
     vfs = repo.vfs
+    # load bookmark before changelog to avoid side effect from outdated
+    # changelog (see repo._refreshchangelog)
+    repo._bookmarks
     cl = repo.changelog
 
     # TODO handle undo of merge sets
--- a/tests/test-bookmarks-corner-case.t	Fri Aug 02 16:17:02 2019 +0200
+++ b/tests/test-bookmarks-corner-case.t	Sun Aug 04 20:59:21 2019 +0900
@@ -200,6 +200,7 @@
   $ cat push-output.txt
   pushing to ssh://user@dummy/bookrace-server
   searching for changes
+  remote has heads on branch 'default' that are not known locally: f26c3b5167d1
   remote: setting raced push up
   remote: adding changesets
   remote: adding manifests
@@ -219,7 +220,7 @@
   |  summary:     A1
   |
   | o  changeset:   3:f26c3b5167d1
-  | |  bookmark:    book-B (false !)
+  | |  bookmark:    book-B
   | |  user:        test
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
   | |  summary:     B1
@@ -242,4 +243,4 @@
   
   $ hg -R bookrace-server book
      book-A                    4:9ce3b28c16de
-     book-B                    3:f26c3b5167d1 (false !)
+     book-B                    3:f26c3b5167d1
--- a/tests/test-strip.t	Fri Aug 02 16:17:02 2019 +0200
+++ b/tests/test-strip.t	Sun Aug 04 20:59:21 2019 +0900
@@ -9,10 +9,10 @@
   $ teststrip() {
   >     hg up -C $1
   >     echo % before update $1, strip $2
-  >     hg parents
+  >     hg log -G -T '{rev}:{node}'
   >     hg --traceback strip $2
   >     echo % after update $1, strip $2
-  >     hg parents
+  >     hg log -G -T '{rev}:{node}'
   >     restore
   > }
 
@@ -70,95 +70,136 @@
   $ teststrip 4 4
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   % before update 4, strip 4
-  changeset:   4:443431ffac4f
-  tag:         tip
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     e
+  @  4:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  |
+  o  3:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  | o  2:264128213d290d868c54642d13aeaa3675551a78
+  |/
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
   % after update 4, strip 4
-  changeset:   3:65bd5f99a4a3
-  tag:         tip
-  parent:      1:ef3a871183d7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     d
+  @  3:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  | o  2:264128213d290d868c54642d13aeaa3675551a78
+  |/
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   $ teststrip 4 3
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   % before update 4, strip 3
-  changeset:   4:443431ffac4f
-  tag:         tip
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     e
+  @  4:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  |
+  o  3:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  | o  2:264128213d290d868c54642d13aeaa3675551a78
+  |/
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
   % after update 4, strip 3
-  changeset:   1:ef3a871183d7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     b
+  o  2:264128213d290d868c54642d13aeaa3675551a78
+  |
+  @  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   $ teststrip 1 4
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   % before update 1, strip 4
-  changeset:   1:ef3a871183d7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     b
+  o  4:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  |
+  o  3:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  | o  2:264128213d290d868c54642d13aeaa3675551a78
+  |/
+  @  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
   % after update 1, strip 4
-  changeset:   1:ef3a871183d7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     b
+  o  3:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  | o  2:264128213d290d868c54642d13aeaa3675551a78
+  |/
+  @  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   $ teststrip 4 2
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   % before update 4, strip 2
-  changeset:   4:443431ffac4f
-  tag:         tip
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     e
+  @  4:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  |
+  o  3:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  | o  2:264128213d290d868c54642d13aeaa3675551a78
+  |/
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
   % after update 4, strip 2
-  changeset:   3:443431ffac4f
-  tag:         tip
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     e
+  @  3:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  |
+  o  2:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   $ teststrip 4 1
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   % before update 4, strip 1
-  changeset:   4:264128213d29
-  tag:         tip
-  parent:      1:ef3a871183d7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     c
+  @  4:264128213d290d868c54642d13aeaa3675551a78
+  |
+  | o  3:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  | |
+  | o  2:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |/
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
   % after update 4, strip 1
-  changeset:   0:9ab35a2d17cb
-  tag:         tip
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     a
+  @  0:9ab35a2d17cb64271241ea881efcc19dd953215b
   
   $ teststrip null 4
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   % before update null, strip 4
+  o  4:264128213d290d868c54642d13aeaa3675551a78
+  |
+  | o  3:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  | |
+  | o  2:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |/
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
+  
   saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
   % after update null, strip 4
+  o  3:443431ffac4f5b5a19b0b6c298a21b7ba736bcce
+  |
+  o  2:65bd5f99a4a376cdea23a1153f07856b0d881d64
+  |
+  o  1:ef3a871183d7199c541cc140218298bbfcc6c28a
+  |
+  o  0:9ab35a2d17cb64271241ea881efcc19dd953215b
+  
 
   $ hg log
   changeset:   4:264128213d29