Search in sources :

Example 6 with JavaDriverClient

use of org.apache.cassandra.stress.util.JavaDriverClient in project cassandra by apache.

the class ValidatingSchemaQuery method prepare.

private static ValidatingStatement prepare(StressSettings settings, String cql, boolean incLb, boolean incUb) {
    JavaDriverClient jclient = settings.getJavaDriverClient();
    PreparedStatement statement = jclient.prepare(cql);
    return new ValidatingStatement(statement, incLb, incUb);
}
Also used : JavaDriverClient(org.apache.cassandra.stress.util.JavaDriverClient)

Example 7 with JavaDriverClient

use of org.apache.cassandra.stress.util.JavaDriverClient in project cassandra by apache.

the class SettingsCommand method truncateTables.

protected void truncateTables(StressSettings settings, String ks, String... tables) {
    JavaDriverClient client = settings.getJavaDriverClient(false);
    assert settings.command.truncate != SettingsCommand.TruncateWhen.NEVER;
    for (String table : tables) {
        String cql = String.format("TRUNCATE %s.%s", ks, table);
        client.execute(cql, org.apache.cassandra.db.ConsistencyLevel.ONE);
    }
    System.out.println(String.format("Truncated %s.%s. Sleeping %ss for propagation.", ks, Arrays.toString(tables), settings.node.nodes.size()));
    Uninterruptibles.sleepUninterruptibly(settings.node.nodes.size(), TimeUnit.SECONDS);
}
Also used : JavaDriverClient(org.apache.cassandra.stress.util.JavaDriverClient)

Example 8 with JavaDriverClient

use of org.apache.cassandra.stress.util.JavaDriverClient in project cassandra by apache.

the class StressProfile method maybeLoadTokenRanges.

public Set<TokenRange> maybeLoadTokenRanges(StressSettings settings) {
    // ensure table metadata is available
    maybeLoadSchemaInfo(settings);
    JavaDriverClient client = settings.getJavaDriverClient();
    synchronized (client) {
        if (tokenRanges != null)
            return tokenRanges;
        Cluster cluster = client.getCluster();
        Metadata metadata = cluster.getMetadata();
        if (metadata == null)
            throw new RuntimeException("Unable to get metadata");
        List<TokenRange> sortedRanges = new ArrayList<>(metadata.getTokenRanges().size() + 1);
        for (TokenRange range : metadata.getTokenRanges()) {
            //if we don't unwrap we miss the partitions between ring min and smallest range start value
            if (range.isWrappedAround())
                sortedRanges.addAll(range.unwrap());
            else
                sortedRanges.add(range);
        }
        Collections.sort(sortedRanges);
        tokenRanges = new LinkedHashSet<>(sortedRanges);
        return tokenRanges;
    }
}
Also used : JavaDriverClient(org.apache.cassandra.stress.util.JavaDriverClient) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) TableMetadata(com.datastax.driver.core.TableMetadata)

Example 9 with JavaDriverClient

use of org.apache.cassandra.stress.util.JavaDriverClient in project cassandra by apache.

the class StressProfile method maybeLoadSchemaInfo.

private void maybeLoadSchemaInfo(StressSettings settings) {
    if (tableMetaData == null) {
        JavaDriverClient client = settings.getJavaDriverClient();
        synchronized (client) {
            if (tableMetaData != null)
                return;
            TableMetadata metadata = client.getCluster().getMetadata().getKeyspace(keyspaceName).getTable(quoteIdentifier(tableName));
            if (metadata == null)
                throw new RuntimeException("Unable to find table " + keyspaceName + "." + tableName);
            //Fill in missing column configs
            for (com.datastax.driver.core.ColumnMetadata col : metadata.getColumns()) {
                if (columnConfigs.containsKey(col.getName()))
                    continue;
                columnConfigs.put(col.getName(), new GeneratorConfig(seedStr + col.getName(), null, null, null));
            }
            tableMetaData = metadata;
        }
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) JavaDriverClient(org.apache.cassandra.stress.util.JavaDriverClient) com.datastax.driver.core(com.datastax.driver.core)

Example 10 with JavaDriverClient

use of org.apache.cassandra.stress.util.JavaDriverClient in project cassandra by apache.

the class StressProfile method maybeCreateSchema.

public void maybeCreateSchema(StressSettings settings) {
    if (!schemaCreated) {
        JavaDriverClient client = settings.getJavaDriverClient(false);
        if (keyspaceCql != null) {
            try {
                client.execute(keyspaceCql, org.apache.cassandra.db.ConsistencyLevel.ONE);
            } catch (AlreadyExistsException e) {
            }
        }
        client.execute("use " + keyspaceName, org.apache.cassandra.db.ConsistencyLevel.ONE);
        if (tableCql != null) {
            try {
                client.execute(tableCql, org.apache.cassandra.db.ConsistencyLevel.ONE);
            } catch (AlreadyExistsException e) {
            }
            System.out.println(String.format("Created schema. Sleeping %ss for propagation.", settings.node.nodes.size()));
            Uninterruptibles.sleepUninterruptibly(settings.node.nodes.size(), TimeUnit.SECONDS);
        }
        if (extraSchemaDefinitions != null) {
            for (String extraCql : extraSchemaDefinitions) {
                try {
                    client.execute(extraCql, org.apache.cassandra.db.ConsistencyLevel.ONE);
                } catch (AlreadyExistsException e) {
                }
            }
            System.out.println(String.format("Created extra schema. Sleeping %ss for propagation.", settings.node.nodes.size()));
            Uninterruptibles.sleepUninterruptibly(settings.node.nodes.size(), TimeUnit.SECONDS);
        }
        schemaCreated = true;
    }
    maybeLoadSchemaInfo(settings);
}
Also used : JavaDriverClient(org.apache.cassandra.stress.util.JavaDriverClient) AlreadyExistsException(com.datastax.driver.core.exceptions.AlreadyExistsException)

Aggregations

JavaDriverClient (org.apache.cassandra.stress.util.JavaDriverClient)10 com.datastax.driver.core (com.datastax.driver.core)2 TableMetadata (com.datastax.driver.core.TableMetadata)2 AlreadyExistsException (com.datastax.driver.core.exceptions.AlreadyExistsException)2 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)2 CharacterCodingException (java.nio.charset.CharacterCodingException)1 EncryptionOptions (org.apache.cassandra.config.EncryptionOptions)1 SchemaInsert (org.apache.cassandra.stress.operations.userdefined.SchemaInsert)1 SchemaQuery (org.apache.cassandra.stress.operations.userdefined.SchemaQuery)1 ValidatingSchemaQuery (org.apache.cassandra.stress.operations.userdefined.ValidatingSchemaQuery)1