public String getToken() { if (StorageService.instance.isClientMode()) return CassandraUtils.fakeToken; return StorageService.instance.getTokenMetadata().getToken(FBUtilities.getLocalAddress()).toString(); }
private String sanitizeBrokenByteToken(Token<?> tok) { /* * Background: https://issues.apache.org/jira/browse/CASSANDRA-5566 * * This check is useful for compatibility with Cassandra server versions * 1.2.4 and earlier. */ String st = tok.toString(); if (!(tok instanceof BytesToken)) return st; // Do a cheap 1-character startsWith before unleashing the regex if (st.startsWith("T")) { Matcher m = BROKEN_BYTE_TOKEN_PATTERN.matcher(st); if (!m.matches()) { logger.warn("Unknown token string format: \"{}\"", st); } else { String old = st; st = m.group(1); logger.debug("Rewrote token string: \"{}\" -> \"{}\"", old, st); } } return st; }
/** * check whether current row is at the end of range * * @return the boolean */ private boolean reachEndRange() { // current row key ByteBuffer rowKey; if (keyValidator instanceof CompositeType) { ByteBuffer[] keys = new ByteBuffer[partitionBoundColumns.size()]; for (int i = 0; i < partitionBoundColumns.size(); i++) { keys[i] = partitionBoundColumns.get(i).value.duplicate(); } rowKey = CompositeType.build(keys); } else { rowKey = partitionBoundColumns.get(0).value; } String endToken = String.valueOf(split.getEndToken()); String currentToken = partitioner.getToken(rowKey).toString(); return endToken.equals(currentToken); }
/** check whether current row is at the end of range */ private boolean reachEndRange() { // current row key ByteBuffer rowKey; if (keyValidator instanceof CompositeType) { ByteBuffer[] keys = new ByteBuffer[partitionBoundColumns.size()]; for (int i = 0; i < partitionBoundColumns.size(); i++) keys[i] = partitionBoundColumns.get(i).value.duplicate(); rowKey = CompositeType.build(keys); } else { rowKey = partitionBoundColumns.get(0).value; } String endToken = split.getEndToken(); String currentToken = partitioner.getToken(rowKey).toString(); logger.debug("End token: {}, current token: {}", endToken, currentToken); return endToken.equals(currentToken); }
/** * 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); } }