You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "dcapwell (via GitHub)" <gi...@apache.org> on 2023/04/04 16:32:13 UTC

[GitHub] [cassandra] dcapwell commented on a diff in pull request #2259: CASSANDRA-18422: C* side

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


##########
test/simulator/test/org/apache/cassandra/simulator/paxos/HistoryValidatorTest.java:
##########
@@ -356,79 +383,142 @@ private static Event writeOnly(int pk)
         return new Event(EnumSet.of(Event.Type.WRITE), pk, null);
     }
 
-    private void fromLog(String log)
+    private interface Operation {}
+    private static class Read implements Operation
     {
-        IntSet pks = new IntHashSet();
-        class Read
-        {
-            final int pk, id, count;
-            final int[] seq;
+        final int pk, id, count;
+        final int[] seq;
 
-            Read(int pk, int id, int count, int[] seq)
-            {
-                this.pk = pk;
-                this.id = id;
-                this.count = count;
-                this.seq = seq;
-            }
+        Read(int pk, int id, int count, int[] seq)
+        {
+            this.pk = pk;
+            this.id = id;
+            this.count = count;
+            this.seq = seq;
         }
-        class Write
+    }
+    private static class Write implements Operation
+    {
+        final int pk, id;
+        final boolean success;
+
+        Write(int pk, int id, boolean success)
         {
-            final int pk, id;
-            final boolean success;
+            this.pk = pk;
+            this.id = id;
+            this.success = success;
+        }
+    }
 
-            Write(int pk, int id, boolean success)
-            {
-                this.pk = pk;
-                this.id = id;
-                this.success = success;
-            }
+    private static class Witness
+    {
+        final int start, end;
+        final List<Operation> actions = new ArrayList<>();
+
+        Witness(int start, int end)
+        {
+            this.start = start;
+            this.end = end;
         }
-        class Witness
+
+        void read(int pk, int id, int count, int[] seq)
         {
-            final int start, end;
-            final List<Object> actions = new ArrayList<>();
+            actions.add(new Read(pk, id, count, seq));
+        }
 
-            Witness(int start, int end)
-            {
-                this.start = start;
-                this.end = end;
-            }
+        void write(int pk, int id, boolean success)
+        {
+            actions.add(new Write(pk, id, success));
+        }
 
-            void read(int pk, int id, int count, int[] seq)
+        void process(HistoryValidator validator)
+        {
+            try (HistoryValidator.Checker check = validator.witness(start, end))
             {
-                actions.add(new Read(pk, id, count, seq));
+                for (Object a : actions)
+                {
+                    if (a instanceof Read)
+                    {
+                        Read read = (Read) a;
+                        check.read(read.pk, read.id, read.count, read.seq);
+                    }
+                    else
+                    {
+                        Write write = (Write) a;
+                        check.write(write.pk, write.id, write.success);
+                    }
+                }

Review Comment:
   thanks, did this and all other places that did `instanceOf` checks



-- 
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-unsubscribe@cassandra.apache.org

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


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