Skip to content

Commit

Permalink
Merge pull request #838 from gbregman/devel
Browse files Browse the repository at this point in the history
Display an error in case operation was longer than OMAP lock duration
  • Loading branch information
gbregman authored Aug 29, 2024
2 parents 8b1fe4e + 83a7928 commit 036dbec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def __init__(self, omap_state, gateway_state, rpc_lock: threading.Lock) -> None:
self.omap_file_lock_retries = self.omap_state.config.getint_with_default("gateway", "omap_file_lock_retries", 30)
self.omap_file_lock_retry_sleep_interval = self.omap_state.config.getfloat_with_default("gateway",
"omap_file_lock_retry_sleep_interval", 1.0)
self.lock_start_time = 0.0
# This is used for testing purposes only. To allow us testing locking from two gateways at the same time
self.omap_file_disable_unlock = self.omap_state.config.getboolean_with_default("gateway", "omap_file_disable_unlock", False)
if self.omap_file_disable_unlock:
Expand All @@ -240,11 +241,18 @@ def __init__(self, omap_state, gateway_state, rpc_lock: threading.Lock) -> None:
def __enter__(self):
if self.omap_file_lock_duration > 0:
self.lock_omap()
self.lock_start_time = time.monotonic()
return self

def __exit__(self, typ, value, traceback):
if self.omap_file_lock_duration > 0:
duration = 0.0
if self.lock_start_time:
duration = time.monotonic() - self.lock_start_time
self.lock_start_time = 0.0
self.unlock_omap()
if duration > self.omap_file_lock_duration:
self.logger.error(f"Operation ran for {duration:.2f} seconds, but the OMAP lock expired after {self.omap_file_lock_duration} seconds")

def get_omap_lock_to_use(self, context):
if context:
Expand Down

0 comments on commit 036dbec

Please sign in to comment.