@Override public List<KeyRange> getLocalKeyPartition() throws BackendException { CTConnection conn = null; IPartitioner partitioner = getCassandraPartitioner(); if (!(partitioner instanceof AbstractByteOrderedPartitioner)) throw new UnsupportedOperationException("getLocalKeyPartition() only supported by byte ordered partitioner."); Token.TokenFactory tokenFactory = partitioner.getTokenFactory(); try { // Resist the temptation to describe SYSTEM_KS. It has no ring. // Instead, we'll create our own keyspace (or check that it exists), then describe it. ensureKeyspaceExists(keySpaceName); conn = pool.borrowObject(keySpaceName); List<TokenRange> ranges = conn.getClient().describe_ring(keySpaceName); List<KeyRange> keyRanges = new ArrayList<KeyRange>(ranges.size()); for (TokenRange range : ranges) { if (!NetworkUtil.hasLocalAddress(range.endpoints)) continue; keyRanges.add(CassandraHelper.transformRange(tokenFactory.fromString(range.start_token), tokenFactory.fromString(range.end_token))); } return keyRanges; } catch (Exception e) { throw CassandraThriftKeyColumnValueStore.convertException(e); } finally { pool.returnObjectUnsafe(keySpaceName, conn); } }
TokenFactory tokenFactory = this.partitioner.getTokenFactory(); TokenRange tokenRange = rangeToTokenRange(new Range<>( tokenFactory.fromString(start), tokenFactory.fromString(end)));
@VisibleForTesting public List<Token> resplitLocally(String startToken, String endToken, int numResplits) { List<Token> splitTokens = ImmutableList.of(_tokenFactory.fromString(startToken), _tokenFactory.fromString(endToken)); for (int i = 0; i < numResplits; i++) { List<Token> newTokens = new ArrayList<>(splitTokens.size() * 2 - 1); for (int j = 0; j < splitTokens.size() - 1; j++) { newTokens.add(splitTokens.get(j)); newTokens.add(ByteOrderedPartitioner.instance.midpoint(splitTokens.get(j), splitTokens.get(j + 1))); } newTokens.add(splitTokens.get(splitTokens.size() - 1)); splitTokens = newTokens; } return splitTokens; }
/** * Handle node moving inside the ring. * * @param endpoint moving endpoint address * @param pieces STATE_MOVING, token */ private void handleStateMoving(InetAddress endpoint, String[] pieces) { assert pieces.length >= 2; Token token = getTokenFactory().fromString(pieces[1]); if (logger.isDebugEnabled()) logger.debug("Node {} state moving, new token {}", endpoint, token); tokenMetadata.addMovingEndpoint(token, endpoint); PendingRangeCalculatorService.instance.update(); }
/** * Handle node moving inside the ring. * * @param endpoint moving endpoint address * @param pieces STATE_MOVING, token */ private void handleStateMoving(InetAddress endpoint, String[] pieces) { assert pieces.length >= 2; Token token = getPartitioner().getTokenFactory().fromString(pieces[1]); if (logger.isDebugEnabled()) logger.debug("Node {} state moving, new token {}", endpoint, token); tokenMetadata.addMovingEndpoint(token, endpoint); PendingRangeCalculatorService.instance.update(); }
private ByteBuffer parseTokenString(String string) { return _tokenFactory.toByteArray(_tokenFactory.fromString(string)); }
@VisibleForTesting public List<Token> resplitLocally(String startToken, String endToken, int numResplits) { List<Token> splitTokens = ImmutableList.of(_tokenFactory.fromString(startToken), _tokenFactory.fromString(endToken)); for (int i = 0; i < numResplits; i++) { List<Token> newTokens = new ArrayList<>(splitTokens.size() * 2 - 1); for (int j = 0; j < splitTokens.size() - 1; j++) { newTokens.add(splitTokens.get(j)); newTokens.add(ByteOrderedPartitioner.instance.midpoint(splitTokens.get(j), splitTokens.get(j + 1))); } newTokens.add(splitTokens.get(splitTokens.size() - 1)); splitTokens = newTokens; } return splitTokens; }
private static Collection<Token> getSpecifiedTokens(final TokenMetadata metadata, Collection<String> initialTokens) { logger.info("tokens manually specified as {}", initialTokens); List<Token> tokens = new ArrayList<>(initialTokens.size()); for (String tokenString : initialTokens) { Token token = metadata.partitioner.getTokenFactory().fromString(tokenString); if (metadata.getEndpoint(token) != null) throw new ConfigurationException("Bootstrapping to existing token " + tokenString + " is not allowed (decommission/removenode the old node first)."); tokens.add(token); } return tokens; }
/** * Handle node moving inside the ring. * * @param endpoint moving endpoint address * @param pieces STATE_MOVING, token */ private void handleStateMoving(InetAddress endpoint, String[] pieces) { assert pieces.length >= 2; Token token = getTokenFactory().fromString(pieces[1]); if (logger.isDebugEnabled()) logger.debug("Node {} state moving, new token {}", endpoint, token); tokenMetadata.addMovingEndpoint(token, endpoint); PendingRangeCalculatorService.instance.update(); }
private static Collection<Token> getSpecifiedTokens(final TokenMetadata metadata, Collection<String> initialTokens) { logger.info("tokens manually specified as {}", initialTokens); List<Token> tokens = new ArrayList<>(initialTokens.size()); for (String tokenString : initialTokens) { Token token = metadata.partitioner.getTokenFactory().fromString(tokenString); if (metadata.getEndpoint(token) != null) throw new ConfigurationException("Bootstrapping to existing token " + tokenString + " is not allowed (decommission/removenode the old node first)."); tokens.add(token); } return tokens; }
private static Collection<Token> getSpecifiedTokens(final TokenMetadata metadata, Collection<String> initialTokens) { logger.info("tokens manually specified as {}", initialTokens); List<Token> tokens = new ArrayList<>(initialTokens.size()); for (String tokenString : initialTokens) { Token token = metadata.partitioner.getTokenFactory().fromString(tokenString); if (metadata.getEndpoint(token) != null) throw new ConfigurationException("Bootstrapping to existing token " + tokenString + " is not allowed (decommission/removenode the old node first)."); tokens.add(token); } return tokens; }
private static Collection<Token> deserializeTokens(Collection<String> tokensStrings) { Token.TokenFactory factory = StorageService.instance.getTokenFactory(); List<Token> tokens = new ArrayList<>(tokensStrings.size()); for (String tk : tokensStrings) tokens.add(factory.fromString(tk)); return tokens; }
public void move(String newToken) throws IOException { try { getPartitioner().getTokenFactory().validate(newToken); } catch (ConfigurationException e) { throw new IOException(e.getMessage()); } move(getPartitioner().getTokenFactory().fromString(newToken)); }
private static Collection<Token> deserializeTokens(Collection<String> tokensStrings) { Token.TokenFactory factory = StorageService.instance.getTokenFactory(); List<Token> tokens = new ArrayList<>(tokensStrings.size()); for (String tk : tokensStrings) tokens.add(factory.fromString(tk)); return tokens; }
public void move(String newToken) throws IOException { try { getTokenFactory().validate(newToken); } catch (ConfigurationException e) { throw new IOException(e.getMessage()); } move(getTokenFactory().fromString(newToken)); }
private static Collection<Token> deserializeTokens(Collection<String> tokensStrings) { Token.TokenFactory factory = StorageService.getPartitioner().getTokenFactory(); List<Token> tokens = new ArrayList<Token>(tokensStrings.size()); for (String tk : tokensStrings) tokens.add(factory.fromString(tk)); return tokens; }
/** * Returns the specified token as a {@link java.lang.Comparable}. * * @param tokenAsString a token represented as a {@link java.lang.String}. * @return the specified token as a {@link java.lang.Comparable}. */ @SuppressWarnings("unchecked") public Comparable tokenAsComparable(String tokenAsString) { Token token = tokenFactory.fromString(tokenAsString); ByteBuffer bb = tokenFactory.toByteArray(token); return (Comparable) tokenType.compose(bb); }
public void move(String newToken) throws IOException { try { getTokenFactory().validate(newToken); } catch (ConfigurationException e) { throw new IOException(e.getMessage()); } move(getTokenFactory().fromString(newToken)); }
public void move(String newToken) throws IOException { try { getTokenFactory().validate(newToken); } catch (ConfigurationException e) { throw new IOException(e.getMessage()); } move(getTokenFactory().fromString(newToken)); }
private static Collection<Token> deserializeTokens(Collection<String> tokensStrings) { Token.TokenFactory factory = StorageService.instance.getTokenFactory(); List<Token> tokens = new ArrayList<>(tokensStrings.size()); for (String tk : tokensStrings) tokens.add(factory.fromString(tk)); return tokens; }