annotate hgext3rd/evolve/obscache.py @ 4488:6c0992ce05f7

compat: drop getcachevfs, repo.cachevfs is supported in hg 4.4
author Joerg Sonnenberger <joerg@bec.de>
date Sun, 07 Apr 2019 20:00:16 +0200
parents d562316c548f
children f0ecf2137824
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
1 # Code dedicated to an cache around obsolescence property
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
2 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
3 # This module content aims at being upstreamed.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
4 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
5 # Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
6 #
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of the
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
8 # GNU General Public License version 2 or any later version.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
9
2424
4afbcdcfa9b2 compat: handle lack of 'util.timer' for pre 4.2 version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2387
diff changeset
10 import errno
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
11 import hashlib
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
12 import struct
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
13
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
14 from mercurial import (
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
15 localrepo,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
16 obsolete,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
17 phases,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
18 node,
2315
e16f6bef5848 compat: make obscache code compatible with Mercurial version prior to 4.2
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2309
diff changeset
19 util,
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
20 )
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
21
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
22 from . import (
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
23 exthelper,
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
24 )
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
25
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
26 eh = exthelper.exthelper()
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
27
3144
6f10c94a2114 compat: stop working around 3.8 file cache limitation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3036
diff changeset
28 obsstorefilecache = localrepo.localrepository.obsstore
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
29
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
30 # obsstore is a filecache so we have do to some spacial dancing
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
31 @eh.wrapfunction(obsstorefilecache, 'func')
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
32 def obsstorewithcache(orig, repo):
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
33 obsstore = orig(repo)
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
34 obsstore.obscache = obscache(repo.unfiltered())
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
35
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
36 class cachekeyobsstore(obsstore.__class__):
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
37
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
38 _obskeysize = 200
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
39
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
40 def cachekey(self, index=None):
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
41 """return (current-length, cachekey)
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
42
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
43 'current-length': is the current length of the obsstore storage file,
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
44 'cachekey' is the hash of the last 200 bytes ending at 'index'.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
45
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
46 if 'index' is unspecified, current obsstore length is used.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
47 Cacheckey will be set to null id if the obstore is empty.
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
48
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
49 If the index specified is higher than the current obsstore file
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
50 length, cachekey will be set to None."""
2306
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
51 # default value
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
52 obsstoresize = 0
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
53 keydata = ''
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
54 # try to get actual data from the obsstore
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
55 try:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
56 with self.svfs('obsstore') as obsfile:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
57 obsfile.seek(0, 2)
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
58 obsstoresize = obsfile.tell()
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
59 if index is None:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
60 index = obsstoresize
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
61 elif obsstoresize < index:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
62 return obsstoresize, None
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
63 actualsize = min(index, self._obskeysize)
2306
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
64 if actualsize:
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
65 obsfile.seek(index - actualsize, 0)
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
66 keydata = obsfile.read(actualsize)
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
67 except (OSError, IOError) as e:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
68 if e.errno != errno.ENOENT:
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
69 raise
2354
fed22455e510 obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2353
diff changeset
70 if keydata:
fed22455e510 obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2353
diff changeset
71 key = hashlib.sha1(keydata).digest()
fed22455e510 obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2353
diff changeset
72 else:
fed22455e510 obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2353
diff changeset
73 # reusing an existing "empty" value make it easier to define a
fed22455e510 obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2353
diff changeset
74 # default cachekey for 'no data'.
fed22455e510 obscache: use 'nullid' as the hash of an empty obsstore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2353
diff changeset
75 key = node.nullid
2306
b33bc2f37e89 obscache: have the obsstore fix empty file cachekey
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2305
diff changeset
76 return obsstoresize, key
2294
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
77
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
78 obsstore.__class__ = cachekeyobsstore
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
79
75996eafab43 perf: adds some cache key helper on the obsstore class
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
80 return obsstore
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
81
2328
7ccacaa38782 obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2327
diff changeset
82 def markersfrom(obsstore, byteoffset, firstmarker):
2345
406c1a57b4ee obscache: return the new data along-side the upgrade needs (and cache key)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2344
diff changeset
83 if not firstmarker:
406c1a57b4ee obscache: return the new data along-side the upgrade needs (and cache key)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2344
diff changeset
84 return list(obsstore)
406c1a57b4ee obscache: return the new data along-side the upgrade needs (and cache key)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2344
diff changeset
85 elif '_all' in vars(obsstore):
2328
7ccacaa38782 obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2327
diff changeset
86 # if the data are in memory, just use that
7ccacaa38782 obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2327
diff changeset
87 return obsstore._all[firstmarker:]
7ccacaa38782 obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2327
diff changeset
88 else:
7ccacaa38782 obscache: Only access the new obsmarkers for marker update
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2327
diff changeset
89 obsdata = obsstore.svfs.tryread('obsstore')
3687
50f1968724f0 obscache: drop compat layer for obsmarkers reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3685
diff changeset
90 return obsolete._readmarkers(obsdata, byteoffset)[1]
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
91
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
92
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
93 class dualsourcecache(object):
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
94 """An abstract class for cache that needs both changelog and obsstore
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
95
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
96 This class handle the tracking of changelog and obsstore update. It provide
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
97 data to performs incremental update (see the 'updatefrom' function for
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
98 details). This class can also detect stripping of the changelog or the
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
99 obsstore and can reset the cache in this cache (see the 'clear' function
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
100 for details).
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
101 """
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
102
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
103 # default key used for an empty cache
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
104 #
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
105 # The cache key covering the changesets and obsmarkers content
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
106 #
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
107 # The cache key parts are:
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
108 # - tip-rev,
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
109 # - tip-node,
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
110 # - obsstore-length (nb markers),
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
111 # - obsstore-file-size (in bytes),
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
112 # - obsstore "cache key"
2353
393cbaf0d294 obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2352
diff changeset
113 emptykey = (node.nullrev, node.nullid, 0, 0, node.nullid)
2376
12386f7f5056 dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2375
diff changeset
114 _cachename = None # used for error message
2353
393cbaf0d294 obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2352
diff changeset
115
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
116 def __init__(self):
2359
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
117 super(dualsourcecache, self).__init__()
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
118 self._cachekey = None
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
119
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
120 def _updatefrom(self, repo, revs, obsmarkers):
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
121 """override this method to update your cache data incrementally
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
122
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
123 revs: list of new revision in the changelog
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
124 obsmarker: list of new obsmarkers in the obsstore
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
125 """
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
126 raise NotImplementedError
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
127
2333
adf114c767ab obscache: distinct 'clear' and 'reset'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2330
diff changeset
128 def clear(self, reset=False):
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
129 """invalidate the cache content
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
130
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
131 if 'reset' is passed, we detected a strip and the cache will have to be
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
132 recomputed.
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
133 """
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
134 # /!\ IMPORTANT /!\
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
135 # You must overide this method to actually
2387
a41d900d015c dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2385
diff changeset
136 if reset:
a41d900d015c dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2385
diff changeset
137 self._cachekey = self.emptykey if reset else None
a41d900d015c dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2385
diff changeset
138 else:
a41d900d015c dualsourcecache: simplify cachekey.clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2385
diff changeset
139 self._cachekey = None
2359
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
140
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
141 def load(self, repo):
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
142 """Load data from disk
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
143
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
144 Do not forget to restore the "cachekey" attribute while doing so.
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
145 """
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
146 raise NotImplementedError
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
147
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
148 # Useful public function (no need to override them)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
149
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
150 def uptodate(self, repo):
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
151 """return True if the cache content is up to date False otherwise
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
152
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
153 This method can be used to detect of the cache is lagging behind new
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
154 data in either changelog or obsstore.
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
155 """
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
156 if self._cachekey is None:
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
157 self.load(repo)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
158 status = self._checkkey(repo.changelog, repo.obsstore)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
159 return (status is not None
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
160 and status[0] == self._cachekey[0] # tiprev
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
161 and status[1] == self._cachekey[3]) # obssize
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
162
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
163 def update(self, repo):
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
164 """update the cache with new repository data
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
165
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
166 The update will be incremental when possible"""
2359
ff635fa59a25 obscache: makes dualsourcecache compatible with obshashrange cache needs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2357
diff changeset
167 repo = repo.unfiltered()
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
168 # If we do not have any data, try loading from disk
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
169 if self._cachekey is None:
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
170 self.load(repo)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
171
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
172 assert repo.filtername is None
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
173 cl = repo.changelog
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
174
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
175 upgrade = self._upgradeneeded(repo)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
176 if upgrade is None:
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
177 return
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
178
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
179 reset, revs, obsmarkers, obskeypair = upgrade
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
180 if reset or self._cachekey is None:
2382
42092b9d6d25 dualsourcecache: log cache reset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2380
diff changeset
181 repo.ui.log('evoext-cache', 'strip detected, %s cache reset\n' % self._cachename)
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
182 self.clear(reset=True)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
183
3685
bf000d1a525f timer: drop compat layer for time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3645
diff changeset
184 starttime = util.timer()
3507
c0b6a95b94b9 pure: make sure what we expect to be list are list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3409
diff changeset
185 revs = list(revs)
c0b6a95b94b9 pure: make sure what we expect to be list are list
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3409
diff changeset
186 obsmarkers = list(obsmarkers)
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
187 self._updatefrom(repo, revs, obsmarkers)
3685
bf000d1a525f timer: drop compat layer for time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3645
diff changeset
188 duration = util.timer() - starttime
2380
694494619795 cache: track time spend updating various cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2379
diff changeset
189 repo.ui.log('evoext-cache', 'updated %s in %.4f seconds (%sr, %so)\n',
694494619795 cache: track time spend updating various cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2379
diff changeset
190 self._cachename, duration, len(revs), len(obsmarkers))
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
191
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
192 # update the key from the new data
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
193 key = list(self._cachekey)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
194 if revs:
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
195 key[0] = len(cl) - 1
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
196 key[1] = cl.node(key[0])
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
197 if obsmarkers:
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
198 key[2] += len(obsmarkers)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
199 key[3], key[4] = obskeypair
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
200 self._cachekey = tuple(key)
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
201
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
202 # from here, there are internal function only
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
203
2352
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
204 def _checkkey(self, changelog, obsstore):
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
205 """internal function"""
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
206 key = self._cachekey
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
207 if key is None:
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
208 return None
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
209
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
210 ### Is the cache valid ?
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
211 keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
212 # check for changelog strip
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
213 tiprev = len(changelog) - 1
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
214 if (tiprev < keytiprev
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
215 or changelog.node(keytiprev) != keytipnode):
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
216 return None
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
217 # check for obsstore strip
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
218 obssize, obskey = obsstore.cachekey(index=keyobssize)
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
219 if obskey != keyobskey:
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
220 return None
2385
fab59e2cb05f dualsourcecache: fix obskey return by _checkkey
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2382
diff changeset
221 if obssize != keyobssize:
fab59e2cb05f dualsourcecache: fix obskey return by _checkkey
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2382
diff changeset
222 # we want to return the obskey for the new size
fab59e2cb05f dualsourcecache: fix obskey return by _checkkey
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2382
diff changeset
223 __, obskey = obsstore.cachekey(index=obssize)
2352
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
224 return tiprev, obssize, obskey
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
225
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
226 def _upgradeneeded(self, repo):
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
227 """return (valid, start-rev, start-obs-idx)
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
228
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
229 'valid': is "False" if older cache value needs invalidation,
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
230
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
231 'start-rev': first revision not in the cache. None if cache is up to date,
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
232
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
233 'start-obs-idx': index of the first obs-markers not in the cache. None is
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
234 up to date.
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
235 """
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
236
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
237 # We need to ensure we use the same changelog and obsstore through the
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
238 # processing. Otherwise some invalidation could update the object and their
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
239 # content after we computed the cache key.
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
240 cl = repo.changelog
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
241 obsstore = repo.obsstore
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
242 key = self._cachekey
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
243
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
244 reset = False
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
245
2352
dd8471e54708 obcache: move _checkkey on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2351
diff changeset
246 status = self._checkkey(cl, obsstore)
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
247 if status is None:
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
248 reset = True
2353
393cbaf0d294 obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2352
diff changeset
249 key = self.emptykey
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
250 obssize, obskey = obsstore.cachekey()
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
251 tiprev = len(cl) - 1
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
252 else:
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
253 tiprev, obssize, obskey = status
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
254
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
255 keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
256
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
257 if not reset and keytiprev == tiprev and keyobssize == obssize:
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
258 return None # nothing to upgrade
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
259
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
260 ### cache is valid, is there anything to update
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
261
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
262 # any new changesets ?
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
263 revs = ()
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
264 if keytiprev < tiprev:
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
265 revs = list(cl.revs(start=keytiprev + 1, stop=tiprev))
2295
017b971ba28f perf: adds cachekey utility to validate changelog+obsstore content
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2294
diff changeset
266
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
267 # any new markers
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
268 markers = ()
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
269 if keyobssize < obssize:
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
270 # XXX Three are a small race change here. Since the obsstore might have
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
271 # move forward between the time we computed the cache key and we access
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
272 # the data. To fix this we need so "up to" argument when fetching the
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
273 # markers here. Otherwise we might return more markers than covered by
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
274 # the cache key.
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
275 #
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
276 # In pratice the cache is only updated after each transaction within a
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
277 # lock. So we should be fine. We could enforce this with a new repository
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
278 # requirement (or fix the race, that is not too hard).
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
279 markers = markersfrom(obsstore, keyobssize, keyobslength)
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
280
2351
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
281 return reset, revs, markers, (obssize, obskey)
1bec5ee99674 obcache: move updateneeded on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2347
diff changeset
282
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
283 class obscache(dualsourcecache):
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
284 """cache the "does a rev" is the precursors of some obsmarkers data
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
285
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
286 This is not directly holding the "is this revision obsolete" information,
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
287 because phases data gets into play here. However, it allow to compute the
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
288 "obsolescence" set without reading the obsstore content.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
289
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
290 Implementation note #1:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
291
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
292 The obsstore is implementing only half of the transaction logic it
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
293 should. It properly record the starting point of the obsstore to allow
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
294 clean rollback. However it still write to the obsstore file directly
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
295 during the transaction. Instead it should be keeping data in memory and
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
296 write to a '.pending' file to make the data vailable for hooks.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
297
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
298 This cache is not going futher than what the obstore is doing, so it does
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
299 not has any '.pending' logic. When the obsstore gains proper '.pending'
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
300 support, adding it to this cache should not be too hard. As the flag
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
301 always move from 0 to 1, we could have a second '.pending' cache file to
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
302 be read. If flag is set in any of them, the value is 1. For the same
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
303 reason, updating the file in place should be possible.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
304
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
305 Implementation note #2:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
306
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
307 Instead of having a large final update run, we could update this cache at
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
308 the level adding a new changeset or a new obsmarkers. More on this in the
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
309 'update code'.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
310
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
311 Implementation note #3:
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
312
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
313 Storage-wise, we could have a "start rev" to avoid storing useless
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
314 zero. That would be especially useful for the '.pending' overlay.
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
315 """
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
316
2749
e1b7ea48e243 compat: use 'repo.cachevfs' when available
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2594
diff changeset
317 _filepath = 'evoext-obscache-00'
2302
acd2431dff29 obscache: update the format to allow negative tiprev
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2301
diff changeset
318 _headerformat = '>q20sQQ20s'
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
319
2376
12386f7f5056 dualsourcecache: add a cache name
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2375
diff changeset
320 _cachename = 'evo-ext-obscache' # used for error message
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
321
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
322 def __init__(self, repo):
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
323 super(obscache, self).__init__()
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
324 self._ondiskkey = None
2552
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
325
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
326 @util.propertycache
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
327 def get(self):
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
328 """final signature: obscache.get(rev)
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
329
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
330 return True if "rev" is used as "precursors for any obsmarkers
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
331
2552
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
332 IMPORTANT: make sure the cache has been updated to match the repository
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
333 content before using it
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
334
2552
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
335 We use a property cache to skip the attribute resolution overhead in
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
336 hot loops."""
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
337 return self._data.__getitem__
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
338
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
339 def _setdata(self, data):
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
340 """set a new bytearray data, invalidating the 'get' shortcut if needed"""
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
341 self._data = data
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
342 if 'get' in vars(self):
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
343 del self.get
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
344
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
345 def clear(self, reset=False):
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
346 """invalidate the cache content"""
2357
f787f5406a98 obscache: extract a data agnostic class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2356
diff changeset
347 super(obscache, self).clear(reset=reset)
2552
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
348 self._setdata(bytearray())
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
349
2356
d5de0529a48f obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2355
diff changeset
350 def _updatefrom(self, repo, revs, obsmarkers):
d5de0529a48f obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2355
diff changeset
351 if revs:
d5de0529a48f obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2355
diff changeset
352 self._updaterevs(repo, revs)
d5de0529a48f obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2355
diff changeset
353 if obsmarkers:
d5de0529a48f obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2355
diff changeset
354 self._updatemarkers(repo, obsmarkers)
d5de0529a48f obscache: extract the actual data update in a dedicated function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2355
diff changeset
355
2326
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
356 def _updaterevs(self, repo, revs):
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
357 """update the cache with new revisions
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
358
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
359 Newly added changeset might be affected by obsolescence markers
2329
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
360 we already have locally. So we needs to have some global
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
361 knowledge about the markers to handle that question.
2326
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
362
2329
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
363 Right now this requires parsing all markers in the obsstore. We could
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
364 imagine using various optimisation (eg: another cache, network
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
365 exchange, etc).
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
366
2330
d72c8c1f09e2 obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2329
diff changeset
367 A possible approach to this is to build a set of all node used as
d72c8c1f09e2 obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2329
diff changeset
368 precursors in `obsstore._obscandidate`. If markers are not loaded yet,
d72c8c1f09e2 obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2329
diff changeset
369 we could initialize it by doing a quick scan through the obsstore data
d72c8c1f09e2 obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2329
diff changeset
370 and filling a (pre-sized) set. Doing so would be much faster than
d72c8c1f09e2 obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2329
diff changeset
371 parsing all the obsmarkers since we would access less data, not create
d72c8c1f09e2 obscache: document a possible way forward to skipping obsstore parsing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2329
diff changeset
372 any object beside the nodes and not have to decode any complex data.
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
373
2329
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
374 For now we stick to the simpler approach of paying the
2326
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
375 performance cost on new changesets.
72853bade853 obscache: extract code to update from new revision
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2325
diff changeset
376 """
2570
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
377 new_entries = bytearray(len(revs))
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
378 if not self._data:
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
379 self._setdata(new_entries)
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
380 else:
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
381 self._data.extend(new_entries)
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
382 data = self._data
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
383 if repo.obsstore:
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
384 node = repo.changelog.node
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
385 succs = repo.obsstore.successors
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
386 for r in revs:
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
387 if node(r) in succs:
86959f2c625d obscache: directly allocate zeroed bytearray
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2569
diff changeset
388 data[r] = 1
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
389
2327
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
390 def _updatemarkers(self, repo, obsmarkers):
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
391 """update the cache with new markers"""
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
392 rev = repo.changelog.nodemap.get
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
393 for m in obsmarkers:
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
394 r = rev(m[0])
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
395 if r is not None:
6b751daad348 obscache: extract _updatemarkers code into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2326
diff changeset
396 self._data[r] = 1
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
397
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
398 def save(self, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
399 """save the data to disk"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
400
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
401 # XXX it happens that the obsstore is (buggilly) always up to date on disk
2309
9f09cabe679e obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2308
diff changeset
402 if self._cachekey is None or self._cachekey == self._ondiskkey:
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
403 return
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
404
4097
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
405 try:
4488
6c0992ce05f7 compat: drop getcachevfs, repo.cachevfs is supported in hg 4.4
Joerg Sonnenberger <joerg@bec.de>
parents: 4109
diff changeset
406 cachefile = repo.cachevfs(self._filepath, 'w', atomictemp=True)
4097
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
407 headerdata = struct.pack(self._headerformat, *self._cachekey)
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
408 cachefile.write(headerdata)
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
409 cachefile.write(self._data)
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
410 cachefile.close()
4098
c9fc82c4e66d obscache: update the variable tracking on disk state after write
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4097
diff changeset
411 self._ondiskkey = self._cachekey
4097
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
412 except (IOError, OSError) as exc:
4109
d562316c548f caches: issue both debug and blackbox log message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4098
diff changeset
413 repo.ui.log('obscache', 'could not write update %s\n' % exc)
4097
4ea2a813b82c obscache: ignore permission and OS errors when writing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3975
diff changeset
414 repo.ui.debug('obscache: could not write update %s\n' % exc)
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
415
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
416 def load(self, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
417 """load data from disk"""
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
418 assert repo.filtername is None
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
419
4488
6c0992ce05f7 compat: drop getcachevfs, repo.cachevfs is supported in hg 4.4
Joerg Sonnenberger <joerg@bec.de>
parents: 4109
diff changeset
420 data = repo.cachevfs.tryread(self._filepath)
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
421 if not data:
2353
393cbaf0d294 obcache: move empty on the class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2352
diff changeset
422 self._cachekey = self.emptykey
2552
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
423 self._setdata(bytearray())
2309
9f09cabe679e obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2308
diff changeset
424 else:
9f09cabe679e obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2308
diff changeset
425 headersize = struct.calcsize(self._headerformat)
9f09cabe679e obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2308
diff changeset
426 self._cachekey = struct.unpack(self._headerformat, data[:headersize])
2552
006400e25e22 obscache: shortcut the attribute access for testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
427 self._setdata(bytearray(data[headersize:]))
2309
9f09cabe679e obscache: skip writing to disk if the data did not changed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2308
diff changeset
428 self._ondiskkey = self._cachekey
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
429
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
430 def _computeobsoleteset(orig, repo):
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
431 """the set of obsolete revisions"""
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
432 obs = set()
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
433 repo = repo.unfiltered()
3688
bda024010aed obscache: drop compat layer to access public changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3687
diff changeset
434 notpublic = repo._phasecache.getrevset(repo, (phases.draft, phases.secret))
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
435 if notpublic:
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
436 obscache = repo.obsstore.obscache
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
437 # Since we warm the cache at the end of every transaction, the cache
2329
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
438 # should be up to date. However a non-enabled client might have touched
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
439 # the repository.
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
440 #
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
441 # Updating the cache without a lock is sloppy, so we fallback to the
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
442 # old method and rely on the fact the next transaction will write the
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
443 # cache down anyway.
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
444 #
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
445 # With the current implementation updating the cache will requires to
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
446 # load the obsstore anyway. Once loaded, hitting the obsstore directly
2329
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
447 # will be about as fast...
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
448 if not obscache.uptodate(repo):
2304
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
449 if repo.currenttransaction() is None:
2379
3593442d4a0e obshashrange: adds blackbox usage in tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2376
diff changeset
450 repo.ui.log('evoext-cache',
2305
a786240c95bd obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2304
diff changeset
451 'obscache is out of date, '
a786240c95bd obscache: log case where the cache is not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2304
diff changeset
452 'falling back to slower obsstore version\n')
2554
08bd8ab55cc9 obscache: add a missing "new line" at the end of a debug message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2424
diff changeset
453 repo.ui.debug('obscache is out of date\n')
2304
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
454 return orig(repo)
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
455 else:
2329
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
456 # If a transaction is open, it is worthwhile to update and use
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
457 # the cache, the lock prevent race and it will be written on
3bb8382fc4cb obscache: update some documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2328
diff changeset
458 # disk when the transaction close.
2304
2f15090712fe obscache: still update and use the cache during transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2303
diff changeset
459 obscache.update(repo)
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
460 isobs = obscache.get
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
461 for r in notpublic:
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
462 if isobs(r):
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
463 obs.add(r)
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
464 return obs
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
465
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
466 @eh.uisetup
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
467 def cachefuncs(ui):
2300
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
468 orig = obsolete.cachefuncs['obsolete']
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
469 wrapped = lambda repo: _computeobsoleteset(orig, repo)
01efebff13ec obscache: skip the cache entirely if not up to date
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2298
diff changeset
470 obsolete.cachefuncs['obsolete'] = wrapped
2298
8199204274f0 perf: use the cache to compute the obsolete set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2297
diff changeset
471
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
472 @eh.reposetup
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
473 def setupcache(ui, repo):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
474
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
475 class obscacherepo(repo.__class__):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
476
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
477 @localrepo.unfilteredmethod
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
478 def destroyed(self):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
479 if 'obsstore' in vars(self):
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
480 self.obsstore.obscache.clear()
2367
3be45918c7b5 evolve: fixing obscache invalidation
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 2316
diff changeset
481 super(obscacherepo, self).destroyed()
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
482
3968
37178a2d3557 compat: drop compatibility layer for updatecaches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3688
diff changeset
483 @localrepo.unfilteredmethod
37178a2d3557 compat: drop compatibility layer for updatecaches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3688
diff changeset
484 def updatecaches(self, tr=None, **kwargs):
37178a2d3557 compat: drop compatibility layer for updatecaches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3688
diff changeset
485 super(obscacherepo, self).updatecaches(tr, **kwargs)
37178a2d3557 compat: drop compatibility layer for updatecaches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3688
diff changeset
486 self.obsstore.obscache.update(self)
37178a2d3557 compat: drop compatibility layer for updatecaches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3688
diff changeset
487 self.obsstore.obscache.save(self)
2297
32cdcf493567 perf: warm the cache after all transactions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2296
diff changeset
488
2296
d6584ce58030 perf: adds a cache to know if obsmarkers might affect a revision
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2295
diff changeset
489 repo.__class__ = obscacherepo