comparison mercurial/streamclone.py @ 29919:519a02267f90

streamclone: clear caches after writing changes into files for visibility Before this patch, streamclone-ed changes are invisible via @filecache properties to in-process procedures before closing transaction (e.g. pretxnclose python hook), if corresponded property is cached before consumev1(). Strictly speaking, caching should occur inside (store) lock for transaction. repo.invalidate() after closing transaction is too late to force @filecache properties to be reloaded from changed files at next access. For visibility of streamclone-ed changes to in-process procedures before closing transaction, this patch clears caches just after writing changes into files. BTW, regardless of changing in this patch, clearing cached properties in consumev1() causes inconsistency, if (1) transaction is started and (2) any @filecache property is changed before consumev1(). This patch also adds the comment to fix this (potential) inconsistency in the future.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 12 Sep 2016 03:06:29 +0900
parents f32f8bf5dc4c
children 318a24b52eeb
comparison
equal deleted inserted replaced
29918:d9c49138ab93 29919:519a02267f90
296 repo.ui.status(_('%d files to transfer, %s of data\n') % 296 repo.ui.status(_('%d files to transfer, %s of data\n') %
297 (filecount, util.bytecount(bytecount))) 297 (filecount, util.bytecount(bytecount)))
298 handled_bytes = 0 298 handled_bytes = 0
299 repo.ui.progress(_('clone'), 0, total=bytecount, unit=_('bytes')) 299 repo.ui.progress(_('clone'), 0, total=bytecount, unit=_('bytes'))
300 start = time.time() 300 start = time.time()
301
302 # TODO: get rid of (potential) inconsistency
303 #
304 # If transaction is started and any @filecache property is
305 # changed at this point, it causes inconsistency between
306 # in-memory cached property and streamclone-ed file on the
307 # disk. Nested transaction prevents transaction scope "clone"
308 # below from writing in-memory changes out at the end of it,
309 # even though in-memory changes are discarded at the end of it
310 # regardless of transaction nesting.
311 #
312 # But transaction nesting can't be simply prohibited, because
313 # nesting occurs also in ordinary case (e.g. enabling
314 # clonebundles).
301 315
302 with repo.transaction('clone'): 316 with repo.transaction('clone'):
303 with repo.svfs.backgroundclosing(repo.ui, expectedcount=filecount): 317 with repo.svfs.backgroundclosing(repo.ui, expectedcount=filecount):
304 for i in xrange(filecount): 318 for i in xrange(filecount):
305 # XXX doesn't support '\n' or '\r' in filenames 319 # XXX doesn't support '\n' or '\r' in filenames
320 handled_bytes += len(chunk) 334 handled_bytes += len(chunk)
321 repo.ui.progress(_('clone'), handled_bytes, 335 repo.ui.progress(_('clone'), handled_bytes,
322 total=bytecount, unit=_('bytes')) 336 total=bytecount, unit=_('bytes'))
323 ofp.write(chunk) 337 ofp.write(chunk)
324 338
325 # Writing straight to files circumvented the inmemory caches 339 # force @filecache properties to be reloaded from
326 repo.invalidate(clearfilecache=True) 340 # streamclone-ed file at next access
341 repo.invalidate(clearfilecache=True)
327 342
328 elapsed = time.time() - start 343 elapsed = time.time() - start
329 if elapsed <= 0: 344 if elapsed <= 0:
330 elapsed = 0.001 345 elapsed = 0.001
331 repo.ui.progress(_('clone'), None) 346 repo.ui.progress(_('clone'), None)