diff --git a/remotefilelog/debugcommands.py b/remotefilelog/debugcommands.py --- a/remotefilelog/debugcommands.py +++ b/remotefilelog/debugcommands.py @@ -18,6 +18,7 @@ shallowrepo, shallowutil, ) +from .repack import repacklockvfs from .lz4wrapper import lz4decompress import hashlib, os, time @@ -361,7 +362,7 @@ def debugwaitonrepack(repo): while True: try: - with extutil.fcntllock(repo.svfs, 'repacklock', ''): + with extutil.fcntllock(repacklockvfs(repo), 'repacklock', ''): return except error.LockHeld: time.sleep(0.1) diff --git a/remotefilelog/repack.py b/remotefilelog/repack.py --- a/remotefilelog/repack.py +++ b/remotefilelog/repack.py @@ -9,6 +9,7 @@ policy, scmutil, util, + vfs, ) from mercurial.node import ( nullid, @@ -412,7 +413,7 @@ def run(self, targetdata, targethistory): ledger = repackledger() - with fcntllock(self.repo.svfs, "repacklock", + with fcntllock(repacklockvfs(self.repo), "repacklock", _('repacking %s') % self.repo.origroot): self.repo.hook('prerepack') @@ -739,3 +740,14 @@ self.historyrepacked = False # If garbage collected self.gced = False + +def repacklockvfs(repo): + if util.safehasattr(repo, 'name'): + # Lock in the shared cache so repacks across multiple copies of the same + # repo are coordinated. + sharedcachepath = shallowutil.getcachepackpath( + repo, + constants.FILEPACK_CATEGORY) + return vfs.vfs(sharedcachepath) + else: + return repo.svfs diff --git a/tests/test-remotefilelog-bgprefetch.t b/tests/test-remotefilelog-bgprefetch.t --- a/tests/test-remotefilelog-bgprefetch.t +++ b/tests/test-remotefilelog-bgprefetch.t @@ -111,6 +111,7 @@ $TESTTMP/hgcache/master/packs/94d53eef9e622533aec1fc6d8053cb086e785d21.histpack $TESTTMP/hgcache/master/packs/f3644bc7773e8289deda7f765138120c838f4e6e.dataidx $TESTTMP/hgcache/master/packs/f3644bc7773e8289deda7f765138120c838f4e6e.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # background prefetch with repack on update when wcprevset configured @@ -146,6 +147,7 @@ $TESTTMP/hgcache/master/packs/27c52c105a1ddf8c75143a6b279b04c24b1f4bee.histpack $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.dataidx $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Ensure that file 'w' was prefetched - it was not part of the update operation and therefore @@ -197,6 +199,7 @@ $TESTTMP/hgcache/master/packs/27c52c105a1ddf8c75143a6b279b04c24b1f4bee.histpack $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.dataidx $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Ensure that file 'w' was prefetched - it was not part of the commit operation and therefore @@ -288,6 +291,7 @@ $TESTTMP/hgcache/master/packs/27c52c105a1ddf8c75143a6b279b04c24b1f4bee.histpack $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.dataidx $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Ensure that files were prefetched @@ -331,6 +335,7 @@ $TESTTMP/hgcache/master/packs/27c52c105a1ddf8c75143a6b279b04c24b1f4bee.histpack $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.dataidx $TESTTMP/hgcache/master/packs/8299d5a1030f073f4adbb3b6bd2ad3bdcc276df0.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Ensure that files were prefetched diff --git a/tests/test-remotefilelog-gc.t b/tests/test-remotefilelog-gc.t --- a/tests/test-remotefilelog-gc.t +++ b/tests/test-remotefilelog-gc.t @@ -94,6 +94,7 @@ $TESTTMP/hgcache/master/packs/8d3499c65d926e4f107cf03c6b0df833222025b4.histpack $TESTTMP/hgcache/master/packs/9c7046f8cad0417c39aa7c03ce13e0ba991306c2.dataidx $TESTTMP/hgcache/master/packs/9c7046f8cad0417c39aa7c03ce13e0ba991306c2.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Test that warning is displayed when there are no valid repos in repofile diff --git a/tests/test-remotefilelog-lfs.t b/tests/test-remotefilelog-lfs.t --- a/tests/test-remotefilelog-lfs.t +++ b/tests/test-remotefilelog-lfs.t @@ -100,6 +100,7 @@ $TESTTMP/hgcache/master/packs/8f2de7e341fbe688326386a45a3a7082d9f56871.histpack $TESTTMP/hgcache/master/packs/fd280cbfab2f4047961d1ec5f7858e763ac985ab.dataidx $TESTTMP/hgcache/master/packs/fd280cbfab2f4047961d1ec5f7858e763ac985ab.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos $ cp -R . ../shallow2 @@ -237,6 +238,7 @@ $TESTTMP/hgcache/master/packs/bf634767241b49b174b18732f92c6653ff966751.histpack $TESTTMP/hgcache/master/packs/faa267575712c2ee0a4ff7e9c09bf75e10055c04.dataidx $TESTTMP/hgcache/master/packs/faa267575712c2ee0a4ff7e9c09bf75e10055c04.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos $ hg log -p -r ::tip -T '{rev}:{node} {desc}\n' diff --git a/tests/test-remotefilelog-repack-fast.t b/tests/test-remotefilelog-repack-fast.t --- a/tests/test-remotefilelog-repack-fast.t +++ b/tests/test-remotefilelog-repack-fast.t @@ -54,6 +54,7 @@ $TESTTMP/hgcache/master/packs/276d308429d0303762befa376788300f0310f90e.histpack $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Test that the packs are readonly @@ -62,6 +63,7 @@ -r--r--r-- 172 276d308429d0303762befa376788300f0310f90e.histpack -r--r--r-- 1074 8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx -r--r--r-- 69 8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + -rw-r--r-- 0 repacklock # Test that the data in the new packs is accessible $ hg cat -r . x @@ -85,6 +87,7 @@ $TESTTMP/hgcache/master/packs/276d308429d0303762befa376788300f0310f90e.histpack $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos $ hg repack --traceback @@ -94,6 +97,7 @@ $TESTTMP/hgcache/master/packs/077e7ce5dfe862dc40cc8f3c9742d96a056865f2.histpack $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.dataidx $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Verify all the file data is still available @@ -113,6 +117,7 @@ $TESTTMP/hgcache/master/packs/077e7ce5dfe862dc40cc8f3c9742d96a056865f2.histpack $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.dataidx $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Run two repacks at once @@ -137,6 +142,7 @@ $TESTTMP/hgcache/master/packs/077e7ce5dfe862dc40cc8f3c9742d96a056865f2.histpack $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.dataidx $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos $ hg repack --background @@ -148,6 +154,7 @@ $TESTTMP/hgcache/master/packs/094b530486dad4427a0faf6bcbc031571b99ca24.histpack $TESTTMP/hgcache/master/packs/8fe685c56f6f7edf550bfcec74eeecc5f3c2ba15.dataidx $TESTTMP/hgcache/master/packs/8fe685c56f6f7edf550bfcec74eeecc5f3c2ba15.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Test debug commands @@ -224,6 +231,7 @@ e8fdf7ae22b772dcc291f905b9c6e5f381d28739.datapack ebbd7411e00456c0eec8d1150a77e2b3ef490f3f.histidx ebbd7411e00456c0eec8d1150a77e2b3ef490f3f.histpack + repacklock $ hg debughistorypack $TESTTMP/hgcache/master/packs/*.histidx x diff --git a/tests/test-remotefilelog-repack.t b/tests/test-remotefilelog-repack.t --- a/tests/test-remotefilelog-repack.t +++ b/tests/test-remotefilelog-repack.t @@ -49,6 +49,7 @@ $TESTTMP/hgcache/master/packs/276d308429d0303762befa376788300f0310f90e.histpack $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Test that the packs are readonly @@ -57,6 +58,7 @@ -r--r--r-- 172 276d308429d0303762befa376788300f0310f90e.histpack -r--r--r-- 1074 8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx -r--r--r-- 69 8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + -rw-r--r-- 0 repacklock # Test that the data in the new packs is accessible $ hg cat -r . x @@ -80,6 +82,7 @@ $TESTTMP/hgcache/master/packs/276d308429d0303762befa376788300f0310f90e.histpack $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # First assert that with --packsonly, the loose object will be ignored: @@ -92,6 +95,7 @@ $TESTTMP/hgcache/master/packs/276d308429d0303762befa376788300f0310f90e.histpack $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.dataidx $TESTTMP/hgcache/master/packs/8e25dec685d5e0bb1f1b39df3acebda0e0d75c6e.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos $ hg repack --traceback @@ -101,6 +105,7 @@ $TESTTMP/hgcache/master/packs/077e7ce5dfe862dc40cc8f3c9742d96a056865f2.histpack $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.dataidx $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Verify all the file data is still available @@ -120,6 +125,7 @@ $TESTTMP/hgcache/master/packs/077e7ce5dfe862dc40cc8f3c9742d96a056865f2.histpack $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.dataidx $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Run two repacks at once @@ -144,6 +150,7 @@ $TESTTMP/hgcache/master/packs/077e7ce5dfe862dc40cc8f3c9742d96a056865f2.histpack $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.dataidx $TESTTMP/hgcache/master/packs/935861cae0be6ce41a0d47a529e4d097e9e68a69.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos $ hg repack --background @@ -155,6 +162,7 @@ $TESTTMP/hgcache/master/packs/094b530486dad4427a0faf6bcbc031571b99ca24.histpack $TESTTMP/hgcache/master/packs/8fe685c56f6f7edf550bfcec74eeecc5f3c2ba15.dataidx $TESTTMP/hgcache/master/packs/8fe685c56f6f7edf550bfcec74eeecc5f3c2ba15.datapack + $TESTTMP/hgcache/master/packs/repacklock $TESTTMP/hgcache/repos # Test debug commands @@ -231,6 +239,7 @@ e8fdf7ae22b772dcc291f905b9c6e5f381d28739.datapack ebbd7411e00456c0eec8d1150a77e2b3ef490f3f.histidx ebbd7411e00456c0eec8d1150a77e2b3ef490f3f.histpack + repacklock $ hg debughistorypack $TESTTMP/hgcache/master/packs/*.histidx x