MCPcopy
hub / github.com/borgbackup/borg / refresh

Method refresh

src/borg/storelocking.py:249–271  ·  view source on GitHub ↗

Refreshes the lock; call this frequently, but not later than every seconds.

(self)

Source from the content-addressed store, hash-verified

247 self._delete_lock(old_locks[0]["key"], update_last_refresh=False)
248
249 def refresh(self):
250 """Refreshes the lock; call this frequently, but not later than every <stale> seconds."""
251 now = datetime.datetime.now(datetime.timezone.utc)
252 if self.last_refresh_dt is not None and now > self.last_refresh_dt + self.refresh_td:
253 old_locks = self._find_locks(only_mine=True)
254 if len(old_locks) == 0:
255 # crap, my lock has been removed. :-(
256 # this can happen e.g. if my machine has been suspended while doing a backup, so that the
257 # lock will auto-expire. a borg client on another machine might then kill that lock.
258 # if my machine then wakes up again, the lock will have vanished and we get here.
259 # in this case, we need to abort the operation, because the other borg might have removed
260 # repo objects we have written, but the referential tree was not yet full present, e.g.
261 # no archive has been added yet to the manifest, thus all objects looked unused/orphaned.
262 # another scenario when this can happen is a careless user running break-lock on another
263 # machine without making sure there is no borg activity in that repo.
264 logger.debug("LOCK-REFRESH: our lock was killed, there is no safe way to continue.")
265 raise LockTimeout(str(self.store))
266 assert len(old_locks) == 1 # there shouldn't be more than 1
267 old_lock = old_locks[0]
268 if now > old_lock["dt"] + self.refresh_td:
269 logger.debug(f"LOCK-REFRESH: lock needs a refresh. lock: {old_lock}.")
270 self._create_lock(exclusive=old_lock["exclusive"], update_last_refresh=True)
271 self._delete_lock(old_lock["key"], update_last_refresh=False)

Callers 2

_lock_refreshMethod · 0.80

Calls 5

_find_locksMethod · 0.95
_create_lockMethod · 0.95
_delete_lockMethod · 0.95
debugMethod · 0.80
LockTimeoutClass · 0.70

Tested by 1