Skip to content

Commit

Permalink
Merge pull request #308 from sylwiaszunejko/keyerror
Browse files Browse the repository at this point in the history
Remove endpoint to host_id mapping when removing host by host_id
  • Loading branch information
Lorak-mmk authored Mar 18, 2024
2 parents f356716 + 12daf57 commit 9adcd27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cassandra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4007,7 +4007,7 @@ def _refresh_node_list_and_token_map(self, connection, preloaded_results=None,
if old_host_id not in found_host_ids:
should_rebuild_token_map = True
log.debug("[control connection] Removing host not found in peers metadata: %r", old_host)
self._cluster.metadata.remove_host_by_host_id(old_host_id)
self._cluster.metadata.remove_host_by_host_id(old_host_id, old_host.endpoint)

log.debug("[control connection] Finished fetching ring info")
if partitioner and should_rebuild_token_map:
Expand Down
4 changes: 3 additions & 1 deletion cassandra/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ def remove_host(self, host):
self._host_id_by_endpoint.pop(host.endpoint, False)
return bool(self._hosts.pop(host.host_id, False))

def remove_host_by_host_id(self, host_id):
def remove_host_by_host_id(self, host_id, endpoint=None):
with self._hosts_lock:
if endpoint and self._host_id_by_endpoint[endpoint] == host_id:
self._host_id_by_endpoint.pop(endpoint, False)
return bool(self._hosts.pop(host_id, False))

def update_host(self, host, old_endpoint):
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_control_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def update_host(self, host, old_endpoint):
def all_hosts_items(self):
return list(self.hosts.items())

def remove_host_by_host_id(self, host_id):
def remove_host_by_host_id(self, host_id, endpoint=None):
if endpoint and self._host_id_by_endpoint[endpoint] == host_id:
self._host_id_by_endpoint.pop(endpoint, False)
self.removed_hosts.append(self.hosts.pop(host_id, False))
return bool(self.hosts.pop(host_id, False))

Expand Down

0 comments on commit 9adcd27

Please sign in to comment.