Mercurial > public > mercurial-scm > hg-stable
diff mercurial/obsolete.py @ 17126:8fa8717b47b6
obsolete: write obsolete marker inside a transaction
Marker are now written as soon as possible but within a transaction. Using a
transaction ensure a proper behavior on error and rollback compatibility.
Flush logic are not necessary anymore and are dropped from lock release.
With this changeset, the obsstore is open, written and closed for every single
added marker. This is expected to be highly inefficient and batched write should
be implemented "quickly".
Another issue is that every flush of the file will invalidate the obsstore
filecache and trigger a full re instantiation of the repo.obsstore attribute
(including, reading and parsing entry). This is also expected to be highly
inefficient and proper filecache operation should be implemented "quickly" too.
A side benefit of the filecache issue is that repo.obsstore object is properly
invalidated on transaction abortion.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 04 Jul 2012 02:21:04 +0200 |
parents | 95d785ccb4e5 |
children | 48c232873a54 |
line wrap: on
line diff
--- a/mercurial/obsolete.py Wed Jul 04 02:02:48 2012 +0200 +++ b/mercurial/obsolete.py Wed Jul 04 02:21:04 2012 +0200 @@ -159,7 +159,6 @@ def __init__(self, sopener): self._all = [] # new markers to serialize - self._new = [] self.precursors = {} self.successors = {} self.sopener = sopener @@ -174,7 +173,7 @@ def __nonzero__(self): return bool(self._all) - def create(self, prec, succs=(), flag=0, metadata=None): + def create(self, transaction, prec, succs=(), flag=0, metadata=None): """obsolete: add a new obsolete marker * ensuring it is hashable @@ -189,39 +188,33 @@ if len(succ) != 20: raise ValueError(succ) marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata)) - self.add(marker) - - def add(self, marker): - """Add a new marker to the store - - This marker still needs to be written to disk""" - self._new.append(marker) - self._load(marker) + self.add(transaction, marker) - def mergemarkers(self, data): - other = set(_readmarkers(data)) - local = set(self._all) - new = other - local - for marker in new: - self.add(marker) - - def flushmarkers(self): - """Write all markers on disk - - After this operation, "new" markers are considered "known".""" - # XXX: transaction logic should be used - if self._new: + def add(self, transaction, marker): + """Add a new marker to the store""" + if marker not in self._all: f = self.sopener('obsstore', 'ab') try: - if f.tell() == 0: - # plain new obsstore + offset = f.tell() + transaction.add('obsstore', offset) + if offset == 0: + # new file add version header f.write(_pack('>B', _fmversion)) - _writemarkers(f.write, self._new) + _writemarkers(f.write, [marker]) + finally: + # XXX: f.close() == filecache invalidation == obsstore rebuilt. + # call 'filecacheentry.refresh()' here f.close() - self._new[:] = [] - except: # re-raises - f.discard() - raise + self._load(marker) + + def mergemarkers(self, transation, data): + other = _readmarkers(data) + local = set(self._all) + new = [m for m in other if m not in local] + for marker in new: + # XXX: N marker == N x (open, write, close) + # we should write them all at once + self.add(transation, marker) def _load(self, marker): self._all.append(marker) @@ -261,8 +254,13 @@ data = base85.b85decode(new) lock = repo.lock() try: - repo.obsstore.mergemarkers(data) - return 1 + tr = repo.transaction('pushkey: obsolete markers') + try: + repo.obsstore.mergemarkers(tr, data) + tr.close() + return 1 + finally: + tr.release() finally: lock.release()