kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a18d9fe5715a8219f9e94a9abab8c0b257f1d59e9092c5f2cbfd1a4b3a613200 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-09-18 14:36 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-09-18 14:36 -05:00 |
| Parents | 2521b15bf39d, fd581548d210 |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +30 −0
| @@ -283,6 +283,9 @@ | ||
| 283 | 283 | and(sb, formatted).append("min_index_interval = ").append(options.minIndexInterval); |
| 284 | 284 | and(sb, formatted).append("max_index_interval = ").append(options.maxIndexInterval); |
| 285 | 285 | } |
| 286 | + if (cassandraVersion.getMajor() > 2) { | |
| 287 | + and(sb, formatted).append("crc_check_chance = ").append(options.crcCheckChance); | |
| 288 | + } | |
| 286 | 289 | sb.append(';'); |
| 287 | 290 | return sb; |
| 288 | 291 | } |
| @@ -367,6 +370,7 @@ | ||
| 367 | 370 | private static final String INDEX_INTERVAL = "index_interval"; |
| 368 | 371 | private static final String MIN_INDEX_INTERVAL = "min_index_interval"; |
| 369 | 372 | private static final String MAX_INDEX_INTERVAL = "max_index_interval"; |
| 373 | + private static final String CRC_CHECK_CHANCE = "crc_check_chance"; | |
| 370 | 374 | |
| 371 | 375 | private static final boolean DEFAULT_REPLICATE_ON_WRITE = true; |
| 372 | 376 | private static final double DEFAULT_BF_FP_CHANCE = 0.01; |
| @@ -377,6 +381,7 @@ | ||
| 377 | 381 | private static final int DEFAULT_INDEX_INTERVAL = 128; |
| 378 | 382 | private static final int DEFAULT_MIN_INDEX_INTERVAL = 128; |
| 379 | 383 | private static final int DEFAULT_MAX_INDEX_INTERVAL = 2048; |
| 384 | + private static final double DEFAULT_CRC_CHECK_CHANCE = 1.0; | |
| 380 | 385 | |
| 381 | 386 | private final boolean isCompactStorage; |
| 382 | 387 | |
| @@ -396,6 +401,7 @@ | ||
| 396 | 401 | private final Integer maxIndexInterval; |
| 397 | 402 | private final Map<String, String> compaction; |
| 398 | 403 | private final Map<String, String> compression; |
| 404 | + private final Double crcCheckChance; | |
| 399 | 405 | |
| 400 | 406 | Options(Row row, boolean isCompactStorage, VersionNumber version) { |
| 401 | 407 | |
| @@ -461,6 +467,13 @@ | ||
| 461 | 467 | this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class)); |
| 462 | 468 | else |
| 463 | 469 | 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; | |
| 464 | 477 | } |
| 465 | 478 | |
| 466 | 479 | private static boolean isNullOrAbsent(Row row, String name) { |
| @@ -627,6 +640,23 @@ | ||
| 627 | 640 | return maxIndexInterval; |
| 628 | 641 | } |
| 629 | 642 | |
| 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 | + | |
| 630 | 660 | /** |
| 631 | 661 | * Returns the compaction options for this table. |
| 632 | 662 | * |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +4 −1
| @@ -211,7 +211,8 @@ | ||
| 211 | 211 | + " AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 10 }\n" |
| 212 | 212 | + " AND comment = 'My awesome table'\n" |
| 213 | 213 | + " 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 | |
| 215 | 216 | keyspace); |
| 216 | 217 | |
| 217 | 218 | // older versions |
| @@ -267,6 +268,7 @@ | ||
| 267 | 268 | assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128); |
| 268 | 269 | assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); |
| 269 | 270 | assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default |
| 271 | + assertThat(table.getOptions().getCrcCheckChance()).isEqualTo(0.5); | |
| 270 | 272 | assertThat(table.asCQLQuery()) |
| 271 | 273 | .contains("read_repair_chance = 0.5") |
| 272 | 274 | .contains("dclocal_read_repair_chance = 0.6") |
| @@ -283,6 +285,7 @@ | ||
| 283 | 285 | .contains("speculative_retry = '99.9PERCENTILE'") |
| 284 | 286 | .contains("min_index_interval = 128") |
| 285 | 287 | .contains("max_index_interval = 2048") |
| 288 | + .contains("crc_check_chance = 0.5") | |
| 286 | 289 | .doesNotContain(" index_interval") |
| 287 | 290 | .doesNotContain("replicate_on_write"); |
| 288 | 291 |