kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | d9c6eca56604527e29b39ae26a3615cf34abf60cf03daaf31b623b07f072e04f |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-10-09 11:18 -05:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-10-12 12:06 +02:00 |
| Parents | ccdf5a93b3d2 |
3 files changed
modified changelog/README.md +2 −1
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | ## Changelog |
| 2 | 2 | |
| 3 | -### 3.0.0-beta1 | |
| 3 | +### 3.0.0-beta1 (in progress) | |
| 4 | 4 | |
| 5 | 5 | - [improvement] Change default consistency level to LOCAL_QUORUM (JAVA-926) |
| 6 | 6 | - [bug] Fix implementation of UserType.hashCode() (JAVA-942) |
| 7 | 7 | - [improvement] Don't delay UP/ADDED notifications if protocol version = V4 (JAVA-877) |
| 8 | +- [improvement] Parse 'extensions' column in table metadata (JAVA-938) | |
| 8 | 9 | |
| 9 | 10 | |
| 10 | 11 | ### 3.0.0-alpha3 |
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +22 −2
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | |
| 19 | +import java.nio.ByteBuffer; | |
| 19 | 20 | import java.util.*; |
| 20 | 21 | |
| 21 | 22 | import com.google.common.base.Objects; |
| @@ -371,6 +372,7 @@ | ||
| 371 | 372 | private static final String MIN_INDEX_INTERVAL = "min_index_interval"; |
| 372 | 373 | private static final String MAX_INDEX_INTERVAL = "max_index_interval"; |
| 373 | 374 | private static final String CRC_CHECK_CHANCE = "crc_check_chance"; |
| 375 | + private static final String EXTENSIONS = "extensions"; | |
| 374 | 376 | |
| 375 | 377 | private static final boolean DEFAULT_REPLICATE_ON_WRITE = true; |
| 376 | 378 | private static final double DEFAULT_BF_FP_CHANCE = 0.01; |
| @@ -402,6 +404,7 @@ | ||
| 402 | 404 | private final Map<String, String> compaction; |
| 403 | 405 | private final Map<String, String> compression; |
| 404 | 406 | private final Double crcCheckChance; |
| 407 | + private final Map<String, ByteBuffer> extensions; | |
| 405 | 408 | |
| 406 | 409 | Options(Row row, boolean isCompactStorage, VersionNumber version) { |
| 407 | 410 | |
| @@ -474,6 +477,11 @@ | ||
| 474 | 477 | : row.getDouble(CRC_CHECK_CHANCE); |
| 475 | 478 | else |
| 476 | 479 | this.crcCheckChance = null; |
| 480 | + | |
| 481 | + if(is300OrHigher) | |
| 482 | + this.extensions = ImmutableMap.copyOf(row.getMap(EXTENSIONS, String.class, ByteBuffer.class)); | |
| 483 | + else | |
| 484 | + this.extensions = ImmutableMap.of(); | |
| 477 | 485 | } |
| 478 | 486 | |
| 479 | 487 | private static boolean isNullOrAbsent(Row row, String name) { |
| @@ -675,6 +683,17 @@ | ||
| 675 | 683 | return compression; |
| 676 | 684 | } |
| 677 | 685 | |
| 686 | + /** | |
| 687 | + * Returns the extension options for this table. | |
| 688 | + * <p> | |
| 689 | + * For Cassandra versions prior to 3.0.0, this method always returns an empty map. | |
| 690 | + * | |
| 691 | + * @return an immutable map containing the extension options for this table. | |
| 692 | + */ | |
| 693 | + public Map<String, ByteBuffer> getExtensions() { | |
| 694 | + return extensions; | |
| 695 | + } | |
| 696 | + | |
| 678 | 697 | @Override |
| 679 | 698 | public boolean equals(Object other) { |
| 680 | 699 | if (other == this) |
| @@ -699,14 +718,15 @@ | ||
| 699 | 718 | Objects.equal(this.minIndexInterval, that.minIndexInterval) && |
| 700 | 719 | Objects.equal(this.maxIndexInterval, that.maxIndexInterval) && |
| 701 | 720 | Objects.equal(this.compaction, that.compaction) && |
| 702 | - Objects.equal(this.compression, that.compression); | |
| 721 | + Objects.equal(this.compression, that.compression) && | |
| 722 | + Objects.equal(this.extensions, that.extensions); | |
| 703 | 723 | } |
| 704 | 724 | |
| 705 | 725 | @Override |
| 706 | 726 | public int hashCode() { |
| 707 | 727 | return Objects.hashCode(isCompactStorage, comment, readRepair, localReadRepair, replicateOnWrite, gcGrace, |
| 708 | 728 | bfFpChance, caching, populateCacheOnFlush, memtableFlushPeriodMs, defaultTTL, speculativeRetry, |
| 709 | - indexInterval, minIndexInterval, maxIndexInterval, compaction, compression); | |
| 729 | + indexInterval, minIndexInterval, maxIndexInterval, compaction, compression, extensions); | |
| 710 | 730 | } |
| 711 | 731 | } |
| 712 | 732 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +39 −0
| @@ -15,9 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import java.nio.ByteBuffer; | |
| 18 | 19 | import java.util.Collection; |
| 19 | 20 | import java.util.Collections; |
| 20 | 21 | |
| 22 | +import com.google.common.collect.ImmutableMap; | |
| 21 | 23 | import org.testng.annotations.Test; |
| 22 | 24 | |
| 23 | 25 | import static org.assertj.core.api.Assertions.entry; |
| @@ -269,6 +271,7 @@ | ||
| 269 | 271 | assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); |
| 270 | 272 | assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default |
| 271 | 273 | assertThat(table.getOptions().getCrcCheckChance()).isEqualTo(0.5); |
| 274 | + assertThat(table.getOptions().getExtensions()).isEmpty(); // default | |
| 272 | 275 | assertThat(table.asCQLQuery()) |
| 273 | 276 | .contains("read_repair_chance = 0.5") |
| 274 | 277 | .contains("dclocal_read_repair_chance = 0.6") |
| @@ -310,6 +313,7 @@ | ||
| 310 | 313 | assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128); |
| 311 | 314 | assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); |
| 312 | 315 | assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default |
| 316 | + assertThat(table.getOptions().getExtensions()).isEmpty(); | |
| 313 | 317 | assertThat(table.asCQLQuery()) |
| 314 | 318 | .contains("read_repair_chance = 0.5") |
| 315 | 319 | .contains("dclocal_read_repair_chance = 0.6") |
| @@ -349,6 +353,7 @@ | ||
| 349 | 353 | assertThat(table.getOptions().getMinIndexInterval()).isNull(); |
| 350 | 354 | assertThat(table.getOptions().getMaxIndexInterval()).isNull(); |
| 351 | 355 | assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // explicitly set |
| 356 | + assertThat(table.getOptions().getExtensions()).isEmpty(); | |
| 352 | 357 | assertThat(table.asCQLQuery()) |
| 353 | 358 | .contains("read_repair_chance = 0.5") |
| 354 | 359 | .contains("dclocal_read_repair_chance = 0.6") |
| @@ -387,6 +392,7 @@ | ||
| 387 | 392 | assertThat(table.getOptions().getMinIndexInterval()).isNull(); |
| 388 | 393 | assertThat(table.getOptions().getMaxIndexInterval()).isNull(); |
| 389 | 394 | assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // explicitly set |
| 395 | + assertThat(table.getOptions().getExtensions()).isEmpty(); | |
| 390 | 396 | assertThat(table.asCQLQuery()) |
| 391 | 397 | .contains("read_repair_chance = 0.5") |
| 392 | 398 | .contains("dclocal_read_repair_chance = 0.6") |
| @@ -474,4 +480,37 @@ | ||
| 474 | 480 | assertThat(table_cd.getIndexes().size()).isEqualTo(1); |
| 475 | 481 | assertThat(table_cd.getIndexes().get(0).getName()).isEqualTo("test_d"); |
| 476 | 482 | } |
| 483 | + | |
| 484 | + /** | |
| 485 | + * Validates that the 'extensions' option is properly parsed when set on a table. | |
| 486 | + * This value is currently not modifiable via CQL so we fake out a table containing | |
| 487 | + * populated extensions by updating the extensions column in system_schema.tables | |
| 488 | + * and forcing a schema refresh on it. | |
| 489 | + * | |
| 490 | + * @jira_ticket JAVA-938, CASSANDRA-9426 | |
| 491 | + * @test_category metadata | |
| 492 | + */ | |
| 493 | + @Test(groups = "short") | |
| 494 | + @CassandraVersion(major=3.0) | |
| 495 | + public void should_parse_extensions_from_table_options() throws Exception { | |
| 496 | + // given | |
| 497 | + // create a simple table and retrieve it's metadata from system_schema.tables. | |
| 498 | + String cql = String.format("CREATE TABLE %s.table_with_extensions (\n" | |
| 499 | + + " k text,\n" | |
| 500 | + + " c int,\n" | |
| 501 | + + " v timeuuid,\n" | |
| 502 | + + " PRIMARY KEY (k, c)\n" | |
| 503 | + + ");", keyspace); | |
| 504 | + session.execute(cql); | |
| 505 | + | |
| 506 | + // Manually change column value in system_schema.tables and force a schema refresh on that table. | |
| 507 | + ImmutableMap<String, ByteBuffer> extensions = ImmutableMap.of("Hello", ByteBuffer.wrap("World".getBytes("UTF-8"))); | |
| 508 | + session.execute("update system_schema.tables set extensions=? where keyspace_name=? and table_name=?", extensions, keyspace, "table_with_extensions"); | |
| 509 | + cluster.manager.controlConnection.refreshSchema(SchemaElement.TABLE, keyspace, "table_with_extensions", null); | |
| 510 | + | |
| 511 | + // when retrieving the table's metadata. | |
| 512 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("table_with_extensions"); | |
| 513 | + // then the table's options should contain populated extensions. | |
| 514 | + assertThat(table.getOptions().getExtensions()).isEqualTo(extensions); | |
| 515 | + } | |
| 477 | 516 | } |