Elffuss BraidHub

kikocis/java-driver public

Merge pull request #460 from datastax/java919

JAVA-919: Move crc_check_chance out of compressions options.
Changeseta18d9fe5715a8219f9e94a9abab8c0b257f1d59e9092c5f2cbfd1a4b3a613200
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-09-18 14:36 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-09-18 14:36 -05:00
Parents2521b15bf39d, fd581548d210

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +30 −0
@@ -283,6 +283,9 @@
283283 and(sb, formatted).append("min_index_interval = ").append(options.minIndexInterval);
284284 and(sb, formatted).append("max_index_interval = ").append(options.maxIndexInterval);
285285 }
286+ if (cassandraVersion.getMajor() > 2) {
287+ and(sb, formatted).append("crc_check_chance = ").append(options.crcCheckChance);
288+ }
286289 sb.append(';');
287290 return sb;
288291 }
@@ -367,6 +370,7 @@
367370 private static final String INDEX_INTERVAL = "index_interval";
368371 private static final String MIN_INDEX_INTERVAL = "min_index_interval";
369372 private static final String MAX_INDEX_INTERVAL = "max_index_interval";
373+ private static final String CRC_CHECK_CHANCE = "crc_check_chance";
370374
371375 private static final boolean DEFAULT_REPLICATE_ON_WRITE = true;
372376 private static final double DEFAULT_BF_FP_CHANCE = 0.01;
@@ -377,6 +381,7 @@
377381 private static final int DEFAULT_INDEX_INTERVAL = 128;
378382 private static final int DEFAULT_MIN_INDEX_INTERVAL = 128;
379383 private static final int DEFAULT_MAX_INDEX_INTERVAL = 2048;
384+ private static final double DEFAULT_CRC_CHECK_CHANCE = 1.0;
380385
381386 private final boolean isCompactStorage;
382387
@@ -396,6 +401,7 @@
396401 private final Integer maxIndexInterval;
397402 private final Map<String, String> compaction;
398403 private final Map<String, String> compression;
404+ private final Double crcCheckChance;
399405
400406 Options(Row row, boolean isCompactStorage, VersionNumber version) {
401407
@@ -461,6 +467,13 @@
461467 this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class));
462468 else
463469 this.compression = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(COMPRESSION_PARAMS)));
470+
471+ if(is300OrHigher)
472+ this.crcCheckChance = isNullOrAbsent(row, CRC_CHECK_CHANCE)
473+ ? DEFAULT_CRC_CHECK_CHANCE
474+ : row.getDouble(CRC_CHECK_CHANCE);
475+ else
476+ this.crcCheckChance = null;
464477 }
465478
466479 private static boolean isNullOrAbsent(Row row, String name) {
@@ -627,6 +640,23 @@
627640 return maxIndexInterval;
628641 }
629642
643+ /**
644+ * When compression is enabled, this option defines the probability
645+ * with which checksums for compressed blocks are checked during reads.
646+ * The default value for this options is 1.0 (always check).
647+ * <p>
648+ * Note that this option is available in Cassandra 3.0.0 and above, when it
649+ * became a "top-level" table option, whereas previously it was a suboption
650+ * of the {@link #getCompression() compression} option.
651+ * <p>
652+ * For Cassandra versions prior to 3.0.0, this method always returns {@code null}.
653+ *
654+ * @return the probability with which checksums for compressed blocks are checked during reads
655+ */
656+ public Double getCrcCheckChance() {
657+ return crcCheckChance;
658+ }
659+
630660 /**
631661 * Returns the compaction options for this table.
632662 *
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +4 −1
@@ -211,7 +211,8 @@
211211 + " AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 10 }\n"
212212 + " AND comment = 'My awesome table'\n"
213213 + " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n"
214- + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };",
214+ + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 }\n"
215+ + " AND crc_check_chance = 0.5;", // available from C* 3.0
215216 keyspace);
216217
217218 // older versions
@@ -267,6 +268,7 @@
267268 assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128);
268269 assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048);
269270 assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default
271+ assertThat(table.getOptions().getCrcCheckChance()).isEqualTo(0.5);
270272 assertThat(table.asCQLQuery())
271273 .contains("read_repair_chance = 0.5")
272274 .contains("dclocal_read_repair_chance = 0.6")
@@ -283,6 +285,7 @@
283285 .contains("speculative_retry = '99.9PERCENTILE'")
284286 .contains("min_index_interval = 128")
285287 .contains("max_index_interval = 2048")
288+ .contains("crc_check_chance = 0.5")
286289 .doesNotContain(" index_interval")
287290 .doesNotContain("replicate_on_write");
288291