forked from apache/cassandra-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces 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 PreparedStatement or 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
19 changed files
with
919 additions
and
13 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
core/src/main/java/com/datastax/oss/driver/api/core/metadata/HostShardPair.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,30 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Simple class to hold UUID of a host and a shard number. Class itself makes no checks or | ||
* guarantees about existence of a shard on corresponding host. | ||
*/ | ||
public class HostShardPair { | ||
private final UUID host; | ||
private final int shard; | ||
|
||
public HostShardPair(UUID host, int shard) { | ||
this.host = host; | ||
this.shard = shard; | ||
} | ||
|
||
public UUID getHost() { | ||
return host; | ||
} | ||
|
||
public int getShard() { | ||
return shard; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HostShardPair{" + "host=" + host + ", shard=" + shard + '}'; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import java.util.Objects; | ||
|
||
/** Simple keyspace name and table name pair. */ | ||
public class KeyspaceTableNamePair { | ||
private final String keyspace; | ||
private final String tableName; | ||
|
||
public KeyspaceTableNamePair(String keyspace, String tableName) { | ||
this.keyspace = keyspace; | ||
this.tableName = tableName; | ||
} | ||
|
||
public String getKeyspace() { | ||
return keyspace; | ||
} | ||
|
||
public String 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
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
/** Represents a tablet as described in tablets-routing-v1 protocol extension. */ | ||
public interface Tablet extends Comparable<Tablet> { | ||
public String getKeyspaceName(); | ||
|
||
public UUID getTableId(); | ||
|
||
public String getTableName(); | ||
|
||
public long getFirstToken(); | ||
|
||
public long getLastToken(); | ||
|
||
public Set<HostShardPair> getReplicas(); | ||
} |
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
package com.datastax.oss.driver.api.core.metadata; | ||
|
||
import com.datastax.oss.driver.api.core.data.TupleValue; | ||
import java.util.Map; | ||
import java.util.NavigableSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
/** Holds all currently known tablet metadata. */ | ||
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 Map<KeyspaceTableNamePair, NavigableSet<Tablet>> getMapping(); | ||
|
||
/** | ||
* Adds a singular tablet to the map. Provided tuple has to match format described for | ||
* tablets-routing-v1 described in Scylla protocol extensions. | ||
* | ||
* @param keyspace tablet's keyspace | ||
* @param table tablet's table | ||
* @param tupleValue tablet | ||
*/ | ||
public void addTablet(String keyspace, String table, TupleValue tupleValue); | ||
|
||
/** | ||
* Returns replicas holding tablets for given token. Because TabletMap holds only UUIDs of nodes a | ||
* current mapping from UUID to actual Node instances is needed. If a mapping for the specific | ||
* UUID is missing then such Node won't be included in the returned set. | ||
* | ||
* @param keyspace tablet's keyspace | ||
* @param table tablet's table | ||
* @param token target token | ||
* @param nodes current UUID to Node mapping | ||
* @return Set of {@link Node} that holds target tablets. | ||
*/ | ||
public Set<Node> getReplicas(String keyspace, String table, long token, Map<UUID, Node> nodes); | ||
} |
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.