Search in sources :

Example 1 with TokenFactory

use of org.apache.cassandra.dht.Token.TokenFactory in project cassandra by apache.

the class NativeSSTableLoaderClient method init.

public void init(String keyspace) {
    Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port);
    if (sslOptions != null)
        builder.withSSL(sslOptions);
    if (authProvider != null)
        builder = builder.withAuthProvider(authProvider);
    try (Cluster cluster = builder.build();
        Session session = cluster.connect()) {
        Metadata metadata = cluster.getMetadata();
        Set<TokenRange> tokenRanges = metadata.getTokenRanges();
        IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner());
        TokenFactory tokenFactory = partitioner.getTokenFactory();
        for (TokenRange tokenRange : tokenRanges) {
            Set<Host> endpoints = metadata.getReplicas(Metadata.quote(keyspace), tokenRange);
            Range<Token> range = new Range<>(tokenFactory.fromString(tokenRange.getStart().getValue().toString()), tokenFactory.fromString(tokenRange.getEnd().getValue().toString()));
            for (Host endpoint : endpoints) addRangeForEndpoint(range, endpoint.getAddress());
        }
        Types types = fetchTypes(keyspace, session);
        tables.putAll(fetchTables(keyspace, session, partitioner, types));
        // We only need the TableMetadata for the views, so we only load that.
        tables.putAll(fetchViews(keyspace, session, partitioner, types));
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) TableMetadata(org.apache.cassandra.schema.TableMetadata) Token(org.apache.cassandra.dht.Token) TokenFactory(org.apache.cassandra.dht.Token.TokenFactory)

Aggregations

Token (org.apache.cassandra.dht.Token)1 TokenFactory (org.apache.cassandra.dht.Token.TokenFactory)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1