Skip to content

Commit

Permalink
token_metadata: use static ring version
Browse files Browse the repository at this point in the history
For generating unique _ring_version.

Currently when we clone a mutable token_metadata_ptr
it remains with the same _ring_version
and the ring version is updated only when the topology changes.

To be able to distinguish these traqnsient copies
from the ones that got applied, be stricter about
the ring version and change it to a unique number
using a static counter.

Next patch will update the ring version
(and consequently invalidate the cached_endpoints
on the replication strategy) every time the token_metadata
changes, not only when the topology changes.

Note that the _cached_endpoints will go away
once the transition to effective_replication_map
is finished, so this will not degrade performance.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
  • Loading branch information
bhalevy committed Oct 13, 2021
1 parent 685f5e7 commit 43160ab
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions locator/token_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class token_metadata_impl final {
topology _topology;

long _ring_version = 0;
static thread_local long _static_ring_version;

// Note: if any member is added to this class
// clone_async() must be updated to copy that member.
Expand Down Expand Up @@ -317,13 +318,14 @@ class token_metadata_impl final {
}

void invalidate_cached_rings() {
++_ring_version;
//cachedTokenMap.set(null);
_ring_version = ++_static_ring_version;
}

friend class token_metadata;
};

thread_local long token_metadata_impl::_static_ring_version;

token_metadata::tokens_iterator::tokens_iterator(const token& start, const token_metadata_impl* token_metadata)
: _token_metadata(token_metadata) {
_cur_it = _token_metadata->sorted_tokens().begin() + _token_metadata->first_token_index(start);
Expand Down

0 comments on commit 43160ab

Please sign in to comment.