Looks good
Show More
@@ -0,0 +1,26 b'' | |||||
|
1 | # Dummy extension that adds a delay after acquiring a lock. | |||
|
2 | # | |||
|
3 | # This extension can be used to test race conditions between lock acquisition. | |||
|
4 | ||||
|
5 | from __future__ import absolute_import | |||
|
6 | ||||
|
7 | import os | |||
|
8 | import time | |||
|
9 | ||||
|
10 | from mercurial import ( | |||
|
11 | lock as lockmod, | |||
|
12 | ) | |||
|
13 | ||||
|
14 | class delaylock(lockmod.lock): | |||
|
15 | def lock(self): | |||
|
16 | delay = float(os.environ.get('HGPRELOCKDELAY', '0.0')) | |||
|
17 | if delay: | |||
|
18 | time.sleep(delay) | |||
|
19 | res = super(delaylock, self).lock() | |||
|
20 | delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0')) | |||
|
21 | if delay: | |||
|
22 | time.sleep(delay) | |||
|
23 | return res | |||
|
24 | ||||
|
25 | def extsetup(ui): | |||
|
26 | lockmod.lock = delaylock |
@@ -335,15 +335,28 b' def clonewithshare(ui, peeropts, sharepa' | |||||
335 | "support clone by revision")) |
|
335 | "support clone by revision")) | |
336 | revs = [srcpeer.lookup(r) for r in rev] |
|
336 | revs = [srcpeer.lookup(r) for r in rev] | |
337 |
|
337 | |||
|
338 | # Obtain a lock before checking for or cloning the pooled repo otherwise | |||
|
339 | # 2 clients may race creating or populating it. | |||
|
340 | pooldir = os.path.dirname(sharepath) | |||
|
341 | # lock class requires the directory to exist. | |||
|
342 | try: | |||
|
343 | util.makedir(pooldir, False) | |||
|
344 | except OSError as e: | |||
|
345 | if e.errno != errno.EEXIST: | |||
|
346 | raise | |||
|
347 | ||||
|
348 | poolvfs = scmutil.vfs(pooldir) | |||
338 | basename = os.path.basename(sharepath) |
|
349 | basename = os.path.basename(sharepath) | |
339 |
|
350 | |||
|
351 | with lock.lock(poolvfs, '%s.lock' % basename): | |||
340 | if os.path.exists(sharepath): |
|
352 | if os.path.exists(sharepath): | |
341 | ui.status(_('(sharing from existing pooled repository %s)\n') % |
|
353 | ui.status(_('(sharing from existing pooled repository %s)\n') % | |
342 | basename) |
|
354 | basename) | |
343 | else: |
|
355 | else: | |
344 | ui.status(_('(sharing from new pooled repository %s)\n') % basename) |
|
356 | ui.status(_('(sharing from new pooled repository %s)\n') % basename) | |
345 |
# Always use pull mode because hardlinks in share mode don't work |
|
357 | # Always use pull mode because hardlinks in share mode don't work | |
346 |
# Never update because working copies aren't necessary in |
|
358 | # well. Never update because working copies aren't necessary in | |
|
359 | # share mode. | |||
347 | clone(ui, peeropts, source, dest=sharepath, pull=True, |
|
360 | clone(ui, peeropts, source, dest=sharepath, pull=True, | |
348 | rev=rev, update=False, stream=stream) |
|
361 | rev=rev, update=False, stream=stream) | |
349 |
|
362 |
@@ -1025,3 +1025,49 b" Test that auto sharing doesn't cause fai" | |||||
1025 | $ hg --config share.pool=share -q clone -e "python \"$TESTDIR/dummyssh\"" a ssh://user@dummy/remote |
|
1025 | $ hg --config share.pool=share -q clone -e "python \"$TESTDIR/dummyssh\"" a ssh://user@dummy/remote | |
1026 | $ hg -R remote id -r 0 |
|
1026 | $ hg -R remote id -r 0 | |
1027 | acb14030fe0a |
|
1027 | acb14030fe0a | |
|
1028 | ||||
|
1029 | Cloning into pooled storage doesn't race (issue5104) | |||
|
1030 | ||||
|
1031 | $ HGPOSTLOCKDELAY=2.0 hg --config share.pool=racepool --config extensions.lockdelay=$TESTDIR/lockdelay.py clone source1a share-destrace1 > race1.log 2>&1 & | |||
|
1032 | $ HGPRELOCKDELAY=1.0 hg --config share.pool=racepool --config extensions.lockdelay=$TESTDIR/lockdelay.py clone source1a share-destrace2 > race2.log 2>&1 | |||
|
1033 | $ wait | |||
|
1034 | ||||
|
1035 | $ hg -R share-destrace1 log -r tip | |||
|
1036 | changeset: 2:e5bfe23c0b47 | |||
|
1037 | bookmark: bookA | |||
|
1038 | tag: tip | |||
|
1039 | user: test | |||
|
1040 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1041 | summary: 1a | |||
|
1042 | ||||
|
1043 | ||||
|
1044 | $ hg -R share-destrace2 log -r tip | |||
|
1045 | changeset: 2:e5bfe23c0b47 | |||
|
1046 | bookmark: bookA | |||
|
1047 | tag: tip | |||
|
1048 | user: test | |||
|
1049 | date: Thu Jan 01 00:00:00 1970 +0000 | |||
|
1050 | summary: 1a | |||
|
1051 | ||||
|
1052 | $ cat race1.log | |||
|
1053 | (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1) | |||
|
1054 | requesting all changes | |||
|
1055 | adding changesets | |||
|
1056 | adding manifests | |||
|
1057 | adding file changes | |||
|
1058 | added 3 changesets with 3 changes to 1 files | |||
|
1059 | updating working directory | |||
|
1060 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
1061 | searching for changes | |||
|
1062 | no changes found | |||
|
1063 | adding remote bookmark bookA | |||
|
1064 | ||||
|
1065 | $ cat race2.log | |||
|
1066 | (sharing from existing pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1) | |||
|
1067 | updating working directory | |||
|
1068 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
1069 | waiting for lock on repository share-destrace2 held by * (glob) | |||
|
1070 | got lock after \d+ seconds (re) | |||
|
1071 | searching for changes | |||
|
1072 | no changes found | |||
|
1073 | adding remote bookmark bookA |
General Comments 1
You need to be logged in to leave comments.
Login now