dcapwell commented on code in PR #3481:
URL: https://github.com/apache/cassandra/pull/3481#discussion_r1724288916


##########
src/java/org/apache/cassandra/db/virtual/AccordVirtualTables.java:
##########
@@ -246,6 +257,96 @@ public DataSet data()
         }
     }
 
+    public static class TxnStateTable extends AbstractVirtualTable
+    {
+        private final UserType partitionKeyType;
+        private final UserType cfkType;
+
+        protected TxnStateTable(String keyspace)
+        {
+            super(TableMetadata.builder(keyspace, "txn_state")
+                               .kind(TableMetadata.Kind.VIRTUAL)
+                               .addPartitionKeyColumn("txn_id", 
UTF8Type.instance)
+                               .addClusteringColumn("shard", 
Int32Type.instance)
+                               .addRegularColumn("save_status", 
UTF8Type.instance)
+                               .addRegularColumn("waiting_on_txns", 
MapType.getInstance(UTF8Type.instance, UTF8Type.instance, false))
+                               .addRegularColumn("waiting_on_keys", 
MapType.getInstance(pkType(keyspace), cfkType(keyspace), false))
+                               .build());
+            partitionKeyType = pkType(keyspace);
+            cfkType = cfkType(keyspace);
+        }
+
+        private static UserType pkType(String keyspace)
+        {
+            return new UserType(keyspace, bytes("partition_key"),
+                                
Arrays.asList(FieldIdentifier.forQuoted("table"), 
FieldIdentifier.forQuoted("token")),
+                                Arrays.asList(UTF8Type.instance, 
UTF8Type.instance), false);
+        }
+
+        private ByteBuffer pk(PartitionKey pk)
+        {
+            var tm = Schema.instance.getTableMetadata(pk.table());
+            return 
partitionKeyType.pack(UTF8Type.instance.decompose(tm.toString()),
+                                         
UTF8Type.instance.decompose(pk.token().toString()));
+        }
+
+        private static UserType cfkType(String keyspace)
+        {
+            return new UserType(keyspace, bytes("commands_for_key"),
+                                
Arrays.asList(FieldIdentifier.forQuoted("next_to_apply"), 
FieldIdentifier.forQuoted("min_undecided")),
+                                Arrays.asList(UTF8Type.instance, 
UTF8Type.instance), false);
+        }
+
+        private ByteBuffer cfk(TxnState.CommandsForKeyState cfk)
+        {
+            if (cfk == null) return ByteBufferUtil.EMPTY_BYTE_BUFFER;
+            return cfkType.pack(cfk.nextWaitingToApply == null ? 
ByteBufferUtil.EMPTY_BYTE_BUFFER : 
UTF8Type.instance.decompose(cfk.nextWaitingToApply.toString()),
+                                cfk.minUndecided == null ? 
ByteBufferUtil.EMPTY_BYTE_BUFFER : 
UTF8Type.instance.decompose(cfk.minUndecided.plainTxnId().toString()));
+        }
+
+        @Override
+        public Iterable<UserType> userTypes()
+        {
+            return Arrays.asList(partitionKeyType, cfkType);
+        }
+
+        @Override
+        public DataSet data(DecoratedKey partitionKey)

Review Comment:
   we spoke in slack, each txn now has its own row



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