author | Gregory Szorc <gregory.szorc@gmail.com> |
Sat, 19 Feb 2022 18:42:12 -0700 | |
changeset 48938 | 4561ec90d3c1 |
parent 47887 | 52018f8ef020 |
child 48966 | 6000f5b25c9b |
permissions | -rw-r--r-- |
47887
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
"""Create the race condition for issue6554 |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
The persistent nodemap issues had an issue where a second writer could |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
overwrite the data that a previous write just wrote. The would break the append |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
only garantee of the persistent nodemap and could confuse reader. This |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
extensions create all the necessary synchronisation point to the race condition |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
to happen. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
It involves 3 process <LEFT> (a writer) <RIGHT> (a writer) and <READER> |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
[1] <LEFT> take the lock and start a transaction |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
[2] <LEFT> updated `00changelog.i` with the new data |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
[3] <RIGHT> reads: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
- the new changelog index `00changelog.i` |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
- the old `00changelog.n` |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
[4] <LEFT> update the persistent nodemap: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
- writing new data from the last valid offset |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
- updating the docket (00changelog.n) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
[5] <LEFT> release the lock |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
[6] <RIGHT> grab the lock and run `repo.invalidate` |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 |
[7] <READER> reads: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
- the changelog index after <LEFT> write |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
- the nodemap docket after <LEFT> write |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
[8] <RIGHT> reload the changelog since `00changelog.n` changed |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 |
/!\ This is the faulty part in issue 6554, the outdated docket is kept |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 |
[9] <RIGHT> write: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
- the changelog index (00changelog.i) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
- the nodemap data (00changelog*.nd) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
/!\ if the outdated docket is used, the write starts from the same ofset |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 |
/!\ as in [4], overwriting data that <LEFT> wrote in step [4]. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 |
- the nodemap docket (00changelog.n) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 |
[10] <READER> reads the nodemap data from `00changelog*.nd` |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
/!\ if step [9] was wrong, the data matching the docket that <READER> |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
/!\ loaded have been overwritten and the expected root-nodes is no longer |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
/!\ valid. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 |
""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 |
from __future__ import print_function |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 |
import os |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 |
from mercurial.revlogutils.constants import KIND_CHANGELOG |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 |
from mercurial import ( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
45 |
changelog, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 |
encoding, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 |
extensions, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 |
localrepo, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 |
node, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 |
pycompat, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 |
registrar, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 |
testing, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 |
util, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 |
from mercurial.revlogutils import ( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 |
nodemap as nodemaputil, |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 |
configtable = {} |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
61 |
configitem = registrar.configitem(configtable) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 |
configitem(b'devel', b'nodemap-race.role', default=None) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 |
cmdtable = {} |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 |
command = registrar.command(cmdtable) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 |
LEFT = b'left' |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 |
RIGHT = b'right' |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 |
READER = b'reader' |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
71 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 |
SYNC_DIR = os.path.join(encoding.environ[b'TESTTMP'], b'sync-files') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
73 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
# mark the end of step [1] |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 |
FILE_LEFT_LOCKED = os.path.join(SYNC_DIR, b'left-locked') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
# mark that step [3] is ready to run. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
FILE_RIGHT_READY_TO_LOCK = os.path.join(SYNC_DIR, b'right-ready-to-lock') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
# mark the end of step [2] |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 |
FILE_LEFT_CL_DATA_WRITE = os.path.join(SYNC_DIR, b'left-data') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
81 |
# mark the end of step [4] |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 |
FILE_LEFT_CL_NODEMAP_WRITE = os.path.join(SYNC_DIR, b'left-nodemap') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
# mark the end of step [3] |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 |
FILE_RIGHT_CL_NODEMAP_READ = os.path.join(SYNC_DIR, b'right-nodemap') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
# mark that step [9] is read to run |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 |
FILE_RIGHT_CL_NODEMAP_PRE_WRITE = os.path.join( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 |
SYNC_DIR, b'right-pre-nodemap-write' |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 |
# mark that step [9] has run. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
90 |
FILE_RIGHT_CL_NODEMAP_POST_WRITE = os.path.join( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 |
SYNC_DIR, b'right-post-nodemap-write' |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
# mark that step [7] is ready to run |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
94 |
FILE_READER_READY = os.path.join(SYNC_DIR, b'reader-ready') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
# mark that step [7] has run |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 |
FILE_READER_READ_DOCKET = os.path.join(SYNC_DIR, b'reader-read-docket') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
97 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 |
def _print(*args, **kwargs): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
print(*args, **kwargs) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 |
def _role(repo): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 |
"""find the role associated with the process""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 |
return repo.ui.config(b'devel', b'nodemap-race.role') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 |
def wrap_changelog_finalize(orig, cl, tr): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
109 |
"""wrap the update of `00changelog.i` during transaction finalization |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 |
This is useful for synchronisation before or after the file is updated on disk. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
112 |
""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 |
role = getattr(tr, '_race_role', None) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
114 |
if role == RIGHT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 |
print('right ready to write, waiting for reader') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 |
testing.wait_file(FILE_READER_READY) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 |
testing.write_file(FILE_RIGHT_CL_NODEMAP_PRE_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 |
testing.wait_file(FILE_READER_READ_DOCKET) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 |
print('right proceeding with writing its changelog index and nodemap') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 |
ret = orig(cl, tr) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 |
print("finalized changelog write") |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 |
if role == LEFT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 |
testing.write_file(FILE_LEFT_CL_DATA_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 |
return ret |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 |
def wrap_persist_nodemap(orig, tr, revlog, *args, **kwargs): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 |
"""wrap the update of `00changelog.n` and `*.nd` during tr finalization |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
129 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
130 |
This is useful for synchronisation before or after the files are updated on |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
131 |
disk. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
132 |
""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
133 |
is_cl = revlog.target[0] == KIND_CHANGELOG |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
134 |
role = getattr(tr, '_race_role', None) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
135 |
if is_cl: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
136 |
if role == LEFT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
137 |
testing.wait_file(FILE_RIGHT_CL_NODEMAP_READ) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 |
if is_cl: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 |
print("persisting changelog nodemap") |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 |
print(" new data start at", revlog._nodemap_docket.data_length) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 |
ret = orig(tr, revlog, *args, **kwargs) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 |
if is_cl: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 |
print("persisted changelog nodemap") |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 |
print_nodemap_details(revlog) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 |
if role == LEFT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
146 |
testing.write_file(FILE_LEFT_CL_NODEMAP_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 |
elif role == RIGHT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 |
testing.write_file(FILE_RIGHT_CL_NODEMAP_POST_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 |
return ret |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
150 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
def print_nodemap_details(cl): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
153 |
"""print relevant information about the nodemap docket currently in memory""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
154 |
dkt = cl._nodemap_docket |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
155 |
print('docket-details:') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 |
if dkt is None: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
157 |
print(' <no-docket>') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
158 |
return |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 |
print(' uid: ', pycompat.sysstr(dkt.uid)) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 |
print(' actual-tip: ', cl.tiprev()) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 |
print(' tip-rev: ', dkt.tip_rev) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
162 |
print(' data-length:', dkt.data_length) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 |
def wrap_persisted_data(orig, revlog): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 |
"""print some information about the nodemap information we just read |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
167 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
168 |
Used by the <READER> process only. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
169 |
""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
170 |
ret = orig(revlog) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
171 |
if ret is not None: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
172 |
docket, data = ret |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
173 |
file_path = nodemaputil._rawdata_filepath(revlog, docket) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
174 |
file_path = revlog.opener.join(file_path) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
175 |
file_size = os.path.getsize(file_path) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
176 |
print('record-data-length:', docket.data_length) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
177 |
print('actual-data-length:', len(data)) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
178 |
print('file-actual-length:', file_size) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
179 |
return ret |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
180 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
181 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
182 |
def sync_read(orig): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
183 |
"""used by <READER> to force the race window |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
184 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
185 |
This make sure we read the docker from <LEFT> while reading the datafile |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
186 |
after <RIGHT> write. |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
187 |
""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
188 |
orig() |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
189 |
testing.write_file(FILE_READER_READ_DOCKET) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
190 |
print('reader: nodemap docket read') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
191 |
testing.wait_file(FILE_RIGHT_CL_NODEMAP_POST_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
192 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
193 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
194 |
def uisetup(ui): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
195 |
class RacedRepo(localrepo.localrepository): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
196 |
def lock(self, wait=True): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
197 |
# make sure <RIGHT> as the "Wrong" information in memory before |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
198 |
# grabbing the lock |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
199 |
newlock = self._currentlock(self._lockref) is None |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
200 |
if newlock and _role(self) == LEFT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
201 |
cl = self.unfiltered().changelog |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
202 |
print_nodemap_details(cl) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
203 |
elif newlock and _role(self) == RIGHT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
204 |
testing.write_file(FILE_RIGHT_READY_TO_LOCK) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
205 |
print('nodemap-race: right side start of the locking sequence') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
206 |
testing.wait_file(FILE_LEFT_LOCKED) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
207 |
testing.wait_file(FILE_LEFT_CL_DATA_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
208 |
self.invalidate(clearfilecache=True) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
209 |
print('nodemap-race: right side reading changelog') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
210 |
cl = self.unfiltered().changelog |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
211 |
tiprev = cl.tiprev() |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
212 |
tip = cl.node(tiprev) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
213 |
tiprev2 = cl.rev(tip) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
214 |
if tiprev != tiprev2: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
215 |
raise RuntimeError( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
216 |
'bad tip -round-trip %d %d' % (tiprev, tiprev2) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
217 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
218 |
testing.write_file(FILE_RIGHT_CL_NODEMAP_READ) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
219 |
print('nodemap-race: right side reading of changelog is done') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
220 |
print_nodemap_details(cl) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
221 |
testing.wait_file(FILE_LEFT_CL_NODEMAP_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
222 |
print('nodemap-race: right side ready to wait for the lock') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
223 |
ret = super(RacedRepo, self).lock(wait=wait) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
224 |
if newlock and _role(self) == LEFT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
225 |
print('nodemap-race: left side locked and ready to commit') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
226 |
testing.write_file(FILE_LEFT_LOCKED) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
227 |
testing.wait_file(FILE_RIGHT_READY_TO_LOCK) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
228 |
cl = self.unfiltered().changelog |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
229 |
print_nodemap_details(cl) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
230 |
elif newlock and _role(self) == RIGHT: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
231 |
print('nodemap-race: right side locked and ready to commit') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
232 |
cl = self.unfiltered().changelog |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
233 |
print_nodemap_details(cl) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
234 |
return ret |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
235 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
236 |
def transaction(self, *args, **kwargs): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
237 |
# duck punch the role on the transaction to help other pieces of code |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
238 |
tr = super(RacedRepo, self).transaction(*args, **kwargs) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
239 |
tr._race_role = _role(self) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
240 |
return tr |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
241 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
242 |
localrepo.localrepository = RacedRepo |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
243 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
244 |
extensions.wrapfunction( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
245 |
nodemaputil, 'persist_nodemap', wrap_persist_nodemap |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
246 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
247 |
extensions.wrapfunction( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
248 |
changelog.changelog, '_finalize', wrap_changelog_finalize |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
249 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
250 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
251 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
252 |
def reposetup(ui, repo): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
253 |
if _role(repo) == READER: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
254 |
extensions.wrapfunction( |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
255 |
nodemaputil, 'persisted_data', wrap_persisted_data |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
256 |
) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
257 |
extensions.wrapfunction(nodemaputil, 'test_race_hook_1', sync_read) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
258 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
259 |
class ReaderRepo(repo.__class__): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
260 |
@util.propertycache |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
261 |
def changelog(self): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
262 |
print('reader ready to read the changelog, waiting for right') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
263 |
testing.write_file(FILE_READER_READY) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
264 |
testing.wait_file(FILE_RIGHT_CL_NODEMAP_PRE_WRITE) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
265 |
return super(ReaderRepo, self).changelog |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
266 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
267 |
repo.__class__ = ReaderRepo |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
268 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
269 |
|
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
270 |
@command(b'check-nodemap-race') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
271 |
def cmd_check_nodemap_race(ui, repo): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
272 |
"""Run proper <READER> access in the race Windows and check nodemap content""" |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
273 |
repo = repo.unfiltered() |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
274 |
print('reader: reading changelog') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
275 |
cl = repo.changelog |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
276 |
print('reader: changelog read') |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
277 |
print_nodemap_details(cl) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
278 |
tip_rev = cl.tiprev() |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
279 |
tip_node = cl.node(tip_rev) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
280 |
print('tip-rev: ', tip_rev) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
281 |
print('tip-node:', node.short(tip_node).decode('ascii')) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
282 |
print('node-rev:', cl.rev(tip_node)) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
283 |
for r in cl.revs(): |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
284 |
n = cl.node(r) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
285 |
try: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
286 |
r2 = cl.rev(n) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
287 |
except ValueError as exc: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
288 |
print('error while checking revision:', r) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
289 |
print(' ', exc) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
290 |
return 1 |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
291 |
else: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
292 |
if r2 != r: |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
293 |
print('revision %d is missing from the nodemap' % r) |
52018f8ef020
persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
294 |
return 1 |