forked from apache/cassandra-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce support for tablets [3.x] #237
Merged
avelanarius
merged 1 commit into
scylladb:scylla-3.x
from
Bouncheck:scylla-3.x-tablets-3
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,11 +110,22 @@ private Iterator<Host> getReplicas( | |
} | ||
|
||
Token.Factory partitioner = statement.getPartitioner(); | ||
String tableName = null; | ||
ColumnDefinitions defs = null; | ||
if (statement instanceof BoundStatement) { | ||
defs = ((BoundStatement) statement).preparedStatement().getVariables(); | ||
} else if (statement instanceof PreparedStatement) { | ||
defs = ((PreparedStatement) statement).getVariables(); | ||
} | ||
if (defs != null && defs.size() > 0) { | ||
tableName = defs.getTable(0); | ||
} | ||
|
||
final Set<Host> replicas = | ||
manager | ||
.cluster | ||
.getMetadata() | ||
.getReplicas(Metadata.quote(keyspace), partitioner, partitionKey); | ||
.getReplicas(Metadata.quote(keyspace), tableName, partitioner, partitionKey); | ||
|
||
// replicas are stored in the right order starting with the primary replica | ||
return replicas.iterator(); | ||
|
@@ -437,13 +448,28 @@ private boolean query(final Host host) { | |
ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry); | ||
|
||
PoolingOptions poolingOptions = manager.configuration().getPoolingOptions(); | ||
String statementKeyspace = statement.getKeyspace(); | ||
String statementTable = null; | ||
ColumnDefinitions defs = null; | ||
if (statement instanceof PreparedStatement) { | ||
defs = ((PreparedStatement) statement).getVariables(); | ||
} | ||
if (statement instanceof BoundStatement) { | ||
defs = ((BoundStatement) statement).statement.getVariables(); | ||
} | ||
if (defs != null && defs.size() > 0) { | ||
statementTable = defs.getTable(0); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could capture the tablet map during prepare time and put it into statement itself, avoiding all the casting and checks here. Probably negligible in terms of performance. |
||
ListenableFuture<Connection> connectionFuture = | ||
pool.borrowConnection( | ||
poolingOptions.getPoolTimeoutMillis(), | ||
TimeUnit.MILLISECONDS, | ||
poolingOptions.getMaxQueueSize(), | ||
statement.getPartitioner(), | ||
routingKey); | ||
routingKey, | ||
statementKeyspace, | ||
statementTable); | ||
GuavaCompatibility.INSTANCE.addCallback( | ||
connectionFuture, | ||
new FutureCallback<Connection>() { | ||
|
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
33 changes: 33 additions & 0 deletions
33
driver-core/src/main/java/com/datastax/driver/core/TabletInfo.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,33 @@ | ||
package com.datastax.driver.core; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TabletInfo { | ||
private static final String SCYLLA_TABLETS_STARTUP_OPTION_KEY = "TABLETS_ROUTING_V1"; | ||
private static final String SCYLLA_TABLETS_STARTUP_OPTION_VALUE = ""; | ||
public static final String TABLETS_ROUTING_V1_CUSTOM_PAYLOAD_KEY = "tablets-routing-v1"; | ||
|
||
private boolean enabled = false; | ||
|
||
private TabletInfo(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
// Currently pertains only to TABLETS_ROUTING_V1 | ||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public static TabletInfo parseTabletInfo(Map<String, List<String>> supported) { | ||
List<String> values = supported.get(SCYLLA_TABLETS_STARTUP_OPTION_KEY); | ||
return new TabletInfo( | ||
values != null | ||
&& values.size() == 1 | ||
&& values.get(0).equals(SCYLLA_TABLETS_STARTUP_OPTION_VALUE)); | ||
} | ||
|
||
public static void addOption(Map<String, String> options) { | ||
options.put(SCYLLA_TABLETS_STARTUP_OPTION_KEY, SCYLLA_TABLETS_STARTUP_OPTION_VALUE); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add protection here against too-large shardId.
Scenario:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed 'this' to min(shardCount, 'this')