Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove proxy from CPProxyManager._lock_proxies upon lock destruction #644

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hazelcast/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,15 @@ def _create_fenced_lock(self, group_id, proxy_name, object_name):
return proxy

proxy = FencedLock(self._context, group_id, LOCK_SERVICE, proxy_name, object_name)
proxy._proxy_removal = lambda: self._remove_lock_proxy(proxy_name)
self._lock_proxies[proxy_name] = proxy
return proxy

def _remove_lock_proxy(self, proxy_name):
with self._mux:
if proxy_name in self._lock_proxies:
self._lock_proxies.pop(proxy_name)

def _create_semaphore(self, group_id, proxy_name, object_name):
codec = semaphore_get_semaphore_type_codec
request = codec.encode_request(proxy_name)
Expand Down
3 changes: 3 additions & 0 deletions hazelcast/proxy/cp/fenced_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def cb(_):
def __init__(self, context, group_id, service_name, proxy_name, object_name):
super(FencedLock, self).__init__(context, group_id, service_name, proxy_name, object_name)
self._lock_session_ids = dict() # thread-id to session id that has acquired the lock
self._proxy_removal = None

def lock(self) -> Future[int]:
"""Acquires the lock and returns the fencing token assigned to the
Expand Down Expand Up @@ -308,6 +309,8 @@ def check_response(f):

def destroy(self) -> Future[None]:
self._lock_session_ids.clear()
if self._proxy_removal is not None:
self._proxy_removal()
return super(FencedLock, self).destroy()

def blocking(self) -> "BlockingFencedLock":
Expand Down