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

commit acbd38cecf1cbe2f1e522359ac25b1c0759c876d
Author: Benedict Elliott Smith <[email protected]>
AuthorDate: Tue Nov 12 15:03:23 2024 +0000

    wip: key recovery should witness range transactions (and range transactions 
should witness only precisely intersecting txns))
---
 .../src/main/java/accord/local/KeyHistory.java     | 31 ++++++++++++++++++++--
 .../src/main/java/accord/local/PreLoadContext.java | 10 ++-----
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/accord-core/src/main/java/accord/local/KeyHistory.java 
b/accord-core/src/main/java/accord/local/KeyHistory.java
index a3b46dc5..ccf347af 100644
--- a/accord-core/src/main/java/accord/local/KeyHistory.java
+++ b/accord-core/src/main/java/accord/local/KeyHistory.java
@@ -24,6 +24,7 @@ package accord.local;
  */
 public enum KeyHistory
 {
+    NONE,
     // TODO (required): deprecate
     TIMESTAMPS,
 
@@ -48,7 +49,33 @@ public enum KeyHistory
     /**
      * Load recovery information for all keys into memory before processing 
the command.
      */
-    RECOVER,
+    RECOVER;
+    
+    public boolean satisfiesIfPresent(KeyHistory that)
+    {
+        return satisfies(that, ASYNC);
+    }
+
+    public boolean satisfies(KeyHistory that)
+    {
+        return satisfies(that, SYNC);
+    }
+
+    private boolean satisfies(KeyHistory that, KeyHistory ifSyncRequireAtLeast)
+    {
+        switch (that)
+        {
+            default: throw new AssertionError("Unhandled KeyHistory: " + that);
+            case NONE:
+                return true;
+            case RECOVER:
+            case TIMESTAMPS:
+                return this == that;
+            case ASYNC:
+            case INCR:
+            case SYNC:
+                return this.compareTo(ifSyncRequireAtLeast) >= 0;
+        }
+    }
 
-    NONE
 }
diff --git a/accord-core/src/main/java/accord/local/PreLoadContext.java 
b/accord-core/src/main/java/accord/local/PreLoadContext.java
index 97697d06..3c408708 100644
--- a/accord-core/src/main/java/accord/local/PreLoadContext.java
+++ b/accord-core/src/main/java/accord/local/PreLoadContext.java
@@ -121,14 +121,8 @@ public interface PreLoadContext
         Unseekables<?> keys = keys();
         if (!keys.isEmpty())
         {
-            KeyHistory requiredHistory = keyHistory();
-            if (requiredHistory != NONE)
-            {
-                if (requiredHistory == INCR || requiredHistory == ASYNC)
-                    requiredHistory = SYNC;
-                if (requiredHistory != superset.keyHistory())
-                    return false;
-            }
+            if (!superset.keyHistory().satisfies(keyHistory()))
+                return false;
 
             Unseekables<?> supersetKeys = superset.keys();
             if (supersetKeys.domain() != keys.domain() || 
!supersetKeys.containsAll(keys()))


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

Reply via email to