Skip to content

Commit 9adcd27

Browse files
authored
Merge pull request #308 from sylwiaszunejko/keyerror
Remove endpoint to host_id mapping when removing host by host_id
2 parents f356716 + 12daf57 commit 9adcd27

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

cassandra/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4007,7 +4007,7 @@ def _refresh_node_list_and_token_map(self, connection, preloaded_results=None,
40074007
if old_host_id not in found_host_ids:
40084008
should_rebuild_token_map = True
40094009
log.debug("[control connection] Removing host not found in peers metadata: %r", old_host)
4010-
self._cluster.metadata.remove_host_by_host_id(old_host_id)
4010+
self._cluster.metadata.remove_host_by_host_id(old_host_id, old_host.endpoint)
40114011

40124012
log.debug("[control connection] Finished fetching ring info")
40134013
if partitioner and should_rebuild_token_map:

cassandra/metadata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,10 @@ def remove_host(self, host):
344344
self._host_id_by_endpoint.pop(host.endpoint, False)
345345
return bool(self._hosts.pop(host.host_id, False))
346346

347-
def remove_host_by_host_id(self, host_id):
347+
def remove_host_by_host_id(self, host_id, endpoint=None):
348348
with self._hosts_lock:
349+
if endpoint and self._host_id_by_endpoint[endpoint] == host_id:
350+
self._host_id_by_endpoint.pop(endpoint, False)
349351
return bool(self._hosts.pop(host_id, False))
350352

351353
def update_host(self, host, old_endpoint):

tests/unit/test_control_connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def update_host(self, host, old_endpoint):
8888
def all_hosts_items(self):
8989
return list(self.hosts.items())
9090

91-
def remove_host_by_host_id(self, host_id):
91+
def remove_host_by_host_id(self, host_id, endpoint=None):
92+
if endpoint and self._host_id_by_endpoint[endpoint] == host_id:
93+
self._host_id_by_endpoint.pop(endpoint, False)
9294
self.removed_hosts.append(self.hosts.pop(host_id, False))
9395
return bool(self.hosts.pop(host_id, False))
9496

0 commit comments

Comments
 (0)