token_metadata: Add get_endpoint_to_token_map_for_reading

This commit is contained in:
Asias He
2015-12-09 11:02:39 +08:00
parent 1cc7887ffb
commit 3793bb7be1
2 changed files with 11 additions and 17 deletions

View File

@@ -524,6 +524,14 @@ std::map<token, inet_address> token_metadata::get_normal_and_bootstrapping_token
return ret;
}
std::multimap<inet_address, token> token_metadata::get_endpoint_to_token_map_for_reading() {
std::multimap<inet_address, token> cloned;
for (const auto& x : _token_to_endpoint_map) {
cloned.emplace(x.second, x.first);
}
return cloned;
}
/////////////////// class topology /////////////////////////////////////////////
inline void topology::clear() {

View File

@@ -877,25 +877,11 @@ public:
{
return ImmutableList.copyOf(Iterables.concat(naturalEndpoints, pendingEndpointsFor(token, keyspaceName)));
}
/** @return an endpoint to token multimap representation of tokenToEndpointMap (a copy) */
public Multimap<InetAddress, Token> getEndpointToTokenMapForReading()
{
lock.readLock().lock();
try
{
Multimap<InetAddress, Token> cloned = HashMultimap.create();
for (Map.Entry<Token, InetAddress> entry : tokenToEndpointMap.entrySet())
cloned.put(entry.getValue(), entry.getKey());
return cloned;
}
finally
{
lock.readLock().unlock();
}
}
#endif
public:
/** @return an endpoint to token multimap representation of tokenToEndpointMap (a copy) */
std::multimap<inet_address, token> get_endpoint_to_token_map_for_reading();
/**
* @return a (stable copy, won't be modified) Token to Endpoint map for all the normal and bootstrapping nodes
* in the cluster.