com.datastax.driver.core.Token Java Examples

The following examples show how to use com.datastax.driver.core.Token. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PeerMetadataIntegrationTest.java    From simulacron with Apache License 2.0 6 votes vote down vote up
@Test
public void testVnodeSupport() throws Exception {
  // Validate that peers as appropriately discovered when connecting to a node and vnodes are
  // assigned.
  try (BoundCluster boundCluster =
          server.register(ClusterSpec.builder().withNumberOfTokens(256).withNodes(3, 3, 3));
      Cluster driverCluster = defaultBuilder(boundCluster).build()) {
    driverCluster.init();

    // Should be 9 hosts
    assertThat(driverCluster.getMetadata().getAllHosts()).hasSize(9);

    Set<Token> allTokens = new HashSet<>();
    for (Host host : driverCluster.getMetadata().getAllHosts()) {
      assertThat(host.getTokens()).hasSize(256);
      allTokens.addAll(host.getTokens());
    }

    // Should be 256*9 unique tokens.
    assertThat(allTokens).hasSize(256 * 9);
  }
}
 
Example #2
Source File: CassandraMetricBatch.java    From monasca-persister with Apache License 2.0 6 votes vote down vote up
private void logTokenBatchMap(String name, Map<Token, Deque<BatchStatement>> map) {
  if (logger.isDebugEnabled()) {
    StringBuilder sb = new StringBuilder(name);
    sb.append(": Size: ").append(map.size());
    sb.append(";  Tokens: |");
    for (Entry<Token, Deque<BatchStatement>> entry : map.entrySet()) {
      sb.append(entry.getKey().toString()).append(":");
      for (BatchStatement bs : entry.getValue()) {
        sb.append(bs.size()).append(",");
      }
      sb.append("|.");
    }

    logger.debug(sb.toString());
  }
}
 
Example #3
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
private Observable.Transformer<BoundStatement, Integer> applyMicroBatching() {
    return tObservable -> tObservable
            .groupBy(b -> {
                ByteBuffer routingKey = b.getRoutingKey(ProtocolVersion.NEWEST_SUPPORTED,
                        codecRegistry);
                Token token = metadata.newToken(routingKey);
                for (TokenRange tokenRange : session.getCluster().getMetadata().getTokenRanges()) {
                    if (tokenRange.contains(token)) {
                        return tokenRange;
                    }
                }
                log.warn("Unable to find any Cassandra node to insert token " + token.toString());
                return session.getCluster().getMetadata().getTokenRanges().iterator().next();
            })
            .flatMap(g -> g.compose(new BoundBatchStatementTransformer()))
            .flatMap(batch -> rxSession
                    .execute(batch)
                    .compose(applyInsertRetryPolicy())
                    .map(resultSet -> batch.size())
            );
}
 
Example #4
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public Token getToken(int i) {
    throw new UnsupportedOperationException();
}
 
Example #5
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public Token getToken(String name) {
    throw new UnsupportedOperationException();
}
 
Example #6
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public Token getPartitionKeyToken() {
    throw new UnsupportedOperationException();
}