/** * Merges the list of tokens for each cluster machine to a single list of token ranges. * * @param tokens the map of tokens for each cluster machine. * @param session the connection to the cluster. * @param p the partitioner used in the cluster. * @return the merged lists of tokens transformed to DeepTokenRange(s). The returned collection is shuffled. */ static List<DeepTokenRange> mergeTokenRanges(Map<String, Iterable<Comparable>> tokens, final Session session, final IPartitioner p) { final Iterable<Comparable> allRanges = Ordering.natural().sortedCopy(concat(tokens.values())); final Comparable maxValue = Ordering.natural().max(allRanges); final Comparable minValue = (Comparable) p.minValue(maxValue.getClass()).getToken().token; Function<Comparable, Set<DeepTokenRange>> map = new MergeTokenRangesFunction(maxValue, minValue, session, p, allRanges); Iterable<DeepTokenRange> concatenated = concat(transform(allRanges, map)); Set<DeepTokenRange> dedup = Sets.newHashSet(concatenated); return Ordering.natural().sortedCopy(dedup); }
Iterator<Token> ringIter = TokenMetadata.ringIterator(tokenMetadata.sortedTokens(), queryRange.left.getToken(), true); AbstractBounds<T> remainder = queryRange; while (ringIter.hasNext())
Iterator<Token> ringIter = TokenMetadata.ringIterator(tokenMetadata.sortedTokens(), queryRange.left.getToken(), true); AbstractBounds<T> remainder = queryRange; while (ringIter.hasNext())
Iterator<Token> ringIter = TokenMetadata.ringIterator(tokenMetadata.sortedTokens(), queryRange.left.getToken(), true); AbstractBounds<T> remainder = queryRange; while (ringIter.hasNext())
Iterator<Token> ringIter = TokenMetadata.ringIterator(tokenMetadata.sortedTokens(), queryRange.left.getToken(), true); AbstractBounds<T> remainder = queryRange; while (ringIter.hasNext())
/** * 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); }