public Multimap<InetAddress, Range<Token>> getAddressRanges(TokenMetadata metadata) { Multimap<InetAddress, Range<Token>> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(ep, range); } } return map; }
public Multimap<Range<Token>, InetAddress> getRangeAddresses(TokenMetadata metadata) { Multimap<Range<Token>, InetAddress> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(range, ep); } } return map; }
public Multimap<InetAddress, Range<Token>> getAddressRanges(TokenMetadata metadata) { Multimap<InetAddress, Range<Token>> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(ep, range); } } return map; }
public Multimap<Range<Token>, InetAddress> getRangeAddresses(TokenMetadata metadata) { Multimap<Range<Token>, InetAddress> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(range, ep); } } return map; }
static void addOwnership(final TokenMetadata tokenMetadata, final AbstractReplicationStrategy rs, Token current, Token next, Map<InetAddress, Double> ownership) { double size = current.size(next); Token representative = current.getPartitioner().midpoint(current, next); for (InetAddress n : rs.calculateNaturalEndpoints(representative, tokenMetadata)) { Double v = ownership.get(n); ownership.put(n, v != null ? v + size : size); } }
static void addOwnership(final TokenMetadata tokenMetadata, final AbstractReplicationStrategy rs, Token current, Token next, Map<InetAddress, Double> ownership) { double size = current.size(next); Token representative = current.getPartitioner().midpoint(current, next); for (InetAddress n : rs.calculateNaturalEndpoints(representative, tokenMetadata)) { Double v = ownership.get(n); ownership.put(n, v != null ? v + size : size); } }
static void addOwnership(final TokenMetadata tokenMetadata, final AbstractReplicationStrategy rs, Token current, Token next, Map<InetAddress, Double> ownership) { double size = current.size(next); Token representative = current.getPartitioner().midpoint(current, next); for (InetAddress n : rs.calculateNaturalEndpoints(representative, tokenMetadata)) { Double v = ownership.get(n); ownership.put(n, v != null ? v + size : size); } }
/** * Get the "primary ranges" for the specified keyspace and endpoint. * "Primary ranges" are the ranges that the node is responsible for storing replica primarily. * The node that stores replica primarily is defined as the first node returned * by {@link AbstractReplicationStrategy#calculateNaturalEndpoints}. * * @param keyspace Keyspace name to check primary ranges * @param ep endpoint we are interested in. * @return primary ranges for the specified endpoint. */ public Collection<Range<Token>> getPrimaryRangesForEndpoint(String keyspace, InetAddress ep) { AbstractReplicationStrategy strategy = Keyspace.open(keyspace).getReplicationStrategy(); Collection<Range<Token>> primaryRanges = new HashSet<>(); TokenMetadata metadata = tokenMetadata.cloneOnlyTokenMap(); for (Token token : metadata.sortedTokens()) { List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata); if (endpoints.size() > 0 && endpoints.get(0).equals(ep)) primaryRanges.add(new Range<>(metadata.getPredecessor(token), token)); } return primaryRanges; }
/** * Get the "primary ranges" for the specified keyspace and endpoint. * "Primary ranges" are the ranges that the node is responsible for storing replica primarily. * The node that stores replica primarily is defined as the first node returned * by {@link AbstractReplicationStrategy#calculateNaturalEndpoints}. * * @param keyspace Keyspace name to check primary ranges * @param ep endpoint we are interested in. * @return primary ranges for the specified endpoint. */ public Collection<Range<Token>> getPrimaryRangesForEndpoint(String keyspace, InetAddress ep) { AbstractReplicationStrategy strategy = Keyspace.open(keyspace).getReplicationStrategy(); Collection<Range<Token>> primaryRanges = new HashSet<>(); TokenMetadata metadata = tokenMetadata.cloneOnlyTokenMap(); for (Token token : metadata.sortedTokens()) { List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata); if (endpoints.size() > 0 && endpoints.get(0).equals(ep)) primaryRanges.add(new Range<>(metadata.getPredecessor(token), token)); } return primaryRanges; }
/** * Get the "primary ranges" for the specified keyspace and endpoint. * "Primary ranges" are the ranges that the node is responsible for storing replica primarily. * The node that stores replica primarily is defined as the first node returned * by {@link AbstractReplicationStrategy#calculateNaturalEndpoints}. * * @param keyspace Keyspace name to check primary ranges * @param ep endpoint we are interested in. * @return primary ranges for the specified endpoint. */ public Collection<Range<Token>> getPrimaryRangesForEndpoint(String keyspace, InetAddress ep) { AbstractReplicationStrategy strategy = Keyspace.open(keyspace).getReplicationStrategy(); Collection<Range<Token>> primaryRanges = new HashSet<>(); TokenMetadata metadata = tokenMetadata.cloneOnlyTokenMap(); for (Token token : metadata.sortedTokens()) { List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata); if (endpoints.size() > 0 && endpoints.get(0).equals(ep)) primaryRanges.add(new Range<>(metadata.getPredecessor(token), token)); } return primaryRanges; }
/** * Get the "primary ranges" for the specified keyspace and endpoint. * "Primary ranges" are the ranges that the node is responsible for storing replica primarily. * The node that stores replica primarily is defined as the first node returned * by {@link AbstractReplicationStrategy#calculateNaturalEndpoints}. * * @param keyspace Keyspace name to check primary ranges * @param ep endpoint we are interested in. * @return primary ranges for the specified endpoint. */ public Collection<Range<Token>> getPrimaryRangesForEndpoint(String keyspace, InetAddress ep) { AbstractReplicationStrategy strategy = Keyspace.open(keyspace).getReplicationStrategy(); Collection<Range<Token>> primaryRanges = new HashSet<>(); TokenMetadata metadata = tokenMetadata.cloneOnlyTokenMap(); for (Token token : metadata.sortedTokens()) { List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata); if (endpoints.size() > 0 && endpoints.get(0).equals(ep)) primaryRanges.add(new Range<>(metadata.getPredecessor(token), token)); } return primaryRanges; }
public Multimap<InetAddress, Range<Token>> getAddressRanges(TokenMetadata metadata) { Multimap<InetAddress, Range<Token>> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(ep, range); } } return map; }
public Multimap<InetAddress, Range<Token>> getAddressRanges(TokenMetadata metadata) { Multimap<InetAddress, Range<Token>> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(ep, range); } } return map; }
public Multimap<Range<Token>, InetAddress> getRangeAddresses(TokenMetadata metadata) { Multimap<Range<Token>, InetAddress> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(range, ep); } } return map; }
public Multimap<Range<Token>, InetAddress> getRangeAddresses(TokenMetadata metadata) { Multimap<Range<Token>, InetAddress> map = HashMultimap.create(); for (Token token : metadata.sortedTokens()) { Range<Token> range = metadata.getPrimaryRangeFor(token); for (InetAddress ep : calculateNaturalEndpoints(token, metadata)) { map.put(range, ep); } } return map; }
/** * get the (possibly cached) endpoints that should store the given Token. * Note that while the endpoints are conceptually a Set (no duplicates will be included), * we return a List to avoid an extra allocation when sorting by proximity later * @param searchPosition the position the natural endpoints are requested for * @return a copy of the natural endpoints for the given token */ public ArrayList<InetAddress> getNaturalEndpoints(RingPosition searchPosition) { Token searchToken = searchPosition.getToken(); Token keyToken = TokenMetadata.firstToken(tokenMetadata.sortedTokens(), searchToken); ArrayList<InetAddress> endpoints = getCachedEndpoints(keyToken); if (endpoints == null) { TokenMetadata tm = tokenMetadata.cachedOnlyTokenMap(); // if our cache got invalidated, it's possible there is a new token to account for too keyToken = TokenMetadata.firstToken(tm.sortedTokens(), searchToken); endpoints = new ArrayList<InetAddress>(calculateNaturalEndpoints(searchToken, tm)); cachedEndpoints.put(keyToken, endpoints); } return new ArrayList<InetAddress>(endpoints); }
/** * get the (possibly cached) endpoints that should store the given Token. * Note that while the endpoints are conceptually a Set (no duplicates will be included), * we return a List to avoid an extra allocation when sorting by proximity later * @param searchPosition the position the natural endpoints are requested for * @return a copy of the natural endpoints for the given token */ public ArrayList<InetAddress> getNaturalEndpoints(RingPosition searchPosition) { Token searchToken = searchPosition.getToken(); Token keyToken = TokenMetadata.firstToken(tokenMetadata.sortedTokens(), searchToken); ArrayList<InetAddress> endpoints = getCachedEndpoints(keyToken); if (endpoints == null) { TokenMetadata tm = tokenMetadata.cachedOnlyTokenMap(); // if our cache got invalidated, it's possible there is a new token to account for too keyToken = TokenMetadata.firstToken(tm.sortedTokens(), searchToken); endpoints = new ArrayList<InetAddress>(calculateNaturalEndpoints(searchToken, tm)); cachedEndpoints.put(keyToken, endpoints); } return new ArrayList<InetAddress>(endpoints); }
/** * get the (possibly cached) endpoints that should store the given Token. * Note that while the endpoints are conceptually a Set (no duplicates will be included), * we return a List to avoid an extra allocation when sorting by proximity later * @param searchPosition the position the natural endpoints are requested for * @return a copy of the natural endpoints for the given token */ public ArrayList<InetAddress> getNaturalEndpoints(RingPosition searchPosition) { Token searchToken = searchPosition.getToken(); Token keyToken = TokenMetadata.firstToken(tokenMetadata.sortedTokens(), searchToken); ArrayList<InetAddress> endpoints = getCachedEndpoints(keyToken); if (endpoints == null) { TokenMetadata tm = tokenMetadata.cachedOnlyTokenMap(); // if our cache got invalidated, it's possible there is a new token to account for too keyToken = TokenMetadata.firstToken(tm.sortedTokens(), searchToken); endpoints = new ArrayList<InetAddress>(calculateNaturalEndpoints(searchToken, tm)); cachedEndpoints.put(keyToken, endpoints); } return new ArrayList<InetAddress>(endpoints); }
/** * get the (possibly cached) endpoints that should store the given Token. * Note that while the endpoints are conceptually a Set (no duplicates will be included), * we return a List to avoid an extra allocation when sorting by proximity later * @param searchPosition the position the natural endpoints are requested for * @return a copy of the natural endpoints for the given token */ public ArrayList<InetAddress> getNaturalEndpoints(RingPosition searchPosition) { Token searchToken = searchPosition.getToken(); Token keyToken = TokenMetadata.firstToken(tokenMetadata.sortedTokens(), searchToken); ArrayList<InetAddress> endpoints = getCachedEndpoints(keyToken); if (endpoints == null) { TokenMetadata tm = tokenMetadata.cachedOnlyTokenMap(); // if our cache got invalidated, it's possible there is a new token to account for too keyToken = TokenMetadata.firstToken(tm.sortedTokens(), searchToken); endpoints = new ArrayList<InetAddress>(calculateNaturalEndpoints(searchToken, tm)); cachedEndpoints.put(keyToken, endpoints); } return new ArrayList<InetAddress>(endpoints); }
for (Token token : metadata.sortedTokens()) List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata); for (InetAddress endpoint : endpoints)