kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | fd581548d2100ee8be013d4465eadfb8c29534391227ebdde9030ab645dfb650 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-17 17:07 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-17 18:23 +02:00 |
| Parents | 8e3e8fb031fa |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +30 −0
| @@ -281,6 +281,9 @@ | ||
| 281 | 281 | and(sb, formatted).append("min_index_interval = ").append(options.minIndexInterval); |
| 282 | 282 | and(sb, formatted).append("max_index_interval = ").append(options.maxIndexInterval); |
| 283 | 283 | } |
| 284 | + if (cassandraVersion.getMajor() > 2) { | |
| 285 | + and(sb, formatted).append("crc_check_chance = ").append(options.crcCheckChance); | |
| 286 | + } | |
| 284 | 287 | sb.append(';'); |
| 285 | 288 | return sb; |
| 286 | 289 | } |
| @@ -365,6 +368,7 @@ | ||
| 365 | 368 | private static final String INDEX_INTERVAL = "index_interval"; |
| 366 | 369 | private static final String MIN_INDEX_INTERVAL = "min_index_interval"; |
| 367 | 370 | private static final String MAX_INDEX_INTERVAL = "max_index_interval"; |
| 371 | + private static final String CRC_CHECK_CHANCE = "crc_check_chance"; | |
| 368 | 372 | |
| 369 | 373 | private static final boolean DEFAULT_REPLICATE_ON_WRITE = true; |
| 370 | 374 | private static final double DEFAULT_BF_FP_CHANCE = 0.01; |
| @@ -375,6 +379,7 @@ | ||
| 375 | 379 | private static final int DEFAULT_INDEX_INTERVAL = 128; |
| 376 | 380 | private static final int DEFAULT_MIN_INDEX_INTERVAL = 128; |
| 377 | 381 | private static final int DEFAULT_MAX_INDEX_INTERVAL = 2048; |
| 382 | + private static final double DEFAULT_CRC_CHECK_CHANCE = 1.0; | |
| 378 | 383 | |
| 379 | 384 | private final boolean isCompactStorage; |
| 380 | 385 | |
| @@ -394,6 +399,7 @@ | ||
| 394 | 399 | private final Integer maxIndexInterval; |
| 395 | 400 | private final Map<String, String> compaction; |
| 396 | 401 | private final Map<String, String> compression; |
| 402 | + private final Double crcCheckChance; | |
| 397 | 403 | |
| 398 | 404 | Options(Row row, boolean isCompactStorage, VersionNumber version) { |
| 399 | 405 | |
| @@ -459,6 +465,13 @@ | ||
| 459 | 465 | this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class)); |
| 460 | 466 | else |
| 461 | 467 | 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; | |
| 462 | 475 | } |
| 463 | 476 | |
| 464 | 477 | private static boolean isNullOrAbsent(Row row, String name) { |
| @@ -625,6 +638,23 @@ | ||
| 625 | 638 | return maxIndexInterval; |
| 626 | 639 | } |
| 627 | 640 | |
| 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 | + | |
| 628 | 658 | /** |
| 629 | 659 | * Returns the compaction options for this table. |
| 630 | 660 | * |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +4 −1
| @@ -196,7 +196,8 @@ | ||
| 196 | 196 | + " AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 10 }\n" |
| 197 | 197 | + " AND comment = 'My awesome table'\n" |
| 198 | 198 | + " 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 | |
| 200 | 201 | keyspace); |
| 201 | 202 | |
| 202 | 203 | // older versions |
| @@ -252,6 +253,7 @@ | ||
| 252 | 253 | assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128); |
| 253 | 254 | assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); |
| 254 | 255 | assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default |
| 256 | + assertThat(table.getOptions().getCrcCheckChance()).isEqualTo(0.5); | |
| 255 | 257 | assertThat(table.asCQLQuery()) |
| 256 | 258 | .contains("read_repair_chance = 0.5") |
| 257 | 259 | .contains("dclocal_read_repair_chance = 0.6") |
| @@ -268,6 +270,7 @@ | ||
| 268 | 270 | .contains("speculative_retry = '99.9PERCENTILE'") |
| 269 | 271 | .contains("min_index_interval = 128") |
| 270 | 272 | .contains("max_index_interval = 2048") |
| 273 | + .contains("crc_check_chance = 0.5") | |
| 271 | 274 | .doesNotContain(" index_interval") |
| 272 | 275 | .doesNotContain("replicate_on_write"); |
| 273 | 276 |