comparison mercurial/revlogutils/nodemap.py @ 44335:e41a164db7a9

nodemap: track the maximum revision tracked in the nodemap We need a simple way to detect when the on disk data contains less revision than the index we read from disk. The docket file is meant for this, we just had to start tracking that data. We should also try to detect strip operation, but we will deal with this in later changesets. Right now we are focusing on defining the API for index supporting persistent nodemap. Differential Revision: https://phab.mercurial-scm.org/D7888
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:50:14 +0100
parents 50ad851efd9b
children 8374b69aef75
comparison
equal deleted inserted replaced
44334:6614b301ea58 44335:e41a164db7a9
34 offset = 0 34 offset = 0
35 (version,) = S_VERSION.unpack(pdata[offset : offset + S_VERSION.size]) 35 (version,) = S_VERSION.unpack(pdata[offset : offset + S_VERSION.size])
36 if version != ONDISK_VERSION: 36 if version != ONDISK_VERSION:
37 return None 37 return None
38 offset += S_VERSION.size 38 offset += S_VERSION.size
39 (uid_size,) = S_HEADER.unpack(pdata[offset : offset + S_HEADER.size]) 39 headers = S_HEADER.unpack(pdata[offset : offset + S_HEADER.size])
40 uid_size, tip_rev = headers
40 offset += S_HEADER.size 41 offset += S_HEADER.size
41 docket = NodeMapDocket(pdata[offset : offset + uid_size]) 42 docket = NodeMapDocket(pdata[offset : offset + uid_size])
43 docket.tip_rev = tip_rev
42 44
43 filename = _rawdata_filepath(revlog, docket) 45 filename = _rawdata_filepath(revlog, docket)
44 return docket, revlog.opener.tryread(filename) 46 return docket, revlog.opener.tryread(filename)
45 47
46 48
92 data = persistent_data(revlog.index) 94 data = persistent_data(revlog.index)
93 # EXP-TODO: if this is a cache, this should use a cache vfs, not a 95 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
94 # store vfs 96 # store vfs
95 with revlog.opener(datafile, b'w') as fd: 97 with revlog.opener(datafile, b'w') as fd:
96 fd.write(data) 98 fd.write(data)
99 target_docket.tip_rev = revlog.tiprev()
97 # EXP-TODO: if this is a cache, this should use a cache vfs, not a 100 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
98 # store vfs 101 # store vfs
99 with revlog.opener(revlog.nodemap_file, b'w', atomictemp=True) as fp: 102 with revlog.opener(revlog.nodemap_file, b'w', atomictemp=True) as fp:
100 fp.write(target_docket.serialize()) 103 fp.write(target_docket.serialize())
101 revlog._nodemap_docket = target_docket 104 revlog._nodemap_docket = target_docket
140 143
141 # version 0 is experimental, no BC garantee, do no use outside of tests. 144 # version 0 is experimental, no BC garantee, do no use outside of tests.
142 ONDISK_VERSION = 0 145 ONDISK_VERSION = 0
143 146
144 S_VERSION = struct.Struct(">B") 147 S_VERSION = struct.Struct(">B")
145 S_HEADER = struct.Struct(">B") 148 S_HEADER = struct.Struct(">BQ")
146 149
147 ID_SIZE = 8 150 ID_SIZE = 8
148 151
149 152
150 def _make_uid(): 153 def _make_uid():
162 165
163 def __init__(self, uid=None): 166 def __init__(self, uid=None):
164 if uid is None: 167 if uid is None:
165 uid = _make_uid() 168 uid = _make_uid()
166 self.uid = uid 169 self.uid = uid
170 self.tip_rev = None
167 171
168 def copy(self): 172 def copy(self):
169 return NodeMapDocket(uid=self.uid) 173 new = NodeMapDocket(uid=self.uid)
174 new.tip_rev = self.tip_rev
175 return new
170 176
171 def serialize(self): 177 def serialize(self):
172 """return serialized bytes for a docket using the passed uid""" 178 """return serialized bytes for a docket using the passed uid"""
173 data = [] 179 data = []
174 data.append(S_VERSION.pack(ONDISK_VERSION)) 180 data.append(S_VERSION.pack(ONDISK_VERSION))
175 data.append(S_HEADER.pack(len(self.uid))) 181 headers = (len(self.uid), self.tip_rev)
182 data.append(S_HEADER.pack(*headers))
176 data.append(self.uid) 183 data.append(self.uid)
177 return b''.join(data) 184 return b''.join(data)
178 185
179 186
180 def _rawdata_filepath(revlog, docket): 187 def _rawdata_filepath(revlog, docket):