Skip to content

Commit 8ae6d0f

Browse files
jrwestsumanth-pasupuleti
authored andcommitted
CassJavaDriverGeneric: add options to disable use of batch writes
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.
1 parent 4d82dc3 commit 8ae6d0f

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/cass/CassJavaDriverGeneric.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public String readSingle(String key) throws Exception {
6767
if (!result.isEmpty())
6868
{
6969
nRows = result.size();
70-
if (nRows < (config.getRowsPerPartition()))
70+
if (config.getValidateRowsPerPartition() && nRows < (config.getRowsPerPartition()))
7171
{
7272
throw new Exception("Num rows returned not ok " + nRows);
7373
}
@@ -99,14 +99,19 @@ public String writeSingle(String key)
9999
{
100100
if(config.getRowsPerPartition() > 1)
101101
{
102-
BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);
103-
batch.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel()));
104-
for (int i = 0; i < config.getRowsPerPartition(); i++)
105-
{
106-
batch.add(getWriteBStmt(key,i));
102+
if (config.getUseBatchWrites()) {
103+
BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);
104+
batch.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel()));
105+
for (int i = 0; i < config.getRowsPerPartition(); i++) {
106+
batch.add(getWriteBStmt(key, i));
107+
}
108+
session.execute(batch);
109+
batch.clear();
110+
} else {
111+
session.execute(getWriteBStmt(key, dataGenerator.getRandomInteger() % config.getRowsPerPartition())
112+
.setConsistencyLevel(ConsistencyLevel.valueOf(config.getWriteConsistencyLevel())));
113+
107114
}
108-
session.execute(batch);
109-
batch.clear();
110115
}
111116
else
112117
{

ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/configs/CassandraGenericConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
public interface CassandraGenericConfiguration extends CassandraConfigurationBase {
2424
@DefaultValue("2")
2525
Integer getRowsPerPartition();
26+
2627
@DefaultValue("5")
2728
Integer getColsPerRow();
29+
30+
@DefaultValue("false")
31+
Boolean getUseBatchWrites();
32+
33+
@DefaultValue("false")
34+
Boolean getValidateRowsPerPartition();
2835
}

0 commit comments

Comments
 (0)