belliottsmith commented on code in PR #4225:
URL: https://github.com/apache/cassandra/pull/4225#discussion_r2184541532


##########
src/java/org/apache/cassandra/db/virtual/AccordDebugKeyspace.java:
##########
@@ -577,6 +603,354 @@ public DataSet data()
         }
     }
 
+    public static final class TxnTraceTable extends AbstractMutableVirtualTable
+    {
+        private TxnTraceTable()
+        {
+            super(parse(VIRTUAL_ACCORD_DEBUG, TXN_TRACE,
+                        "Accord Transaction Trace Configuration",
+                        "CREATE TABLE %s (\n" +
+                        "  txn_id text,\n" +
+                        "  event_type text,\n" +
+                        "  permits int,\n" +
+                        "  PRIMARY KEY (txn_id, event_type)" +
+                        ')', UTF8Type.instance));
+        }
+
+        @Override
+        public DataSet data()
+        {
+            AccordTracing tracing = 
((AccordAgent)AccordService.instance().agent()).tracing();
+            SimpleDataSet dataSet = new SimpleDataSet(metadata());
+            tracing.forEach(id -> true, (txnId, eventType, permits, events) -> 
{
+                events.forEach(e -> {
+                    dataSet.row(txnId.toString(), eventType).column("permits", 
permits);
+                });
+            });
+            return dataSet;
+        }
+
+        private AccordTracing tracing()
+        {
+            return ((AccordAgent)AccordService.instance().agent()).tracing();
+        }
+
+        @Override
+        protected void applyPartitionDeletion(ColumnValues partitionKey)
+        {
+            TxnId txnId = TxnId.parse(partitionKey.value(0));
+            tracing().erasePermits(txnId);
+        }
+
+        @Override
+        protected void applyRangeTombstone(ColumnValues partitionKey, 
Range<ColumnValues> range)
+        {
+            TxnId txnId = TxnId.parse(partitionKey.value(0));
+            if (!range.hasLowerBound() || range.lowerBoundType() != 
BoundType.CLOSED) throw invalidRequest("May restrict deletion by at most one 
event_type");
+            if (!range.hasUpperBound() || (range.upperBoundType() != 
BoundType.CLOSED)) throw invalidRequest("Range deletion must specify one 
event_type");
+            if (range.lowerEndpoint().size() != 1 || 
range.upperEndpoint().size() != 1) throw invalidRequest("Invalid number of 
range deletion components");
+            tracing().erasePermits(txnId, 
parseEventType(range.lowerEndpoint().value(0)));
+        }
+
+        @Override
+        protected void applyColumnDeletion(ColumnValues partitionKey, 
ColumnValues clusteringColumns, String columnName)
+        {
+            TxnId txnId = TxnId.parse(partitionKey.value(0));
+            TraceEventType eventType = 
parseEventType(clusteringColumns.value(0));
+            tracing().erasePermits(txnId, eventType);
+        }
+
+        @Override
+        protected void applyColumnUpdate(ColumnValues partitionKey, 
ColumnValues clusteringColumns, Optional<ColumnValue> columnValue)
+        {
+            TxnId txnId = TxnId.parse(partitionKey.value(0));
+            TraceEventType eventType = 
parseEventType(clusteringColumns.value(0));
+            if (columnValue.isEmpty()) tracing().erasePermits(txnId, 
eventType);
+            else tracing().setPermits(txnId, eventType, 
columnValue.get().value());
+        }
+
+        @Override
+        public void truncate()
+        {
+            tracing().eraseAllEvents();
+        }
+    }
+
+    public static final class TxnTracesTable extends 
AbstractMutableVirtualTable
+    {
+        private TxnTracesTable()
+        {
+            super(parse(VIRTUAL_ACCORD_DEBUG, TXN_TRACES,
+                        "Accord Transaction Traces",
+                        "CREATE TABLE %s (\n" +
+                        "  txn_id text,\n" +
+                        "  id_micros bigint,\n" +
+                        "  event_type text,\n" +
+                        "  at_micros bigint,\n" +
+                        "  command_store_id int,\n" +
+                        "  message text,\n" +
+                        "  PRIMARY KEY (txn_id, event_type, id_micros, 
at_micros)" +
+                        ')', UTF8Type.instance));
+        }
+
+        private AccordTracing tracing()
+        {
+            return ((AccordAgent)AccordService.instance().agent()).tracing();
+        }
+
+        @Override
+        protected void applyPartitionDeletion(ColumnValues partitionKey)
+        {
+            TxnId txnId = TxnId.parse(partitionKey.value(0));
+            tracing().eraseEvents(txnId);
+        }
+
+        @Override
+        protected void applyRangeTombstone(ColumnValues partitionKey, 
Range<ColumnValues> range)
+        {
+            TxnId txnId = TxnId.parse(partitionKey.value(0));
+            if (!range.hasLowerBound() || range.lowerBoundType() != 
BoundType.CLOSED) throw invalidRequest("May restrict deletion by at most one 
event_type");
+            if (range.lowerEndpoint().size() != 1) throw 
invalidRequest("Deletion restricted by lower bound on id_micros or at_micros is 
unsupported");
+            if (!range.hasUpperBound() || (range.upperBoundType() != 
BoundType.CLOSED && range.upperEndpoint().size() == 1)) throw 
invalidRequest("Range deletion must specify one event_type");
+            if 
(!range.upperEndpoint().value(0).equals(range.lowerEndpoint().value(0))) throw 
invalidRequest("May restrict deletion by at most one event_type");
+            if (range.upperEndpoint().size() > 2) throw 
invalidRequest("Deletion restricted by upper bound on at_micros is 
unsupported");
+            TraceEventType eventType = 
parseEventType(range.lowerEndpoint().value(0));
+            if (range.upperEndpoint().size() == 1)
+            {
+                tracing().eraseEvents(txnId, eventType);
+            }
+            else
+            {
+                long before = range.upperEndpoint().value(1);
+                tracing().eraseEventsBefore(txnId, eventType, before);
+            }
+        }
+
+        @Override
+        public void truncate()
+        {
+            tracing().eraseAllEvents();
+        }
+
+        @Override
+        public DataSet data()
+        {
+            SimpleDataSet dataSet = new SimpleDataSet(metadata());
+            tracing().forEach(id -> true, (txnId, eventType, permits, events) 
-> {
+                events.forEach(e -> {
+                    e.messages().forEach(m -> {
+                        dataSet.row(txnId.toString(), eventType.name(), 
e.atMicros, m.atNanos - e.atNanos)

Review Comment:
   yes, but I have renamed Event.atMicros to Event.idMicros for 
consistency/clarity



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