Skip to content

Commit

Permalink
locking: better differentiate new vs. old clients, lock upgrade for r…
Browse files Browse the repository at this point in the history
…eplay

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.
  • Loading branch information
ThomasWaldmann committed Aug 5, 2016
1 parent 64dcbbf commit 33e3348
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion borg/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
6 changes: 5 additions & 1 deletion borg/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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())
Expand All @@ -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):
Expand Down

0 comments on commit 33e3348

Please sign in to comment.