dcapwell commented on a change in pull request #31:
URL:
https://github.com/apache/cassandra-in-jvm-dtest-api/pull/31#discussion_r798007635
##########
File path: src/main/java/org/apache/cassandra/distributed/api/TokenSupplier.java
##########
@@ -18,17 +18,41 @@
package org.apache.cassandra.distributed.api;
+import java.util.Arrays;
+import java.util.Collection;
+
public interface TokenSupplier
{
- long token(int nodeId);
+ Collection<String> tokens(int nodeId);
+
+ @Deprecated
+ default long token(int nodeId)
+ {
+ Collection<String> tokens = tokens(nodeId);
+ assert tokens.size() == 1: "tokens function returned multiple tokens,
only expected 1: " + tokens;
+ return Long.parseLong(tokens.stream().findFirst().get());
+ }
+ @Deprecated
static TokenSupplier evenlyDistributedTokens(int numNodes)
{
- long increment = (Long.MAX_VALUE / numNodes) * 2;
- return (int nodeId) -> {
- assert nodeId <= numNodes : String.format("Can not allocate a
token for a node %s, since only %s nodes are allowed by the token allocation
strategy",
- nodeId, numNodes);
- return Long.MIN_VALUE + 1 + nodeId * increment;
- };
+ return evenlyDistributedTokens(numNodes, 1);
+ }
+
+ static TokenSupplier evenlyDistributedTokens(int numNodes, int numTokens)
+ {
+ long increment = (Long.MAX_VALUE / (numNodes * numTokens)) * 2;
+ String[][] tokens = new String[numNodes][numTokens];
+
+ long value = Long.MIN_VALUE + 1;
+ for (int i = 0; i < numTokens; i++)
+ {
+ for (int nodeId = 1; nodeId <= numNodes; nodeId++)
+ {
+ value += nodeId + increment;
Review comment:
good catch, missed that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]