mirror of
https://github.com/netinvent/npbackup.git
synced 2025-12-18 14:09:23 +08:00
Generalize don't acquire locks for certain ops
This commit is contained in:
parent
586cc16266
commit
d4e68ff1fc
2 changed files with 42 additions and 5 deletions
|
|
@ -7,7 +7,7 @@ __intname__ = "npbackup.gui.core.runner"
|
||||||
__author__ = "Orsiris de Jong"
|
__author__ = "Orsiris de Jong"
|
||||||
__copyright__ = "Copyright (C) 2022-2025 NetInvent"
|
__copyright__ = "Copyright (C) 2022-2025 NetInvent"
|
||||||
__license__ = "GPL-3.0-only"
|
__license__ = "GPL-3.0-only"
|
||||||
__build__ = "2025040901"
|
__build__ = "2025051101"
|
||||||
|
|
||||||
|
|
||||||
from typing import Optional, Callable, Union, List, Tuple
|
from typing import Optional, Callable, Union, List, Tuple
|
||||||
|
|
@ -64,6 +64,7 @@ required_permissions = {
|
||||||
"raw": ["full"],
|
"raw": ["full"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Specific operations that should never be run concurrently
|
||||||
locking_operations = [
|
locking_operations = [
|
||||||
"backup",
|
"backup",
|
||||||
"repair",
|
"repair",
|
||||||
|
|
@ -73,6 +74,17 @@ locking_operations = [
|
||||||
"unlock",
|
"unlock",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Specific operations that should not lock the repository (--no-lock)
|
||||||
|
non_locking_operations = [
|
||||||
|
"snapshots",
|
||||||
|
"stats",
|
||||||
|
"list",
|
||||||
|
"ls",
|
||||||
|
"find",
|
||||||
|
# check should not be locking, but we definitly don't want to play with fire here
|
||||||
|
# "check"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def metric_analyser(
|
def metric_analyser(
|
||||||
repo_config: dict,
|
repo_config: dict,
|
||||||
|
|
@ -329,7 +341,7 @@ class NPBackupRunner:
|
||||||
def no_lock(self) -> bool:
|
def no_lock(self) -> bool:
|
||||||
return self._no_lock
|
return self._no_lock
|
||||||
|
|
||||||
@no_lock.setter
|
@no_aquire_lock.setter
|
||||||
def no_lock(self, value: bool):
|
def no_lock(self, value: bool):
|
||||||
if not isinstance(value, bool):
|
if not isinstance(value, bool):
|
||||||
msg = f"Bogus no_lock parameter given: {value}"
|
msg = f"Bogus no_lock parameter given: {value}"
|
||||||
|
|
@ -701,6 +713,30 @@ class NPBackupRunner:
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
def no_aquire_lock(fn: Callable):
|
||||||
|
"""
|
||||||
|
Don't lock some operations
|
||||||
|
"""
|
||||||
|
|
||||||
|
@wraps(fn)
|
||||||
|
def wrapper(self, *args, **kwargs):
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
|
if fn.__name__ == "group_runner":
|
||||||
|
operation = kwargs.get("operation")
|
||||||
|
else:
|
||||||
|
# pylint: disable=E1101 (no-member)
|
||||||
|
operation = fn.__name__
|
||||||
|
|
||||||
|
no_lock = self._no_lock
|
||||||
|
if operation in non_locking_operations:
|
||||||
|
self._no_lock = True
|
||||||
|
# pylint: disable=E1102 (not-callable)
|
||||||
|
result = fn(self, *args, **kwargs)
|
||||||
|
self._no_lock = no_lock
|
||||||
|
return result
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
def catch_exceptions(fn: Callable):
|
def catch_exceptions(fn: Callable):
|
||||||
"""
|
"""
|
||||||
Catch any exception and log it so we don't loose exceptions in thread
|
Catch any exception and log it so we don't loose exceptions in thread
|
||||||
|
|
@ -1102,6 +1138,7 @@ class NPBackupRunner:
|
||||||
@metrics
|
@metrics
|
||||||
@exec_timer
|
@exec_timer
|
||||||
@check_concurrency
|
@check_concurrency
|
||||||
|
@no_aquire_lock
|
||||||
@has_permission
|
@has_permission
|
||||||
@is_ready
|
@is_ready
|
||||||
@apply_config_to_restic_runner
|
@apply_config_to_restic_runner
|
||||||
|
|
@ -1118,6 +1155,7 @@ class NPBackupRunner:
|
||||||
@metrics
|
@metrics
|
||||||
@exec_timer
|
@exec_timer
|
||||||
@check_concurrency
|
@check_concurrency
|
||||||
|
@no_aquire_lock
|
||||||
@has_permission
|
@has_permission
|
||||||
@is_ready
|
@is_ready
|
||||||
@apply_config_to_restic_runner
|
@apply_config_to_restic_runner
|
||||||
|
|
@ -1134,6 +1172,7 @@ class NPBackupRunner:
|
||||||
@metrics
|
@metrics
|
||||||
@exec_timer
|
@exec_timer
|
||||||
@check_concurrency
|
@check_concurrency
|
||||||
|
@no_aquire_lock
|
||||||
@has_permission
|
@has_permission
|
||||||
@is_ready
|
@is_ready
|
||||||
@apply_config_to_restic_runner
|
@apply_config_to_restic_runner
|
||||||
|
|
@ -1151,6 +1190,7 @@ class NPBackupRunner:
|
||||||
@metrics
|
@metrics
|
||||||
@exec_timer
|
@exec_timer
|
||||||
@check_concurrency
|
@check_concurrency
|
||||||
|
@no_aquire_lock
|
||||||
@has_permission
|
@has_permission
|
||||||
@is_ready
|
@is_ready
|
||||||
@apply_config_to_restic_runner
|
@apply_config_to_restic_runner
|
||||||
|
|
|
||||||
|
|
@ -939,12 +939,9 @@ class ResticRunner:
|
||||||
cmd = "snapshots"
|
cmd = "snapshots"
|
||||||
if id:
|
if id:
|
||||||
cmd += f" {id}"
|
cmd += f" {id}"
|
||||||
no_lock = self.no_lock
|
|
||||||
self.no_lock = True
|
|
||||||
result, output = self.executor(
|
result, output = self.executor(
|
||||||
cmd, timeout=FAST_COMMANDS_TIMEOUT, errors_allowed=errors_allowed
|
cmd, timeout=FAST_COMMANDS_TIMEOUT, errors_allowed=errors_allowed
|
||||||
)
|
)
|
||||||
self.no_lock = no_lock
|
|
||||||
if result:
|
if result:
|
||||||
msg = "Snapshots listed successfully"
|
msg = "Snapshots listed successfully"
|
||||||
elif errors_allowed:
|
elif errors_allowed:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue