forked from apache/cassandra-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces basic tablets support for version 4.x of the driver. Metadata about tablets will be kept in TabletMap that gets continuously updated through the tablets-routing-v1 extension. Each time the BoundStatement targets the wrong node and shard combination the server supporting tablets should respond with tablet metadata inside custom payload of its response. This metadata will be transparently processed and used for future queries. Tablets metadata will by enabled by default. Until now driver was using TokenMaps to choose replicas and appropriate shards. Having a token was enough information to do that. Now driver will first attempt tablet-based lookup and only after failing to find corresponding tablet it will defer to TokenMap lookup. Since to find a correct tablet besides the token we need the keyspace and table names, many of the methods were extended to also accept those as parameters. RequestHandlerTestHarness was adjusted to mock also MetadataManager. Before it used to mock only `session.getMetadata()` call but the same can be obtained by `context.getMetadataManager().getMetadata()`. Using the second method was causing test failures.
- Loading branch information
Showing
21 changed files
with
967 additions
and
18 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
core/src/main/java/com/datastax/oss/driver/api/core/metadata/KeyspaceTableNamePair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import com.datastax.oss.driver.api.core.CqlIdentifier; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.Objects; | ||
|
||
/** Simple keyspace name and table name pair. */ | ||
public class KeyspaceTableNamePair { | ||
@NonNull private final CqlIdentifier keyspace; | ||
@NonNull private final CqlIdentifier tableName; | ||
|
||
public KeyspaceTableNamePair(@NonNull CqlIdentifier keyspace, @NonNull CqlIdentifier tableName) { | ||
this.keyspace = keyspace; | ||
this.tableName = tableName; | ||
} | ||
|
||
@NonNull | ||
public CqlIdentifier getKeyspace() { | ||
return keyspace; | ||
} | ||
|
||
@NonNull | ||
public CqlIdentifier getTableName() { | ||
return tableName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "KeyspaceTableNamePair{" | ||
+ "keyspace='" | ||
+ keyspace | ||
+ '\'' | ||
+ ", tableName='" | ||
+ tableName | ||
+ '\'' | ||
+ '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || !(o instanceof KeyspaceTableNamePair)) return false; | ||
KeyspaceTableNamePair that = (KeyspaceTableNamePair) o; | ||
return keyspace.equals(that.keyspace) && tableName.equals(that.tableName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(keyspace, tableName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/datastax/oss/driver/api/core/metadata/Tablet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import com.datastax.oss.driver.shaded.guava.common.annotations.Beta; | ||
import java.util.Set; | ||
|
||
/** | ||
* Represents a tablet as described in tablets-routing-v1 protocol extension with some additional | ||
* fields for ease of use. | ||
*/ | ||
@Beta | ||
public interface Tablet extends Comparable<Tablet> { | ||
/** | ||
* Returns left endpoint of an interval. This interval is left-open, meaning the tablet does not | ||
* own the token equal to the first token. | ||
* | ||
* @return {@code long} value representing first token. | ||
*/ | ||
public long getFirstToken(); | ||
|
||
/** | ||
* Returns right endpoint of an interval. This interval is right-closed, which means that last | ||
* token is owned by this tablet. | ||
* | ||
* @return {@code long} value representing last token. | ||
*/ | ||
public long getLastToken(); | ||
|
||
public Set<Node> getReplicaNodes(); | ||
|
||
/** | ||
* Looks up the shard number for specific replica Node. | ||
* | ||
* @param node one of the replica nodes of this tablet. | ||
* @return Shard number for the replica or -1 if no such Node found. | ||
*/ | ||
public int getShardForNode(Node node); | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/datastax/oss/driver/api/core/metadata/TabletMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import com.datastax.oss.driver.api.core.CqlIdentifier; | ||
import com.datastax.oss.driver.shaded.guava.common.annotations.Beta; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.concurrent.ConcurrentSkipListSet; | ||
|
||
/** Holds all currently known tablet metadata. */ | ||
@Beta | ||
public interface TabletMap { | ||
/** | ||
* Returns mapping from tables to the sets of their tablets. | ||
* | ||
* @return the Map keyed by (keyspace,table) pairs with Set of tablets as value type. | ||
*/ | ||
public ConcurrentMap<KeyspaceTableNamePair, ConcurrentSkipListSet<Tablet>> getMapping(); | ||
|
||
/** | ||
* Adds a single tablet to the map. Handles removal of overlapping tablets. | ||
* | ||
* @param keyspace target keyspace | ||
* @param table target table | ||
* @param tablet tablet instance to add | ||
*/ | ||
public void addTablet(CqlIdentifier keyspace, CqlIdentifier table, Tablet tablet); | ||
|
||
/** | ||
* Returns {@link Tablet} instance | ||
* | ||
* @param keyspace tablet's keyspace | ||
* @param table tablet's table | ||
* @param token target token | ||
* @return {@link Tablet} responsible for provided token or {@code null} if no such tablet is | ||
* present. | ||
*/ | ||
public Tablet getTablet(CqlIdentifier keyspace, CqlIdentifier table, long token); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.