@Override public Set<TokenRange> getTokenRanges() { return executeWithSession(session -> session.getCluster().getMetadata().getTokenRanges()); }
private Map<TokenRange, Set<Host>> getRangeMap() { Metadata metadata = this.session.metadata(); return metadata.getTokenRanges().stream().collect(Collectors.toMap( p -> p, p -> metadata.getReplicas('"' + this.keyspace + '"', p))); }
/** * Asserts that {@link Cluster}'s {@link Host}s have valid {@link TokenRange}s. * * <p>Ensures that no ranges intersect and that they cover the entire ring. */ public ClusterAssert hasValidTokenRanges() { // Sort the token ranges so they are in order (needed for vnodes). Set<TokenRange> ranges = new TreeSet<TokenRange>(actual.getMetadata().getTokenRanges()); return hasValidTokenRanges(ranges); }
/** * Asserts that {@link Cluster}'s {@link Host}s have valid {@link TokenRange}s with the given * keyspace. * * <p>Ensures that no ranges intersect and that they cover the entire ring. * * @param keyspace Keyspace to grab {@link TokenRange}s from. */ public ClusterAssert hasValidTokenRanges(String keyspace) { // Sort the token ranges so they are in order (needed for vnodes). Set<TokenRange> ranges = new TreeSet<TokenRange>(); for (Host host : actual.getMetadata().getAllHosts()) { ranges.addAll(actual.getMetadata().getTokenRanges(keyspace, host)); } return hasValidTokenRanges(ranges); }
@Test(groups = "short") public void should_expose_token_and_range_creation_methods() { Metadata metadata = cluster().getMetadata(); // Pick a random range TokenRange range = metadata.getTokenRanges().iterator().next(); Token start = metadata.newToken(range.getStart().toString()); Token end = metadata.newToken(range.getEnd().toString()); assertThat(metadata.newTokenRange(start, end)).isEqualTo(range); }
/** * Ensures that for the {@link TokenRange}s returned by {@link Metadata#getTokenRanges()} that * there exists at most one {@link TokenRange} for which calling {@link * TokenRange#isWrappedAround()} returns true and {@link TokenRange#unwrap()} returns two {@link * TokenRange}s. * * @test_category metadata:token * @expected_result Tokens are exposed by Host and match those in the system tables. * @jira_ticket JAVA-312 * @since 2.0.10, 2.1.5 */ @Test(groups = "short") public void should_only_unwrap_one_range_for_all_ranges() { Set<TokenRange> ranges = cluster().getMetadata().getTokenRanges(); assertOnlyOneWrapped(ranges); Iterable<TokenRange> splitRanges = Iterables.concat( Iterables.transform( ranges, new Function<TokenRange, Iterable<TokenRange>>() { @Override public Iterable<TokenRange> apply(TokenRange input) { return input.splitEvenly(10); } })); assertOnlyOneWrapped(splitRanges); }
private void checkRangesPerHost(String keyspace, int replicationFactor) { List<TokenRange> allRangesWithReplicas = Lists.newArrayList(); // Get each host's ranges, the count should match the replication factor for (int i = 1; i <= 3; i++) { Host host = TestUtils.findHost(cluster(), i); Set<TokenRange> hostRanges = cluster().getMetadata().getTokenRanges(keyspace, host); // Special case: When using vnodes the tokens are not evenly assigned to each replica. if (!useVnodes) { assertThat(hostRanges).hasSize(replicationFactor * numTokens); } allRangesWithReplicas.addAll(hostRanges); } // Special case check for vnodes to ensure that total number of replicated ranges is correct. assertThat(allRangesWithReplicas).hasSize(3 * numTokens * replicationFactor); // Once we ignore duplicates, the number of ranges should match the number of nodes. Set<TokenRange> allRanges = new HashSet<TokenRange>(allRangesWithReplicas); assertThat(allRanges).hasSize(3 * numTokens); // And the ranges should cover the whole ring and no ranges intersect. assertThat(cluster()).hasValidTokenRanges(keyspace); }
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata) { return metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata) { return metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
private Set<TokenRange> getTokenRanges() { Set<TokenRange> tokenRanges = new HashSet<>(); for (TokenRange tokenRange : metadata.getTokenRanges()) { tokenRanges.addAll(tokenRange.unwrap()); } return tokenRanges; }
/** JAVA-684: Empty TokenRange returned in a one token cluster */ @Test(groups = "short") public void should_return_single_non_empty_range_when_cluster_has_one_single_token() { cluster().manager.controlConnection.refreshNodeListAndTokenMap(); Metadata metadata = cluster().getMetadata(); Set<TokenRange> tokenRanges = metadata.getTokenRanges(); assertThat(tokenRanges).hasSize(1); TokenRange tokenRange = tokenRanges.iterator().next(); assertThat(tokenRange) .startsWith(Token.M3PToken.FACTORY.minToken()) .endsWith(Token.M3PToken.FACTORY.minToken()) .isNotEmpty() .isNotWrappedAround(); Set<Host> hostsForRange = metadata.getReplicas(keyspace, tokenRange); Host host1 = TestUtils.findHost(cluster(), 1); assertThat(hostsForRange).containsOnly(host1); ByteBuffer randomPartitionKey = Bytes.fromHexString("0xCAFEBABE"); Set<Host> hostsForKey = metadata.getReplicas(keyspace, randomPartitionKey); assertThat(hostsForKey).containsOnly(host1); Set<TokenRange> rangesForHost = metadata.getTokenRanges(keyspace, host1); assertThat(rangesForHost).containsOnly(tokenRange); } }
assertThat(metadata.getTokenRanges()).hasSize(3); Map<Host, Token> tokensForHost = getTokenForHosts(metadata); assertThat(metadata.getTokenRanges()).hasSize(2); assertThat(metadata.getTokenRanges()).hasSize(3); TokenRange host4Range = metadata.getTokenRanges(keyspace, host4).iterator().next(); TokenRange hostRange = metadata.getTokenRanges(keyspace, host).iterator().next(); assertThat(host4Range).doesNotIntersect(hostRange);
private Map<TokenRange, Set<Host>> getRangeMap() { Metadata metadata = this.session.metadata(); return metadata.getTokenRanges().stream().collect(Collectors.toMap( p -> p, p -> metadata.getReplicas('"' + this.keyspace + '"', p))); }
public NativeRingCache(Configuration conf, Metadata metadata) { this.partitioner = ConfigHelper.getOutputPartitioner(conf); this.metadata = metadata; String keyspace = ConfigHelper.getOutputKeyspace(conf); this.rangeMap = metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
public NativeRingCache(Configuration conf, Metadata metadata) { this.partitioner = ConfigHelper.getOutputPartitioner(conf); this.metadata = metadata; String keyspace = ConfigHelper.getOutputKeyspace(conf); this.rangeMap = metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
public NativeRingCache(Configuration conf, Metadata metadata) { this.partitioner = ConfigHelper.getOutputPartitioner(conf); this.metadata = metadata; String keyspace = ConfigHelper.getOutputKeyspace(conf); this.rangeMap = metadata.getTokenRanges() .stream() .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p))); }
assertThat(schemaDisabledCluster.getMetadata().newTokenRange(token1, token2)).isNotNull(); assertThat(schemaDisabledCluster.getMetadata().getTokenRanges()).isNotNull().isNotEmpty();
for (TokenRange range : metadata.getTokenRanges()) { List<Row> rows = rangeQuery(rangeStmt, range); for (Row row : rows) {
/** * Asserts that {@link Cluster}'s {@link Host}s have valid {@link TokenRange}s. * * <p>Ensures that no ranges intersect and that they cover the entire ring. */ public ClusterAssert hasValidTokenRanges() { // Sort the token ranges so they are in order (needed for vnodes). Set<TokenRange> ranges = new TreeSet<TokenRange>(actual.getMetadata().getTokenRanges()); return hasValidTokenRanges(ranges); }
@Test(groups = "short") public void should_expose_token_and_range_creation_methods() { Metadata metadata = cluster().getMetadata(); // Pick a random range TokenRange range = metadata.getTokenRanges().iterator().next(); Token start = metadata.newToken(range.getStart().toString()); Token end = metadata.newToken(range.getEnd().toString()); assertThat(metadata.newTokenRange(start, end)).isEqualTo(range); }