From d1eaccd234d937b677bbdf2733ebbe81cbc404ef Mon Sep 17 00:00:00 2001 From: Asias He Date: Wed, 21 Oct 2015 09:18:00 +0800 Subject: [PATCH] storage_service: Implement leave_ring Needed by unbootstrap. --- service/storage_service.cc | 14 ++++++++++++++ service/storage_service.hh | 15 +-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/service/storage_service.cc b/service/storage_service.cc index 0ab51f8151..e40fc92eec 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -1912,4 +1912,18 @@ void storage_service::send_replication_notification(inet_address remote) { #endif } +// Runs inside seastar::async context +void storage_service::leave_ring() { + db::system_keyspace::set_bootstrap_state(db::system_keyspace::bootstrap_state::NEEDS_BOOTSTRAP).get(); + _token_metadata.remove_endpoint(get_broadcast_address()); + get_local_pending_range_calculator_service().update().get(); + + auto& gossiper = gms::get_local_gossiper(); + auto expire_time = gossiper.compute_expire_time().time_since_epoch().count(); + gossiper.add_local_application_state(gms::application_state::STATUS, value_factory.left(get_local_tokens(), expire_time)); + auto delay = std::max(std::chrono::milliseconds(RING_DELAY), gms::gossiper::INTERVAL); + logger.info("Announcing that I have left the ring for {}ms", delay.count()); + sleep(delay).get(); +} + } // namespace service diff --git a/service/storage_service.hh b/service/storage_service.hh index 7af59f5a9d..9176f102fd 100644 --- a/service/storage_service.hh +++ b/service/storage_service.hh @@ -1887,23 +1887,10 @@ public: future<> decommission(); -#if 0 - private void leaveRing() - { - SystemKeyspace.setBootstrapState(SystemKeyspace.BootstrapState.NEEDS_BOOTSTRAP); - _token_metadata.removeEndpoint(FBUtilities.getBroadcastAddress()); - PendingRangeCalculatorService.instance.update(); - - Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS, valueFactory.left(getLocalTokens(),Gossiper.computeExpireTime())); - int delay = Math.max(RING_DELAY, Gossiper.intervalInMillis * 2); - logger.info("Announcing that I have left the ring for {}ms", delay); - Uninterruptibles.sleepUninterruptibly(delay, TimeUnit.MILLISECONDS); - } -#endif private: + void leave_ring(); future<> unbootstrap(); #if 0 - private Future streamHints() { // StreamPlan will not fail if there are zero files to transfer, so flush anyway (need to get any in-memory hints, as well)