Skip to content

Commit 8b0a26c

Browse files
committed
dht: boot_strapper: check if keyspace still exists in bootstrap
While we're iterating over the fetched keyspace names, some of these keyspaces may get dropped. Handle that by checking if the keyspace still exists. Also, when retrieving the replication strategy from the keyspace, store the pointer (which is an `lw_shared_ptr`) to the strategy to keep it alive, in case the keyspace that was holding it gets dropped.
1 parent e499f45 commit 8b0a26c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dht/boot_strapper.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,16 @@ future<> boot_strapper::bootstrap(streaming::stream_reason reason, gms::gossiper
4848
streamer->add_source_filter(std::make_unique<range_streamer::failure_detector_source_filter>(nodes_to_filter));
4949
auto keyspaces = _db.local().get_non_system_keyspaces();
5050
for (auto& keyspace_name : keyspaces) {
51+
if (!_db.local().has_keyspace(keyspace_name)) {
52+
// The keyspace was dropped while we were looping.
53+
continue;
54+
}
55+
5156
auto& ks = _db.local().find_keyspace(keyspace_name);
52-
auto& strategy = ks.get_replication_strategy();
53-
dht::token_range_vector ranges = co_await strategy.get_pending_address_ranges(_token_metadata_ptr, _tokens, _address);
57+
auto strategy = ks.get_replication_strategy_ptr();
58+
// We took a strategy ptr to keep it alive during the `co_await`.
59+
// The keyspace may be dropped in the meantime.
60+
dht::token_range_vector ranges = co_await strategy->get_pending_address_ranges(_token_metadata_ptr, _tokens, _address);
5461
blogger.debug("Will stream keyspace={}, ranges={}", keyspace_name, ranges);
5562
co_await streamer->add_ranges(keyspace_name, ranges, gossiper, reason == streaming::stream_reason::replace);
5663
}

0 commit comments

Comments
 (0)