Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/nodemap.py @ 44634:01b0805534bb
nodemap: make sure on disk change get rolled back with the transaction
In case of errors, we need to rollback the change made to the persistent
nodemap.
Differential Revision: https://phab.mercurial-scm.org/D8191
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 28 Feb 2020 03:05:52 +0100 |
parents | 448d700e0d27 |
children | 99ea74cbed74 |
comparison
equal
deleted
inserted
replaced
44633:dd5b47fb0860 | 44634:01b0805534bb |
---|---|
91 self._postclose = {} | 91 self._postclose = {} |
92 | 92 |
93 def addpostclose(self, callback_id, callback_func): | 93 def addpostclose(self, callback_id, callback_func): |
94 self._postclose[callback_id] = callback_func | 94 self._postclose[callback_id] = callback_func |
95 | 95 |
96 def registertmp(self, *args, **kwargs): | |
97 pass | |
98 | |
99 def addbackup(self, *args, **kwargs): | |
100 pass | |
101 | |
102 def add(self, *args, **kwargs): | |
103 pass | |
104 | |
96 | 105 |
97 def update_persistent_nodemap(revlog): | 106 def update_persistent_nodemap(revlog): |
98 """update the persistent nodemap right now | 107 """update the persistent nodemap right now |
99 | 108 |
100 To be used for updating the nodemap on disk outside of a normal transaction | 109 To be used for updating the nodemap on disk outside of a normal transaction |
136 else: | 145 else: |
137 datafile = _rawdata_filepath(revlog, target_docket) | 146 datafile = _rawdata_filepath(revlog, target_docket) |
138 # EXP-TODO: if this is a cache, this should use a cache vfs, not a | 147 # EXP-TODO: if this is a cache, this should use a cache vfs, not a |
139 # store vfs | 148 # store vfs |
140 new_length = target_docket.data_length + len(data) | 149 new_length = target_docket.data_length + len(data) |
150 tr.add(datafile, target_docket.data_length) | |
141 with revlog.opener(datafile, b'r+') as fd: | 151 with revlog.opener(datafile, b'r+') as fd: |
142 fd.seek(target_docket.data_length) | 152 fd.seek(target_docket.data_length) |
143 fd.write(data) | 153 fd.write(data) |
144 if feed_data: | 154 if feed_data: |
145 if use_mmap: | 155 if use_mmap: |
159 data = revlog.index.nodemap_data_all() | 169 data = revlog.index.nodemap_data_all() |
160 else: | 170 else: |
161 data = persistent_data(revlog.index) | 171 data = persistent_data(revlog.index) |
162 # EXP-TODO: if this is a cache, this should use a cache vfs, not a | 172 # EXP-TODO: if this is a cache, this should use a cache vfs, not a |
163 # store vfs | 173 # store vfs |
174 tr.add(datafile, 0) | |
164 with revlog.opener(datafile, b'w+') as fd: | 175 with revlog.opener(datafile, b'w+') as fd: |
165 fd.write(data) | 176 fd.write(data) |
166 if feed_data: | 177 if feed_data: |
167 if use_mmap: | 178 if use_mmap: |
168 new_data = data | 179 new_data = data |
175 # EXP-TODO: if this is a cache, this should use a cache vfs, not a | 186 # EXP-TODO: if this is a cache, this should use a cache vfs, not a |
176 # store vfs | 187 # store vfs |
177 file_path = revlog.nodemap_file | 188 file_path = revlog.nodemap_file |
178 if pending: | 189 if pending: |
179 file_path += b'.a' | 190 file_path += b'.a' |
191 tr.registertmp(file_path) | |
192 else: | |
193 tr.addbackup(file_path) | |
194 | |
180 with revlog.opener(file_path, b'w', atomictemp=True) as fp: | 195 with revlog.opener(file_path, b'w', atomictemp=True) as fp: |
181 fp.write(target_docket.serialize()) | 196 fp.write(target_docket.serialize()) |
182 revlog._nodemap_docket = target_docket | 197 revlog._nodemap_docket = target_docket |
183 if feed_data: | 198 if feed_data: |
184 revlog.index.update_nodemap_data(target_docket, new_data) | 199 revlog.index.update_nodemap_data(target_docket, new_data) |