From 8ae6d0fdda5e3ffb6a3bea84b3623994e13352d8 Mon Sep 17 00:00:00 2001 From: Jordan West Date: Wed, 10 Feb 2021 18:29:38 -0800 Subject: [PATCH] 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. --- .../plugin/cass/CassJavaDriverGeneric.java | 21 ++++++++++++------- .../CassandraGenericConfiguration.java | 7 +++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/cass/CassJavaDriverGeneric.java b/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/cass/CassJavaDriverGeneric.java index 3ff284b5..52f07c41 100644 --- a/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/cass/CassJavaDriverGeneric.java +++ b/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/cass/CassJavaDriverGeneric.java @@ -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); } @@ -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 { diff --git a/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/configs/CassandraGenericConfiguration.java b/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/configs/CassandraGenericConfiguration.java index 9504d964..6bf7b81f 100644 --- a/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/configs/CassandraGenericConfiguration.java +++ b/ndbench-cass-plugins/src/main/java/com/netflix/ndbench/plugin/configs/CassandraGenericConfiguration.java @@ -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(); }