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); } }
private CandidateInfo<Unit> createCandidates(TokenInfo<Unit> tokens, UnitInfo<Unit> newUnitInfo, double initialTokenOwnership) { TokenInfo<Unit> curr = tokens; CandidateInfo<Unit> first = null; CandidateInfo<Unit> prev = null; do { CandidateInfo<Unit> candidate = new CandidateInfo<Unit>(partitioner.midpoint(curr.prev.token, curr.token), curr, newUnitInfo); first = candidate.insertAfter(first, prev); candidate.replicatedOwnership = initialTokenOwnership; populateCandidate(candidate); prev = candidate; curr = curr.next; } while (curr != tokens); prev.next = first; return first; }
private CandidateInfo<Unit> createCandidates(TokenInfo<Unit> tokens, UnitInfo<Unit> newUnitInfo, double initialTokenOwnership) { TokenInfo<Unit> curr = tokens; CandidateInfo<Unit> first = null; CandidateInfo<Unit> prev = null; do { CandidateInfo<Unit> candidate = new CandidateInfo<Unit>(partitioner.midpoint(curr.prev.token, curr.token), curr, newUnitInfo); first = candidate.insertAfter(first, prev); candidate.replicatedOwnership = initialTokenOwnership; populateCandidate(candidate); prev = candidate; curr = curr.next; } while (curr != tokens); prev.next = first; return first; }
private CandidateInfo<Unit> createCandidates(TokenInfo<Unit> tokens, UnitInfo<Unit> newUnitInfo, double initialTokenOwnership) { TokenInfo<Unit> curr = tokens; CandidateInfo<Unit> first = null; CandidateInfo<Unit> prev = null; do { CandidateInfo<Unit> candidate = new CandidateInfo<Unit>(partitioner.midpoint(curr.prev.token, curr.token), curr, newUnitInfo); first = candidate.insertAfter(first, prev); candidate.replicatedOwnership = initialTokenOwnership; populateCandidate(candidate); prev = candidate; curr = curr.next; } while (curr != tokens); prev.next = first; return first; }
private Hashable initHelper(Token left, Token right, byte depth, byte max) { if (depth == max) // we've reached the leaves return new Leaf(); Token midpoint = partitioner.midpoint(left, right); if (midpoint.equals(left) || midpoint.equals(right)) return new Leaf(); Hashable lchild = initHelper(left, midpoint, inc(depth), max); Hashable rchild = initHelper(midpoint, right, inc(depth), max); return new Inner(midpoint, lchild, rchild); }
private Hashable initHelper(Token left, Token right, byte depth, byte max) { if (depth == max) // we've reached the leaves return new Leaf(); Token midpoint = partitioner.midpoint(left, right); if (midpoint.equals(left) || midpoint.equals(right)) return new Leaf(); Hashable lchild = initHelper(left, midpoint, inc(depth), max); Hashable rchild = initHelper(midpoint, right, inc(depth), max); return new Inner(midpoint, lchild, rchild); }
private Hashable initHelper(Token left, Token right, byte depth, byte max) { if (depth == max) // we've reached the leaves return new Leaf(); Token midpoint = partitioner.midpoint(left, right); if (midpoint.equals(left) || midpoint.equals(right)) return new Leaf(); Hashable lchild = initHelper(left, midpoint, inc(depth), max); Hashable rchild = initHelper(midpoint, right, inc(depth), max); return new Inner(midpoint, lchild, rchild); }
private Hashable initHelper(Token left, Token right, byte depth, byte max) { if (depth == max) // we've reached the leaves return new Leaf(); Token midpoint = partitioner.midpoint(left, right); if (midpoint.equals(left) || midpoint.equals(right)) return new Leaf(); Hashable lchild = initHelper(left, midpoint, inc(depth), max); Hashable rchild = initHelper(midpoint, right, inc(depth), max); return new Inner(midpoint, lchild, rchild); }
private Hashable initHelper(Token left, Token right, byte depth, byte max) { if (depth == max) // we've reached the leaves return new Leaf(); Token midpoint = partitioner.midpoint(left, right); if (midpoint.equals(left) || midpoint.equals(right)) return new Leaf(); Hashable lchild = initHelper(left, midpoint, inc(depth), max); Hashable rchild = initHelper(midpoint, right, inc(depth), max); return new Inner(midpoint, lchild, rchild); }
return CONSISTENT; Token midpoint = ltree.partitioner().midpoint(active.left, active.right);
private Hashable splitHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t) throws StopRecursion.TooDeep { if (depth >= hashdepth) throw new StopRecursion.TooDeep(); if (hashable instanceof Leaf) { Token midpoint = partitioner.midpoint(pleft, pright); // We should not create a non-sensical range where start and end are the same token (this is non-sensical because range are // start exclusive). Note that we shouldn't hit that unless the full range is very small or we are fairly deep if (midpoint.equals(pleft) || midpoint.equals(pright)) throw new StopRecursion.TooDeep(); // split size++; return new Inner(midpoint, new Leaf(), new Leaf()); } // else: node. // recurse on the matching child Inner node = (Inner)hashable; if (Range.contains(pleft, node.token, t)) // left child contains token node.lchild(splitHelper(node.lchild, pleft, node.token, inc(depth), t)); else // else: right child contains token node.rchild(splitHelper(node.rchild, node.token, pright, inc(depth), t)); return node; }
private Hashable splitHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t) throws StopRecursion.TooDeep { if (depth >= hashdepth) throw new StopRecursion.TooDeep(); if (hashable instanceof Leaf) { Token midpoint = partitioner.midpoint(pleft, pright); // We should not create a non-sensical range where start and end are the same token (this is non-sensical because range are // start exclusive). Note that we shouldn't hit that unless the full range is very small or we are fairly deep if (midpoint.equals(pleft) || midpoint.equals(pright)) throw new StopRecursion.TooDeep(); // split size++; return new Inner(midpoint, new Leaf(), new Leaf()); } // else: node. // recurse on the matching child Inner node = (Inner)hashable; if (Range.contains(pleft, node.token, t)) // left child contains token node.lchild(splitHelper(node.lchild, pleft, node.token, inc(depth), t)); else // else: right child contains token node.rchild(splitHelper(node.rchild, node.token, pright, inc(depth), t)); return node; }
private Hashable splitHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t) throws StopRecursion.TooDeep { if (depth >= hashdepth) throw new StopRecursion.TooDeep(); if (hashable instanceof Leaf) { Token midpoint = partitioner.midpoint(pleft, pright); // We should not create a non-sensical range where start and end are the same token (this is non-sensical because range are // start exclusive). Note that we shouldn't hit that unless the full range is very small or we are fairly deep if (midpoint.equals(pleft) || midpoint.equals(pright)) throw new StopRecursion.TooDeep(); // split size++; return new Inner(midpoint, new Leaf(), new Leaf()); } // else: node. // recurse on the matching child Inner node = (Inner)hashable; if (Range.contains(pleft, node.token, t)) // left child contains token node.lchild(splitHelper(node.lchild, pleft, node.token, inc(depth), t)); else // else: right child contains token node.rchild(splitHelper(node.rchild, node.token, pright, inc(depth), t)); return node; }
private Hashable splitHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t) throws StopRecursion.TooDeep { if (depth >= hashdepth) throw new StopRecursion.TooDeep(); if (hashable instanceof Leaf) { Token midpoint = partitioner.midpoint(pleft, pright); // We should not create a non-sensical range where start and end are the same token (this is non-sensical because range are // start exclusive). Note that we shouldn't hit that unless the full range is very small or we are fairly deep if (midpoint.equals(pleft) || midpoint.equals(pright)) throw new StopRecursion.TooDeep(); // split size++; return new Inner(midpoint, new Leaf(), new Leaf()); } // else: node. // recurse on the matching child Inner node = (Inner)hashable; if (Range.contains(pleft, node.token, t)) // left child contains token node.lchild(splitHelper(node.lchild, pleft, node.token, inc(depth), t)); else // else: right child contains token node.rchild(splitHelper(node.rchild, node.token, pright, inc(depth), t)); return node; }
private Hashable splitHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t) throws StopRecursion.TooDeep { if (depth >= hashdepth) throw new StopRecursion.TooDeep(); if (hashable instanceof Leaf) { Token midpoint = partitioner.midpoint(pleft, pright); // We should not create a non-sensical range where start and end are the same token (this is non-sensical because range are // start exclusive). Note that we shouldn't hit that unless the full range is very small or we are fairly deep if (midpoint.equals(pleft) || midpoint.equals(pright)) throw new StopRecursion.TooDeep(); // split size++; return new Inner(midpoint, new Leaf(), new Leaf()); } // else: node. // recurse on the matching child Inner node = (Inner)hashable; if (Range.contains(pleft, node.token, t)) // left child contains token node.lchild(splitHelper(node.lchild, pleft, node.token, inc(depth), t)); else // else: right child contains token node.rchild(splitHelper(node.rchild, node.token, pright, inc(depth), t)); return node; }
/** * Recursive function that splits a given token range to a given number of token ranges. * * @param range the token range to be splitted. * @param partitioner the cassandra partitioner. * @param bisectFactor the actual number of pieces the original token range will be splitted to. * @param accumulator a token range accumulator (ne */ private static void bisectTokeRange( DeepTokenRange range, final IPartitioner partitioner, final int bisectFactor, final List<DeepTokenRange> accumulator) { final AbstractType tkValidator = partitioner.getTokenValidator(); Token leftToken = partitioner.getTokenFactory().fromByteArray(tkValidator.decompose(range.getStartToken())); Token rightToken = partitioner.getTokenFactory().fromByteArray(tkValidator.decompose(range.getEndToken())); Token midToken = partitioner.midpoint(leftToken, rightToken); Comparable midpoint = (Comparable) tkValidator.compose(tkValidator.fromString(midToken.toString())); DeepTokenRange left = new DeepTokenRange(range.getStartToken(), midpoint, range.getReplicas()); DeepTokenRange right = new DeepTokenRange(midpoint, range.getEndToken(), range.getReplicas()); if (bisectFactor / 2 <= 1) { accumulator.add(left); accumulator.add(right); } else { bisectTokeRange(left, partitioner, bisectFactor / 2, accumulator); bisectTokeRange(right, partitioner, bisectFactor / 2, accumulator); } }
return CONSISTENT; Token midpoint = ltree.partitioner().midpoint(active.left, active.right); TreeDifference left = new TreeDifference(active.left, midpoint, inc(active.depth)); TreeDifference right = new TreeDifference(midpoint, active.right, inc(active.depth));
return CONSISTENT; Token midpoint = ltree.partitioner().midpoint(active.left, active.right); TreeDifference left = new TreeDifference(active.left, midpoint, inc(active.depth)); TreeDifference right = new TreeDifference(midpoint, active.right, inc(active.depth));