From d26c7e671d52b34cc85e62a4e389bc5fcb4fe2d1 Mon Sep 17 00:00:00 2001 From: Asias He Date: Wed, 9 Dec 2015 11:03:30 +0800 Subject: [PATCH] storage_service: Enable commented out code in handle_state_normal Add current_owner to endpoints_to_remove if endpoint and current_owner have the same token and endpoint is newer than current_owner. --- service/storage_service.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/service/storage_service.cc b/service/storage_service.cc index 0e1335b3af..6df9223f6a 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -532,16 +532,20 @@ void storage_service::handle_state_normal(inet_address endpoint) { logger.debug("handle_state_normal: endpoint={} > current_owner={}, token {}", endpoint, *current_owner, t); tokens_to_update_in_metadata.insert(t); tokens_to_update_in_system_keyspace.insert(t); -#if 0 - // currentOwner is no longer current, endpoint is. Keep track of these moves, because when // a host no longer has any tokens, we'll want to remove it. - Multimap epToTokenCopy = getTokenMetadata().getEndpointToTokenMapForReading(); - epToTokenCopy.get(currentOwner).remove(token); - if (epToTokenCopy.get(currentOwner).size() < 1) - endpointsToRemove.add(currentOwner); - -#endif + std::multimap ep_to_token_copy = get_token_metadata().get_endpoint_to_token_map_for_reading(); + auto rg = ep_to_token_copy.equal_range(*current_owner); + for (auto it = rg.first; it != rg.second; it++) { + if (it->second == t) { + logger.info("handle_state_normal: remove endpoint={} token={}", *current_owner, t); + ep_to_token_copy.erase(it); + } + } + if (ep_to_token_copy.count(*current_owner) < 1) { + logger.info("handle_state_normal: endpoints_to_remove endpoint={}", *current_owner); + endpoints_to_remove.insert(*current_owner); + } logger.info("handle_state_normal: Nodes {} and {} have the same token {}. {} is the new owner", endpoint, *current_owner, t, endpoint); } else { logger.info("handle_state_normal: Nodes {} and {} have the same token {}. Ignoring {}", endpoint, *current_owner, t, endpoint);