aweisberg commented on code in PR #3777:
URL: https://github.com/apache/cassandra/pull/3777#discussion_r1917276807


##########
src/java/org/apache/cassandra/service/accord/txn/TxnNamedRead.java:
##########
@@ -59,34 +84,88 @@ public class TxnNamedRead extends 
AbstractSerialized<ReadCommand>
     @SuppressWarnings("unused")
     private static final Logger logger = 
LoggerFactory.getLogger(TxnNamedRead.class);
 
-    private static final long EMPTY_SIZE = ObjectSizes.measure(new 
TxnNamedRead(0, null, null));
+    private static final long EMPTY_SIZE = ObjectSizes.measure(new 
TxnNamedRead(0, Keys.of(), (ByteBuffer) null));
 
     private final int name;
-    private final PartitionKey key;
+    private final Seekables<?, ?> keys;
 
     public TxnNamedRead(int name, @Nullable SinglePartitionReadCommand value)
     {
         super(value);
         this.name = name;
-        this.key = new PartitionKey(value.metadata().id, value.partitionKey());
+        this.keys = Keys.of(new PartitionKey(value.metadata().id, 
value.partitionKey()));
     }
 
-    public TxnNamedRead(int name, PartitionKey key, ByteBuffer bytes)
+    public static TokenRange 
boundsAsAccordRange(AbstractBounds<PartitionPosition> range, TableId tableId)
+    {
+        // Should already have been unwrapped
+        checkState(!AbstractBounds.strictlyWrapsAround(range.left, 
range.right));
+
+        // Read commands can contain a mix of different kinds of bounds to 
facilitate paging
+        // and we need to communicate that to Accord as its own ranges. This 
uses
+        // TokenKey, SentinelKey, and MinTokenKey and sticks exclusively with 
left exclusive/right inclusive
+        // ranges rather add more types of ranges to the mix
+        // MinTokenKey allows emulating inclusive left and exclusive right 
with Range
+        boolean inclusiveLeft = range.inclusiveLeft();
+        PartitionPosition startPP = range.left;
+        boolean startIsMinKeyBound = startPP.getClass() == KeyBound.class ? 
((KeyBound)startPP).isMinimumBound : false;
+        Token startToken = startPP.getToken();
+        AccordRoutingKey startAccordRoutingKey;
+        if (startToken.isMinimum() && inclusiveLeft)
+            startAccordRoutingKey = SentinelKey.min(tableId);
+        else if (inclusiveLeft || startIsMinKeyBound)
+            startAccordRoutingKey = new MinTokenKey(tableId, startToken);
+        else
+            startAccordRoutingKey = new TokenKey(tableId, startToken);
+
+        boolean inclusiveRight = range.inclusiveRight();
+        PartitionPosition endPP = range.right;
+        boolean endIsMinKeyBound = endPP.getClass() == KeyBound.class ? 
((KeyBound)endPP).isMinimumBound : false;
+        Token stopToken = range.right.getToken();
+        AccordRoutingKey stopAccordRoutingKey;
+        if (stopToken.isMinimum())
+            stopAccordRoutingKey = SentinelKey.max(tableId);
+        else if (inclusiveRight && !endIsMinKeyBound)
+            stopAccordRoutingKey = new TokenKey(tableId, stopToken);
+        else
+            stopAccordRoutingKey = new MinTokenKey(tableId, stopToken);
+        return TokenRange.create(startAccordRoutingKey, stopAccordRoutingKey);
+    }
+
+    public TxnNamedRead(int name, List<AbstractBounds<PartitionPosition>> 
ranges, PartitionRangeReadCommand value)

Review Comment:
   I'll convert to `Seekable` I think it was a mistake merging `TxnRangeRead` 
into `TxnNamedRead`.



-- 
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]

Reply via email to