Skip to content

Commit

Permalink
Gil's 2024 04 28 patch
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum committed May 28, 2024
1 parent 9cd2088 commit 7f6e57d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def serve(self):

# Register service implementation with server
gateway_state = GatewayStateHandler(self.config, local_state, omap_state, self.gateway_rpc_caller)
omap_lock = OmapLock(omap_state, gateway_state, self.rpc_lock)
omap_lock = OmapLock(omap_state, gateway_state, self.rpc_lock, self.name)
self.gateway_rpc = GatewayService(self.config, gateway_state, self.rpc_lock, omap_lock, self.group_id, self.spdk_rpc_client, self.ceph_utils)
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
pb2_grpc.add_GatewayServicer_to_server(self.gateway_rpc, self.server)
Expand Down
15 changes: 14 additions & 1 deletion control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class OmapLock:
OMAP_FILE_LOCK_NAME = "omap_file_lock"
OMAP_FILE_LOCK_COOKIE = "omap_file_cookie"

def __init__(self, omap_state, gateway_state, rpc_lock: threading.Lock) -> None:
def __init__(self, omap_state, gateway_state, rpc_lock: threading.Lock, hostname: str) -> None:
self.logger = omap_state.logger
self.omap_state = omap_state
self.gateway_state = gateway_state
Expand All @@ -217,6 +217,7 @@ def __init__(self, omap_state, gateway_state, rpc_lock: threading.Lock) -> None:
if self.omap_file_disable_unlock:
self.logger.warning(f"Will not unlock OMAP file for testing purposes")
self.enter_args = {}
self.hostname = hostname

def __call__(self, **kwargs):
self.enter_args.clear()
Expand All @@ -234,12 +235,14 @@ def __enter__(self):
context = self.enter_args.get("context")
if context and self.omap_file_lock_duration > 0:
self.lock_omap()
self.omap_state.mark_last_locker(self.hostname)
return self

def __exit__(self, typ, value, traceback):
context = self.enter_args.get("context")
self.enter_args.clear()
if context and self.omap_file_lock_duration > 0:
self.omap_state.mark_last_locker("<n/a>")
self.unlock_omap()

#
Expand Down Expand Up @@ -430,6 +433,16 @@ def get_state(self) -> Dict[str, str]:
omap_dict.update(dict(omap_list))
return omap_dict

def mark_last_locker(self, locker: str):
try:
timestr = time.asctime()
write_string = f"{locker}: {timestr}"
with rados.WriteOpCtx() as write_op:
self.ioctx.set_omap(write_op, ("last_locker",), (write_string,))
self.ioctx.operate_write_op(write_op, self.omap_name)
except Exception:
self.logger.exception(f"Error marking last locker {locker}")

def _add_key(self, key: str, val: str):
"""Adds key and value to the OMAP."""
try:
Expand Down

0 comments on commit 7f6e57d

Please sign in to comment.