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);
}
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);
}
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;
}
}
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;
}
}
}
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);
}
Aggregations