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

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

commit b8a2adc3d9ee7b25ce31ac845559b6f81d341db9
Author: David Capwell <[email protected]>
AuthorDate: Tue Nov 28 15:20:49 2023 -0800

    revert cache logic
---
 .../java/accord/impl/InMemoryCommandStore.java     | 59 +---------------------
 1 file changed, 2 insertions(+), 57 deletions(-)

diff --git a/accord-core/src/main/java/accord/impl/InMemoryCommandStore.java 
b/accord-core/src/main/java/accord/impl/InMemoryCommandStore.java
index db6be242..35fa6f13 100644
--- a/accord-core/src/main/java/accord/impl/InMemoryCommandStore.java
+++ b/accord-core/src/main/java/accord/impl/InMemoryCommandStore.java
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableMap;
@@ -101,11 +100,6 @@ public abstract class InMemoryCommandStore extends 
CommandStore
 
     private final TreeMap<TxnId, RangeCommand> rangeCommands = new TreeMap<>();
     private final TreeMap<TxnId, Ranges> historicalRangeCommands = new 
TreeMap<>();
-    /**
-     * Since this cache is fully in-memory the store does not hit states that 
most stores will; that data is not in-memory!
-     * To simulate such behaviors, a "cache" is used to state what is 
in-memory vs what needs to be loaded.
-     */
-    private final Set<Object> cache = new LinkedHashSet<>();
     protected Timestamp maxRedundant = Timestamp.NONE;
 
     private InMemorySafeStore current;
@@ -138,7 +132,7 @@ public abstract class InMemoryCommandStore extends 
CommandStore
 
     public GlobalCommand ifPresent(TxnId txnId)
     {
-        return cache.contains(txnId) ? commands.get(txnId) : null;
+        return commands.get(txnId);
     }
 
     public GlobalCommand command(TxnId txnId)
@@ -233,7 +227,7 @@ public abstract class InMemoryCommandStore extends 
CommandStore
 
     public GlobalCommandsForKey ifPresent(Key key)
     {
-        return cache.contains(key) ? commandsForKey.get(key) : null;
+        return commandsForKey.get(key);
     }
 
     public GlobalCommandsForKey commandsForKey(Key key)
@@ -418,58 +412,9 @@ public abstract class InMemoryCommandStore extends 
CommandStore
                     // load range cfks here
             }
         }
-        maybeUpdateCache(commands, commandsForKeys);
         return createSafeStore(context, ranges, commands, commandsForKeys);
     }
 
-    private void maybeUpdateCache(Map<TxnId, InMemorySafeCommand> commands, 
Map<RoutableKey, InMemorySafeCommandsForKey> commandsForKeys)
-    {
-        int cacheSize = this.cache.size();
-        boolean canEvict = true;
-        for (InMemorySafeCommand cmd : commands.values())
-        {
-            if (this.cache.contains(cmd.txnId())) continue;
-            if (canEvict && ++cacheSize > 10)
-            {
-                // need to remove 1 element from the cache!
-                boolean removed = false;
-                Iterator<Object> it = cache.iterator();
-                while (it.hasNext())
-                {
-                    Object next = it.next();
-                    if (commands.containsKey(next) || 
commandsForKeys.containsKey(next)) continue;
-                    it.remove();
-                    removed = true;
-                    if (--cacheSize == 10)
-                        break;
-                }
-                if (!removed) canEvict = false;
-            }
-            this.cache.add(cmd.txnId());
-        }
-        for (InMemorySafeCommandsForKey cfk : commandsForKeys.values())
-        {
-            if (this.cache.contains(cfk.key())) continue;
-            if (canEvict && ++cacheSize > 10)
-            {
-                // need to remove 1 element from the cache!
-                boolean removed = false;
-                Iterator<Object> it = cache.iterator();
-                while (it.hasNext())
-                {
-                    Object next = it.next();
-                    if (commands.containsKey(next) || 
commandsForKeys.containsKey(next)) continue;
-                    it.remove();
-                    removed = true;
-                    if (--cacheSize == 10)
-                        break;
-                }
-                if (!removed) canEvict = false;
-            }
-            this.cache.add(cfk.key());
-        }
-    }
-
     public SafeCommandStore beginOperation(PreLoadContext context)
     {
         if (current != null)


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

Reply via email to