changeset 50312:c185545a4c69 stable

revlog: add a failing variant of the the split + transaction test We have another variant to tests, and it is crashing… So lets cover it with tests.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 16 Mar 2023 21:04:52 +0100
parents e2ba2234bf1c
children b0cdd0bea103
files tests/test-transaction-rollback-on-revlog-split.t
diffstat 1 files changed, 94 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-transaction-rollback-on-revlog-split.t	Thu Mar 16 20:37:11 2023 +0100
+++ b/tests/test-transaction-rollback-on-revlog-split.t	Thu Mar 16 21:04:52 2023 +0100
@@ -17,6 +17,21 @@
   >     extensions.wrapfunction(util.atomictempfile, 'close', close)
   > EOF
 
+  $ cat > $TESTTMP/intercept_after_rename.py << EOF
+  > import os
+  > import signal
+  > from mercurial import extensions, util
+  > 
+  > def extsetup(ui):
+  >     def close(orig, *args, **kwargs):
+  >         path = util.normpath(args[0]._atomictempfile__name)
+  >         r = orig(*args, **kwargs)
+  >         if path.endswith(b'/.hg/store/data/file.i'):
+  >             os.kill(os.getpid(), signal.SIGKILL)
+  >         return r
+  >     extensions.wrapfunction(util.atomictempfile, 'close', close)
+  > EOF
+
   $ cat > $TESTTMP/killme.py << EOF
   > import os
   > import signal
@@ -197,6 +212,85 @@
   $ hg verify -q
   $ cd ..
 
+Test a hard crash right after the index is move into place
+===========================================================
+
+Now retry the procedure but intercept the rename of the index.
+
+Things get corrupted /o\
+
+  $ hg clone --quiet --rev 1 troffset-computation troffset-computation-crash-after-rename
+  $ cd troffset-computation-crash-after-rename
+
+Reference size:
+  $ f -s file
+  file: size=1024
+  $ f -s .hg/store/data/file*
+  .hg/store/data/file.i: size=1174
+
+  $ cat > .hg/hgrc <<EOF
+  > [extensions]
+  > intercept_rename = $TESTTMP/intercept_after_rename.py
+  > [hooks]
+  > pretxnchangegroup = python:$TESTTMP/killme.py:killme
+  > EOF
+#if chg
+  $ hg pull ../troffset-computation
+  pulling from ../troffset-computation
+  [255]
+#else
+  $ hg pull ../troffset-computation
+  pulling from ../troffset-computation
+  Killed
+  [137]
+#endif
+
+the revlog has been split on disk
+
+  $ f -s .hg/store/data/file*
+  .hg/store/data/file.d: size=132139
+  .hg/store/data/file.i: size=256
+
+  $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
+  data/file.i 1174
+  data/file.d 0
+  data/file.d 1046
+
+  $ hg recover
+  rolling back interrupted transaction
+  abort: attempted to truncate data/file.i to 1174 bytes, but it was already 256 bytes
+  
+  [255]
+  $ f -s .hg/store/data/file*
+  .hg/store/data/file.d: size=1046
+  .hg/store/data/file.i: size=256
+  $ hg tip
+  changeset:   1:cfa8d6e60429
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  $ hg verify -q
+  abandoned transaction found - run hg recover
+   warning: revlog 'data/file.d' not in fncache!
+   file@0: data length off by -131093 bytes
+   file@2: unpacking fa1120531cc1: partial read of revlog data/file.d; expected 21 bytes from offset 1046, got 0
+   file@3: unpacking a631378adaa3: partial read of revlog data/file.d; expected 131072 bytes from offset 1067, got -21
+   file@?: rev 2 points to nonexistent changeset 2
+   (expected )
+   file@?: fa1120531cc1 not in manifests
+   file@?: rev 3 points to nonexistent changeset 3
+   (expected )
+   file@?: a631378adaa3 not in manifests
+  not checking dirstate because of previous errors
+  3 warnings encountered!
+  hint: run "hg debugrebuildfncache" to recover from corrupt fncache
+  7 integrity errors encountered!
+  (first damaged changeset appears to be 0)
+  [1]
+  $ cd ..
+
 Have the transaction rollback itself without any hard crash
 ===========================================================