Skip to content
Snippets Groups Projects
Commit a3b1ab5f authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

dirstate: deal with read-race for pure python code

If we cannot read the dirstate data, this is probably because a writing process
wrote it under our feet. So refresh the docket and try again a handful of time.
parent 53f19662
No related branches found
No related tags found
6 merge requests!484Merge stable into default.,!483cleanup branch hack in the transaction.,!482write branch in the transaction when applicable,!479write race fix,!478fix some identity race,!474Test race condition around dirstate read
......@@ -37,6 +37,9 @@
WRITE_MODE_FORCE_APPEND = 2
V2_MAX_READ_ATTEMPTS = 5
class _dirstatemapcommon:
"""
Methods that are identical for both implementations of the dirstatemap
......@@ -125,6 +128,21 @@
return self._docket
def _read_v2_data(self):
data = None
attempts = 0
while attempts < V2_MAX_READ_ATTEMPTS:
attempts += 1
try:
data = self._opener.read(self.docket.data_filename())
except FileNotFoundError:
# read race detected between docket and data file
# reload the docket and retry
self._docket = None
if data is None:
assert attempts >= V2_MAX_READ_ATTEMPTS
msg = b"dirstate read race happened %d times in a row"
msg %= attempts
raise error.Abort(msg)
return self._opener.read(self.docket.data_filename())
def write_v2_no_append(self, tr, st, meta, packed):
......
......@@ -217,4 +217,9 @@
#endif
#else
$ cat $TESTTMP/status-race-lock.out
A dir/n
A dir/o
R dir/nested/m
? p
? q
$ cat $TESTTMP/status-race-lock.log
......@@ -220,5 +225,4 @@
$ cat $TESTTMP/status-race-lock.log
abort: $ENOENT$: '$TESTTMP/race-with-add/.hg/dirstate.* (glob)
#endif
#endif
#endif
......@@ -318,4 +322,8 @@
#endif
#else
$ cat $TESTTMP/status-race-lock.out
M dir/o
? dir/n
? p
? q
$ cat $TESTTMP/status-race-lock.log
......@@ -321,5 +329,5 @@
$ cat $TESTTMP/status-race-lock.log
abort: $ENOENT$: '$TESTTMP/race-with-commit/.hg/dirstate.* (glob)
warning: ignoring unknown working parent 02a67a77ee9b!
#endif
#endif
#endif
......@@ -452,4 +460,8 @@
#endif
#else
$ cat $TESTTMP/status-race-lock.out
A dir/o
? dir/n
? p
? q
$ cat $TESTTMP/status-race-lock.log
......@@ -455,5 +467,4 @@
$ cat $TESTTMP/status-race-lock.log
abort: $ENOENT$: '$TESTTMP/race-with-update/.hg/dirstate.* (glob)
#endif
#endif
#endif
......@@ -542,4 +553,9 @@
#endif
#else
$ cat $TESTTMP/status-race-lock.out
A dir/o
R dir/nested/m
? dir/n
? p
? q
$ cat $TESTTMP/status-race-lock.log
......@@ -545,5 +561,4 @@
$ cat $TESTTMP/status-race-lock.log
abort: $ENOENT$: '$TESTTMP/race-with-status/.hg/dirstate.* (glob)
#endif
#endif
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment