token_metadata: Add get_predecessor
It is used to get the previous token of this token in the ring.
This commit is contained in:
@@ -302,6 +302,17 @@ void token_metadata::remove_from_moving(inet_address endpoint) {
|
||||
invalidate_cached_rings();
|
||||
}
|
||||
|
||||
token token_metadata::get_predecessor(token t) {
|
||||
auto& tokens = sorted_tokens();
|
||||
auto it = std::lower_bound(tokens.begin(), tokens.end(), t);
|
||||
assert(it != tokens.end() && *it == t);
|
||||
if (it == tokens.begin()) {
|
||||
// If the token is the first element, its preprocessor is the last element
|
||||
return tokens.back();
|
||||
} else {
|
||||
return *(--it);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////// class topology /////////////////////////////////////////////
|
||||
inline void topology::clear() {
|
||||
|
||||
@@ -810,15 +810,12 @@ public:
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
public:
|
||||
|
||||
public Token getPredecessor(Token token)
|
||||
{
|
||||
List tokens = sortedTokens();
|
||||
int index = Collections.binarySearch(tokens, token);
|
||||
assert index >= 0 : token + " not found in " + StringUtils.join(tokenToEndpointMap.keySet(), ", ");
|
||||
return (Token) (index == 0 ? tokens.get(tokens.size() - 1) : tokens.get(index - 1));
|
||||
}
|
||||
token get_predecessor(token t);
|
||||
|
||||
#if 0
|
||||
public Token getSuccessor(Token token)
|
||||
{
|
||||
List tokens = sortedTokens();
|
||||
|
||||
Reference in New Issue
Block a user