Elffuss BraidHub

kikocis/java-driver public

JAVA-919: Move crc_check_chance out of compressions options.
Changesetfd581548d2100ee8be013d4465eadfb8c29534391227ebdde9030ab645dfb650
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-17 17:07 +02:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-17 18:23 +02:00
Parents8e3e8fb031fa

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +30 −0
@@ -281,6 +281,9 @@
281281 and(sb, formatted).append("min_index_interval = ").append(options.minIndexInterval);
282282 and(sb, formatted).append("max_index_interval = ").append(options.maxIndexInterval);
283283 }
284+ if (cassandraVersion.getMajor() > 2) {
285+ and(sb, formatted).append("crc_check_chance = ").append(options.crcCheckChance);
286+ }
284287 sb.append(';');
285288 return sb;
286289 }
@@ -365,6 +368,7 @@
365368 private static final String INDEX_INTERVAL = "index_interval";
366369 private static final String MIN_INDEX_INTERVAL = "min_index_interval";
367370 private static final String MAX_INDEX_INTERVAL = "max_index_interval";
371+ private static final String CRC_CHECK_CHANCE = "crc_check_chance";
368372
369373 private static final boolean DEFAULT_REPLICATE_ON_WRITE = true;
370374 private static final double DEFAULT_BF_FP_CHANCE = 0.01;
@@ -375,6 +379,7 @@
375379 private static final int DEFAULT_INDEX_INTERVAL = 128;
376380 private static final int DEFAULT_MIN_INDEX_INTERVAL = 128;
377381 private static final int DEFAULT_MAX_INDEX_INTERVAL = 2048;
382+ private static final double DEFAULT_CRC_CHECK_CHANCE = 1.0;
378383
379384 private final boolean isCompactStorage;
380385
@@ -394,6 +399,7 @@
394399 private final Integer maxIndexInterval;
395400 private final Map<String, String> compaction;
396401 private final Map<String, String> compression;
402+ private final Double crcCheckChance;
397403
398404 Options(Row row, boolean isCompactStorage, VersionNumber version) {
399405
@@ -459,6 +465,13 @@
459465 this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class));
460466 else
461467 this.compression = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(COMPRESSION_PARAMS)));
468+
469+ if(is300OrHigher)
470+ this.crcCheckChance = isNullOrAbsent(row, CRC_CHECK_CHANCE)
471+ ? DEFAULT_CRC_CHECK_CHANCE
472+ : row.getDouble(CRC_CHECK_CHANCE);
473+ else
474+ this.crcCheckChance = null;
462475 }
463476
464477 private static boolean isNullOrAbsent(Row row, String name) {
@@ -625,6 +638,23 @@
625638 return maxIndexInterval;
626639 }
627640
641+ /**
642+ * When compression is enabled, this option defines the probability
643+ * with which checksums for compressed blocks are checked during reads.
644+ * The default value for this options is 1.0 (always check).
645+ * <p>
646+ * Note that this option is available in Cassandra 3.0.0 and above, when it
647+ * became a "top-level" table option, whereas previously it was a suboption
648+ * of the {@link #getCompression() compression} option.
649+ * <p>
650+ * For Cassandra versions prior to 3.0.0, this method always returns {@code null}.
651+ *
652+ * @return the probability with which checksums for compressed blocks are checked during reads
653+ */
654+ public Double getCrcCheckChance() {
655+ return crcCheckChance;
656+ }
657+
628658 /**
629659 * Returns the compaction options for this table.
630660 *
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +4 −1
@@ -196,7 +196,8 @@
196196 + " AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 10 }\n"
197197 + " AND comment = 'My awesome table'\n"
198198 + " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n"
199- + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };",
199+ + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 }\n"
200+ + " AND crc_check_chance = 0.5;", // available from C* 3.0
200201 keyspace);
201202
202203 // older versions
@@ -252,6 +253,7 @@
252253 assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128);
253254 assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048);
254255 assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default
256+ assertThat(table.getOptions().getCrcCheckChance()).isEqualTo(0.5);
255257 assertThat(table.asCQLQuery())
256258 .contains("read_repair_chance = 0.5")
257259 .contains("dclocal_read_repair_chance = 0.6")
@@ -268,6 +270,7 @@
268270 .contains("speculative_retry = '99.9PERCENTILE'")
269271 .contains("min_index_interval = 128")
270272 .contains("max_index_interval = 2048")
273+ .contains("crc_check_chance = 0.5")
271274 .doesNotContain(" index_interval")
272275 .doesNotContain("replicate_on_write");
273276