This is an automated email from the ASF dual-hosted git repository.

benedict pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 841e139b permit disabling TFK validation on replay
841e139b is described below

commit 841e139bc8a974ac674ce8eae847bd52255ca544
Author: Benedict Elliott Smith <[email protected]>
AuthorDate: Wed Oct 9 17:21:00 2024 +0100

    permit disabling TFK validation on replay
---
 .../main/java/accord/impl/TimestampsForKey.java    | 26 ++++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/accord-core/src/main/java/accord/impl/TimestampsForKey.java 
b/accord-core/src/main/java/accord/impl/TimestampsForKey.java
index 77e72fd1..ffe2b566 100644
--- a/accord-core/src/main/java/accord/impl/TimestampsForKey.java
+++ b/accord-core/src/main/java/accord/impl/TimestampsForKey.java
@@ -28,6 +28,14 @@ public class TimestampsForKey
 {
     public static final long NO_LAST_EXECUTED_HLC = Long.MIN_VALUE;
 
+    // TODO (required): this isn't safe - we won't reproduce the same 
timestamps on replay
+    private static volatile boolean replay;
+
+    public static void unsafeSetReplay(boolean newReplay)
+    {
+        replay = newReplay;
+    }
+
     public static class SerializerSupport
     {
         public static TimestampsForKey create(RoutingKey key,
@@ -115,24 +123,28 @@ public class TimestampsForKey
         return this;
     }
 
-    public void validateExecuteAtTime(Timestamp executeAt, boolean 
isForWriteTxn)
+    public boolean validateExecuteAtTime(Timestamp executeAt, boolean 
isForWriteTxn)
     {
         if (executeAt.compareTo(lastWriteTimestamp) < 0)
+        {
+            if (replay) return false;
             throw new IllegalArgumentException(String.format("%s is less than 
the most recent write timestamp %s", executeAt, lastWriteTimestamp));
+        }
 
         int cmp = executeAt.compareTo(lastExecutedTimestamp);
         // execute can be in the past if it's for a read and after the most 
recent write
         if (cmp == 0 || (!isForWriteTxn && cmp < 0))
-            return;
-        if (cmp < 0)
-            throw new IllegalArgumentException(String.format("%s is less than 
the most recent executed timestamp %s", executeAt, lastExecutedTimestamp));
-        else
-            throw new IllegalArgumentException(String.format("%s is greater 
than the most recent executed timestamp, cfk should be updated", executeAt, 
lastExecutedTimestamp));
+            return true;
+
+        if (replay) return false;
+        else if (cmp < 0) throw new IllegalArgumentException(String.format("%s 
is less than the most recent executed timestamp %s", executeAt, 
lastExecutedTimestamp));
+        else throw new IllegalArgumentException(String.format("%s is greater 
than the most recent executed timestamp, cfk should be updated", executeAt, 
lastExecutedTimestamp));
     }
 
     public long hlcFor(Timestamp executeAt, boolean isForWriteTxn)
     {
-        validateExecuteAtTime(executeAt, isForWriteTxn);
+        if (!validateExecuteAtTime(executeAt, isForWriteTxn))
+            return executeAt.hlc();
         return rawLastExecutedHlc == NO_LAST_EXECUTED_HLC ? 
lastExecutedTimestamp.hlc() : rawLastExecutedHlc;
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to