diff --git a/modules/accord b/modules/accord index eedd13ac4b..dd04c81214 160000 --- a/modules/accord +++ b/modules/accord @@ -1 +1 @@ -Subproject commit eedd13ac4b7b9f61d574badb4bfc47611a838739 +Subproject commit dd04c81214be9213cf503025bf6ed4cbf118be00 diff --git a/src/java/org/apache/cassandra/db/DecoratedKey.java b/src/java/org/apache/cassandra/db/DecoratedKey.java index 03d6374112..7dd709f088 100644 --- a/src/java/org/apache/cassandra/db/DecoratedKey.java +++ b/src/java/org/apache/cassandra/db/DecoratedKey.java @@ -97,7 +97,7 @@ public abstract class DecoratedKey implements PartitionPosition, FilterKey return -position.compareTo(partitioner.decorateKey(key)); DecoratedKey otherKey = (DecoratedKey) position; - int cmp = partitioner.getToken(key).compareTo(otherKey.getToken()); + int cmp = partitioner.compareToken(key, otherKey.getToken()); return cmp == 0 ? ByteBufferUtil.compareUnsigned(key, otherKey.getKey()) : cmp; } diff --git a/src/java/org/apache/cassandra/dht/IPartitioner.java b/src/java/org/apache/cassandra/dht/IPartitioner.java index 0c4ae9dbb3..8e30ba6500 100644 --- a/src/java/org/apache/cassandra/dht/IPartitioner.java +++ b/src/java/org/apache/cassandra/dht/IPartitioner.java @@ -91,6 +91,16 @@ public interface IPartitioner */ public Token getToken(ByteBuffer key); + /** + * @return a Token that can be used to route a given key + * (This is NOT a method to create a Token from its string representation; + * for that, use TokenFactory.fromString.) + */ + default int compareToken(ByteBuffer key, Token token) + { + return getToken(key).compareTo(token); + } + /** * @return a randomly generated token */ diff --git a/src/java/org/apache/cassandra/dht/LocalPartitioner.java b/src/java/org/apache/cassandra/dht/LocalPartitioner.java index 0a1ede356b..2f060c6b67 100644 --- a/src/java/org/apache/cassandra/dht/LocalPartitioner.java +++ b/src/java/org/apache/cassandra/dht/LocalPartitioner.java @@ -72,6 +72,11 @@ public class LocalPartitioner implements IPartitioner return new LocalToken(key); } + public int compareToken(ByteBuffer key, Token token) + { + return comparator.compare(key, ((LocalToken)token).token); + } + public LocalToken getRandomToken() { throw new UnsupportedOperationException(); diff --git a/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java b/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java index f339bd9f7a..d44bd7f714 100644 --- a/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/format/big/BigTableReader.java @@ -311,6 +311,7 @@ public class BigTableReader extends SSTableReaderWithFilter implements IndexSumm // of the next interval). int i = 0; String path = null; + ByteBuffer indexKey = null; try (FileDataInput in = ifile.createReader(sampledPosition)) { path = in.getPath(); @@ -318,7 +319,13 @@ public class BigTableReader extends SSTableReaderWithFilter implements IndexSumm { i++; - ByteBuffer indexKey = ByteBufferUtil.readWithShortLength(in); + int length = in.readUnsignedShort(); + if (indexKey == null || indexKey.capacity() < length) + indexKey = ByteBuffer.allocate(length); + + in.readFully(indexKey.array(), 0, length); + indexKey.position(0); + indexKey.limit(length); boolean opSatisfied; // did we find an appropriate position for the op requested boolean exactMatch; // is the current position an exact match for the key, suitable for caching diff --git a/src/java/org/apache/cassandra/service/accord/CommandsForRangesLoader.java b/src/java/org/apache/cassandra/service/accord/CommandsForRangesLoader.java index dca807e171..45f69e67f1 100644 --- a/src/java/org/apache/cassandra/service/accord/CommandsForRangesLoader.java +++ b/src/java/org/apache/cassandra/service/accord/CommandsForRangesLoader.java @@ -35,7 +35,6 @@ import accord.local.Command; import accord.local.KeyHistory; import accord.local.RedundantBefore; import accord.primitives.PartialDeps; -import accord.primitives.Participants; import accord.primitives.Routable.Domain; import accord.primitives.SaveStatus; import accord.primitives.Status; @@ -252,7 +251,7 @@ public class CommandsForRangesLoader implements AccordStateCache.Listener keysOrRanges = cmd.participants().touches(); + Ranges keysOrRanges = cmd.participants().touches().toRanges(); if (keysOrRanges.domain() != Domain.Range) throw new AssertionError(String.format("Txn keys are not range for %s", cmd.partialTxn())); Ranges ranges = (Ranges) keysOrRanges; @@ -276,7 +275,7 @@ public class CommandsForRangesLoader implements AccordStateCache.Listener