本文整理了Java中com.datastax.driver.core.Metadata.getTokenRanges()
方法的一些代码示例,展示了Metadata.getTokenRanges()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.getTokenRanges()
方法的具体详情如下:
包路径:com.datastax.driver.core.Metadata
类名称:Metadata
方法名:getTokenRanges
[英]Returns the token ranges that define data distribution in the ring.
Note that this information is refreshed asynchronously by the control connection, when schema or ring topology changes. It might occasionally be stale.
[中]返回定义环中数据分布的令牌范围。
请注意,当模式或环拓扑发生更改时,控制连接将异步刷新此信息。它可能偶尔会过时。
代码示例来源:origin: prestodb/presto
@Override
public Set<TokenRange> getTokenRanges()
{
return executeWithSession(session -> session.getCluster().getMetadata().getTokenRanges());
}
代码示例来源:origin: hugegraph/hugegraph
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)));
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* 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);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* 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);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@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);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* 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);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
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);
}
代码示例来源:origin: jsevellec/cassandra-unit
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata)
{
return metadata.getTokenRanges()
.stream()
.collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p)));
}
代码示例来源:origin: org.apache.cassandra/cassandra-all
private Map<TokenRange, Set<Host>> getRangeMap(String keyspace, Metadata metadata)
{
return metadata.getTokenRanges()
.stream()
.collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p)));
}
代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-core-service
private Set<TokenRange> getTokenRanges() {
Set<TokenRange> tokenRanges = new HashSet<>();
for (TokenRange tokenRange : metadata.getTokenRanges()) {
tokenRanges.addAll(tokenRange.unwrap());
}
return tokenRanges;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/** 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);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
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);
代码示例来源:origin: com.baidu.hugegraph/hugegraph-cassandra
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)));
}
代码示例来源:origin: org.apache.cassandra/cassandra-all
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)));
}
代码示例来源:origin: jsevellec/cassandra-unit
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)));
}
代码示例来源:origin: com.strapdata.cassandra/cassandra-all
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)));
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
assertThat(schemaDisabledCluster.getMetadata().newTokenRange(token1, token2)).isNotNull();
assertThat(schemaDisabledCluster.getMetadata().getTokenRanges()).isNotNull().isNotEmpty();
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
for (TokenRange range : metadata.getTokenRanges()) {
List<Row> rows = rangeQuery(rangeStmt, range);
for (Row row : rows) {
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
/**
* 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);
}
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@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);
}
内容来源于网络,如有侵权,请联系作者删除!