comparison mercurial/revlogutils/nodemap.py @ 44635:99ea74cbed74

nodemap: display percentage of unused in `hg debugnodemap` This is useful to assess the density of the cache. Differential Revision: https://phab.mercurial-scm.org/D8192
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 28 Feb 2020 03:18:57 +0100
parents 01b0805534bb
children c70bcaf7927b
comparison
equal deleted inserted replaced
44634:01b0805534bb 44635:99ea74cbed74
98 98
99 def addbackup(self, *args, **kwargs): 99 def addbackup(self, *args, **kwargs):
100 pass 100 pass
101 101
102 def add(self, *args, **kwargs): 102 def add(self, *args, **kwargs):
103 pass
104
105 def addabort(self, *args, **kwargs):
103 pass 106 pass
104 107
105 108
106 def update_persistent_nodemap(revlog): 109 def update_persistent_nodemap(revlog):
107 """update the persistent nodemap right now 110 """update the persistent nodemap right now
169 data = revlog.index.nodemap_data_all() 172 data = revlog.index.nodemap_data_all()
170 else: 173 else:
171 data = persistent_data(revlog.index) 174 data = persistent_data(revlog.index)
172 # EXP-TODO: if this is a cache, this should use a cache vfs, not a 175 # EXP-TODO: if this is a cache, this should use a cache vfs, not a
173 # store vfs 176 # store vfs
174 tr.add(datafile, 0) 177
178 tryunlink = revlog.opener.tryunlink
179
180 def abortck(tr):
181 tryunlink(datafile)
182
183 callback_id = b"delete-%s" % datafile
184
185 # some flavor of the transaction abort does not cleanup new file, it
186 # simply empty them.
187 tr.addabort(callback_id, abortck)
175 with revlog.opener(datafile, b'w+') as fd: 188 with revlog.opener(datafile, b'w+') as fd:
176 fd.write(data) 189 fd.write(data)
177 if feed_data: 190 if feed_data:
178 if use_mmap: 191 if use_mmap:
179 new_data = data 192 new_data = data
195 with revlog.opener(file_path, b'w', atomictemp=True) as fp: 208 with revlog.opener(file_path, b'w', atomictemp=True) as fp:
196 fp.write(target_docket.serialize()) 209 fp.write(target_docket.serialize())
197 revlog._nodemap_docket = target_docket 210 revlog._nodemap_docket = target_docket
198 if feed_data: 211 if feed_data:
199 revlog.index.update_nodemap_data(target_docket, new_data) 212 revlog.index.update_nodemap_data(target_docket, new_data)
200
201 # EXP-TODO: if the transaction abort, we should remove the new data and
202 # reinstall the old one.
203 213
204 # search for old index file in all cases, some older process might have 214 # search for old index file in all cases, some older process might have
205 # left one behind. 215 # left one behind.
206 olds = _other_rawdata_filepath(revlog, target_docket) 216 olds = _other_rawdata_filepath(revlog, target_docket)
207 if olds: 217 if olds: