revlog: update the split + transaction test stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 16 Mar 2023 20:37:11 +0100
branchstable
changeset 50311 e2ba2234bf1c
parent 50310 4c1061b3e55a
child 50312 c185545a4c69
revlog: update the split + transaction test We add section, increase the amount of comments and simplify some of the constructs. We are about to build more on top this tests so lets do a small cleanup first.
tests/helper-killhook.py
tests/test-transaction-rollback-on-revlog-split.t
--- a/tests/helper-killhook.py	Wed Mar 15 14:29:37 2023 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-import os
-
-
-def killme(ui, repo, hooktype, **wkargs):
-    os._exit(80)
--- a/tests/test-transaction-rollback-on-revlog-split.t	Wed Mar 15 14:29:37 2023 +0100
+++ b/tests/test-transaction-rollback-on-revlog-split.t	Thu Mar 16 20:37:11 2023 +0100
@@ -1,22 +1,62 @@
 Test correctness of revlog inline -> non-inline transition
 ----------------------------------------------------------
 
-Helper extension to intercept renames.
+Helper extension to intercept renames and kill process
 
-  $ cat > $TESTTMP/intercept_rename.py << EOF
+  $ cat > $TESTTMP/intercept_before_rename.py << EOF
   > import os
-  > import sys
+  > import signal
   > from mercurial import extensions, util
   > 
   > def extsetup(ui):
   >     def close(orig, *args, **kwargs):
   >         path = util.normpath(args[0]._atomictempfile__name)
   >         if path.endswith(b'/.hg/store/data/file.i'):
-  >             os._exit(80)
+  >             os.kill(os.getpid(), signal.SIGKILL)
   >         return orig(*args, **kwargs)
   >     extensions.wrapfunction(util.atomictempfile, 'close', close)
   > EOF
 
+  $ cat > $TESTTMP/killme.py << EOF
+  > import os
+  > import signal
+  > 
+  > def killme(ui, repo, hooktype, **kwargs):
+  >     os.kill(os.getpid(), signal.SIGKILL)
+  > EOF
+
+setup a repository for tests
+----------------------------
+
+  $ cat >> $HGRCPATH << EOF
+  > [format]
+  > revlog-compression=none
+  > EOF
+
+  $ hg init troffset-computation
+  $ cd troffset-computation
+  $ printf '%20d' '1' > file
+  $ hg commit -Aqma
+  $ printf '%1024d' '1' > file
+  $ hg commit -Aqmb
+  $ printf '%20d' '1' > file
+  $ hg commit -Aqmc
+  $ dd if=/dev/zero of=file bs=1k count=128 > /dev/null 2>&1
+  $ hg commit -AqmD
+
+Reference size:
+  $ f -s file
+  file: size=131072
+  $ f -s .hg/store/data/file*
+  .hg/store/data/file.d: size=132139
+  .hg/store/data/file.i: size=256
+
+  $ cd ..
+
+
+Test a hard crash after the file was split but before the transaction was committed
+===================================================================================
+
 Test offset computation to correctly factor in the index entries themselves.
 Also test that the new data size has the correct size if the transaction is aborted
 after the index has been replaced.
@@ -28,30 +68,19 @@
 If the transaction adding c, D is rolled back, then we don't undo the revlog split,
 but truncate the index and the data to remove both c and D.
 
-  $ hg init troffset-computation --config format.revlog-compression=none
-  $ cd troffset-computation
-  $ printf '%20d' '1' > file
-  $ hg commit -Aqma
-  $ printf '%1024d' '1' > file
-  $ hg commit -Aqmb
-  $ printf '%20d' '1' > file
-  $ hg commit -Aqmc
-  $ dd if=/dev/zero of=file bs=1k count=128 > /dev/null 2>&1
-  $ hg commit -AqmD
 
-  $ cd ..
-
-  $ hg clone -r 1 troffset-computation troffset-computation-copy --config format.revlog-compression=none -q
+  $ hg clone --quiet --rev 1 troffset-computation troffset-computation-copy
   $ cd troffset-computation-copy
 
 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
   > [hooks]
-  > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
+  > pretxnchangegroup = python:$TESTTMP/killme.py:killme
   > EOF
 #if chg
   $ hg pull ../troffset-computation
@@ -60,14 +89,24 @@
 #else
   $ hg pull ../troffset-computation
   pulling from ../troffset-computation
-  [80]
+  Killed
+  [137]
 #endif
+
+
+The revlog have 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 | tail -1
   data/file.i 128
 
 The first file.i entry should match the "Reference size" above.
 The first file.d entry is the temporary record during the split,
-the second entry after the split happened. The sum of the second file.d
+
+The second entry after the split happened. The sum of the second file.d
 and the second file.i entry should match the first file.i entry.
 
   $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
@@ -98,18 +137,27 @@
   $ hg verify -q
   $ cd ..
 
+Test a hard crash right before the index is move into place
+===========================================================
 
 Now retry the procedure but intercept the rename of the index and check that
 the journal does not contain the new index size. This demonstrates the edge case
 where the data file is left as garbage.
 
-  $ hg clone -r 1 troffset-computation troffset-computation-copy2 --config format.revlog-compression=none -q
+  $ hg clone --quiet --rev 1 troffset-computation troffset-computation-copy2
   $ cd troffset-computation-copy2
+
+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_rename.py
+  > intercept_rename = $TESTTMP/intercept_before_rename.py
   > [hooks]
-  > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
+  > pretxnchangegroup = python:$TESTTMP/killme.py:killme
   > EOF
 #if chg
   $ hg pull ../troffset-computation
@@ -118,8 +166,16 @@
 #else
   $ hg pull ../troffset-computation
   pulling from ../troffset-computation
-  [80]
+  Killed
+  [137]
 #endif
+
+The data file is created, but the revlog is still inline
+
+  $ f -s .hg/store/data/file*
+  .hg/store/data/file.d: size=132139
+  .hg/store/data/file.i: size=132395
+
   $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
   data/file.i 1174
   data/file.d 0
@@ -141,10 +197,13 @@
   $ hg verify -q
   $ cd ..
 
+Have the transaction rollback itself without any hard crash
+===========================================================
+
 
 Repeat the original test but let hg rollback the transaction.
 
-  $ hg clone -r 1 troffset-computation troffset-computation-copy-rb --config format.revlog-compression=none -q
+  $ hg clone --quiet --rev 1 troffset-computation troffset-computation-copy-rb
   $ cd troffset-computation-copy-rb
   $ cat > .hg/hgrc <<EOF
   > [hooks]
@@ -160,9 +219,13 @@
   rollback completed
   abort: pretxnchangegroup hook exited with status 1
   [40]
+
+File are still split on disk, with the expected size.
+
   $ f -s .hg/store/data/file*
   .hg/store/data/file.d: size=1046
   .hg/store/data/file.i: size=128
+
   $ hg tip
   changeset:   1:cfa8d6e60429
   tag:         tip