mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-21 21:57:36 +00:00
locking: better differentiate new vs. old clients, lock upgrade for replay
old clients use self.exclusive = None and do a read->write lock upgrade when needed. new clients use self.exclusive = True/False and never upgrade. replay fakes an old client by setting self.exclusive = None to get a lock upgrade if needed.
This commit is contained in:
parent
64dcbbfdd0
commit
33e3348208
2 changed files with 6 additions and 2 deletions
|
@ -114,7 +114,7 @@ def serve(self):
|
|||
def negotiate(self, versions):
|
||||
return RPC_PROTOCOL_VERSION
|
||||
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, append_only=False):
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=None, append_only=False):
|
||||
path = os.fsdecode(path)
|
||||
if path.startswith('/~'):
|
||||
path = path[1:]
|
||||
|
|
|
@ -79,7 +79,7 @@ def __enter__(self):
|
|||
if self.do_create:
|
||||
self.do_create = False
|
||||
self.create(self.path)
|
||||
self.open(self.path, self.exclusive, lock_wait=self.lock_wait, lock=self.do_lock)
|
||||
self.open(self.path, bool(self.exclusive), lock_wait=self.lock_wait, lock=self.do_lock)
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
|
@ -317,6 +317,9 @@ def complete_xfer():
|
|||
self.compact = set()
|
||||
|
||||
def replay_segments(self, index_transaction_id, segments_transaction_id):
|
||||
# fake an old client, so that in case we do not have an exclusive lock yet, prepare_txn will upgrade the lock:
|
||||
remember_exclusive = self.exclusive
|
||||
self.exclusive = None
|
||||
self.prepare_txn(index_transaction_id, do_cleanup=False)
|
||||
try:
|
||||
segment_count = sum(1 for _ in self.io.segment_iterator())
|
||||
|
@ -332,6 +335,7 @@ def replay_segments(self, index_transaction_id, segments_transaction_id):
|
|||
pi.finish()
|
||||
self.write_index()
|
||||
finally:
|
||||
self.exclusive = remember_exclusive
|
||||
self.rollback()
|
||||
|
||||
def _update_index(self, segment, objects, report=None):
|
||||
|
|
Loading…
Reference in a new issue