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


##########
src/java/org/apache/cassandra/service/accord/txn/TxnData.java:
##########
@@ -40,18 +41,77 @@
  * Fairly generic holder for result values for Accord txns as well as data 
exchange during Accord txn execution
  * when read results are returned to the coordinator to compute query results 
and writes.
  */
-public class TxnData extends HashMap<TxnDataName, TxnDataValue> implements 
TxnResult, Data
+public class TxnData extends Int2ObjectHashMap<TxnDataValue> implements 
TxnResult, Data
 {
     private static final long EMPTY_SIZE = ObjectSizes.measure(new TxnData());
 
+    private static final int TXN_DATA_NAME_INDEX_BITS = 32 - 6;
+    private static final int TXN_DATA_NAME_INDEX_MASK = ~(~0 << 
TXN_DATA_NAME_INDEX_BITS);
+    public static final int TXN_DATA_NAME_INDEX_MAX = ((1 << 
TXN_DATA_NAME_INDEX_BITS) - 1);
+
+    public enum TxnDataNameKind
+    {
+        USER((byte) 0),
+        RETURNING((byte) 1),
+        AUTO_READ((byte) 2),
+        CAS_READ((byte) 3);
+
+        private final byte value;
+
+        TxnDataNameKind(byte value)
+        {
+            this.value = value;
+        }
+
+        public static TxnDataNameKind from(byte b)
+        {
+            switch (b)
+            {
+                case 0:
+                    return USER;
+                case 1:
+                    return RETURNING;
+                case 2:
+                    return AUTO_READ;
+                case 3:
+                    return CAS_READ;
+                default:
+                    throw new IllegalArgumentException("Unknown kind: " + b);
+            }
+        }
+    }
+
+    public static int txnDataName(TxnDataNameKind kind, int index)
+    {
+        checkArgument(index >= 0 && index <= TXN_DATA_NAME_INDEX_MAX);
+        int kindInt = (int)(((long)kind.value) << TXN_DATA_NAME_INDEX_BITS);
+        return kindInt | index;
+    }
+
+    public static int txnDataName(TxnDataNameKind kind)
+    {
+        return txnDataName(kind, 0);
+    }
+
+    public static TxnDataNameKind txnDataNameKind(int txnDataName)
+    {
+        int kind = txnDataName >> TXN_DATA_NAME_INDEX_BITS;

Review Comment:
   Oh that's a genuine mistake/bug. I forgot which shift was which. We don't 
want signed shift because it would result in the wrong value in kind if it 
extended a 1.



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to