fastmanifest: iterate by filename instead of os.listdir order

Summary:
Before this patch, we were iterating over the cache entries in a non-
deterministic fashion. This patch makes the iteration stable by ordering the
entries by filename.

Test Plan: Changed the tests accordingly

Reviewers: ttung

Differential Revision: https://phabricator.intern.facebook.com/D3336880
This commit is contained in:
Laurent Charignon 2016-05-23 14:57:38 -07:00
parent ee782fcb95
commit e84d5b370e
2 changed files with 27 additions and 28 deletions

View File

@ -345,7 +345,7 @@ class fastmanifestcache(object):
pass
def __iter__(self):
for f in os.listdir(self.cachepath):
for f in sorted(os.listdir(self.cachepath)):
if f.startswith(self.keyprefix()):
yield f

View File

@ -203,10 +203,10 @@ there is a concurrency issue to address
$ sleep 1
$ hg debugcachemanifest --list
fast7ab5760d084a24168f7595c38c00f4bbc2e308d9 (size 328 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0 (size 136 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
cache size is: 1.13 KB
$ hg diff -c . --debug --nodate
cache hit for fastmanifest f064a7f8e3e138341587096641d86e9d23cd9778
@ -223,10 +223,10 @@ Test the --pruneall command to prune all the cached manifests
$ hg debugcachemanifest --pruneall --debug
caching rev: [], background(False), pruneall(True), list(False)
removing cached manifest fast7ab5760d084a24168f7595c38c00f4bbc2e308d9
removing cached manifest fastf064a7f8e3e138341587096641d86e9d23cd9778
removing cached manifest faste3738bf5439958f89499a656982023aba57b076e
removing cached manifest fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7
removing cached manifest fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0
removing cached manifest fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7
removing cached manifest faste3738bf5439958f89499a656982023aba57b076e
removing cached manifest fastf064a7f8e3e138341587096641d86e9d23cd9778
$ hg diff -c . --debug --nodate
cache miss for fastmanifest f064a7f8e3e138341587096641d86e9d23cd9778
@ -293,10 +293,10 @@ to make the test deterministic:
$ hg debugcachemanifest --debug --list
caching rev: [], background(False), pruneall(False), list(True)
fast7ab5760d084a24168f7595c38c00f4bbc2e308d9 (size 328 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0 (size 136 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
cache size is: 1.13 KB
Check that trimming to a limit higher than what is cached does nothing
@ -307,31 +307,30 @@ Check that trimming to a limit higher than what is cached does nothing
Trim the cache to at most 1kb
$ hg debugcachemanifest --debug --limit=1024
caching rev: [], background(False), pruneall(False), list(False)
removing cached manifest fastf064a7f8e3e138341587096641d86e9d23cd9778
$ hg debugcachemanifest --debug --list
caching rev: [], background(False), pruneall(False), list(True)
fast7ab5760d084a24168f7595c38c00f4bbc2e308d9 (size 328 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0 (size 136 bytes)
cache size is: 880 bytes
Trim the cache to at most 512 bytes
$ hg debugcachemanifest --debug --limit=512
caching rev: [], background(False), pruneall(False), list(False)
removing cached manifest fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7
removing cached manifest faste3738bf5439958f89499a656982023aba57b076e
$ hg debugcachemanifest --debug --list
caching rev: [], background(False), pruneall(False), list(True)
fast7ab5760d084a24168f7595c38c00f4bbc2e308d9 (size 328 bytes)
fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0 (size 136 bytes)
cache size is: 464 bytes
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
cache size is: 928 bytes
Trim the cache to at most 512 bytes
$ hg debugcachemanifest --debug --limit=512
caching rev: [], background(False), pruneall(False), list(False)
removing cached manifest fastf064a7f8e3e138341587096641d86e9d23cd9778
removing cached manifest fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0
removing cached manifest fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7
$ hg debugcachemanifest --debug --list
caching rev: [], background(False), pruneall(False), list(True)
fast7ab5760d084a24168f7595c38c00f4bbc2e308d9 (size 328 bytes)
cache size is: 328 bytes
Trim the cache to at most 100 bytes
$ hg debugcachemanifest --debug --limit=100
caching rev: [], background(False), pruneall(False), list(False)
removing cached manifest fast7ab5760d084a24168f7595c38c00f4bbc2e308d9
removing cached manifest fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0
$ hg debugcachemanifest --debug --list
caching rev: [], background(False), pruneall(False), list(True)
cache size is: 0 bytes
@ -341,10 +340,10 @@ Check that trimming the cache to 0 byte works
$ hg debugcachemanifest --debug --list
caching rev: [], background(False), pruneall(False), list(True)
fast7ab5760d084a24168f7595c38c00f4bbc2e308d9 (size 328 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
fasta0c8bcbbb45c63b90b70ad007bf38961f64f2af0 (size 136 bytes)
fasta539ce0c1a22b0ecf34498f9f5ce8ea56df9ecb7 (size 184 bytes)
faste3738bf5439958f89499a656982023aba57b076e (size 232 bytes)
fastf064a7f8e3e138341587096641d86e9d23cd9778 (size 280 bytes)
cache size is: 1.13 KB
$ hg debugcachemanifest --debug --limit=0
caching rev: [], background(False), pruneall(False), list(False)