Skip to content

Commit

Permalink
CassJavaDriverGeneric: add options to disable use of batch writes
Browse files Browse the repository at this point in the history
The use of BATCH in CassJavaDriverGeneric allows the driver to write
multiple rows in a single call to `writeSingle`. Its sometimes
desirable, however, to have `writeSingle` to truly write a single row
so that BATCH is not used.

This can cause the row count validation to fail since not every row is
written to every partition. Ad additional configuration has been added
to disable this valdiation.
  • Loading branch information
jrwest authored and sumanth-pasupuleti committed Feb 11, 2021
1 parent 4d82dc3 commit 8ae6d0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String readSingle(String key) throws Exception {
if (!result.isEmpty())
{
nRows = result.size();
if (nRows < (config.getRowsPerPartition()))
if (config.getValidateRowsPerPartition() && nRows < (config.getRowsPerPartition()))
{
throw new Exception("Num rows returned not ok " + nRows);
}
Expand Down Expand Up @@ -99,14 +99,19 @@ public String writeSingle(String key)
{
if(config.getRowsPerPartition() > 1)
{
BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);
batch.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel()));
for (int i = 0; i < config.getRowsPerPartition(); i++)
{
batch.add(getWriteBStmt(key,i));
if (config.getUseBatchWrites()) {
BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);
batch.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel()));
for (int i = 0; i < config.getRowsPerPartition(); i++) {
batch.add(getWriteBStmt(key, i));
}
session.execute(batch);
batch.clear();
} else {
session.execute(getWriteBStmt(key, dataGenerator.getRandomInteger() % config.getRowsPerPartition())
.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel())));

}
session.execute(batch);
batch.clear();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
public interface CassandraGenericConfiguration extends CassandraConfigurationBase {
@DefaultValue("2")
Integer getRowsPerPartition();

@DefaultValue("5")
Integer getColsPerRow();

@DefaultValue("false")
Boolean getUseBatchWrites();

@DefaultValue("false")
Boolean getValidateRowsPerPartition();
}

0 comments on commit 8ae6d0f

Please sign in to comment.