bdeggleston commented on code in PR #2144:
URL: https://github.com/apache/cassandra/pull/2144#discussion_r1126830800


##########
src/java/org/apache/cassandra/service/accord/AccordStateCache.java:
##########
@@ -247,96 +259,115 @@ private void maybeEvict()
             Node<?, ?> evict = current;
             current = current.prev;
 
-            // if there are any dangling write only groups, apply them and
-            // move their futures into write futures so we don't evict
-            applyAndRemoveWriteOnlyGroup(evict.value);
-            if (!canEvict(evict.key()))
+            if (!canEvict(evict))
                 continue;
 
-            logger.trace("Evicting {} {}", 
evict.value.getClass().getSimpleName(), evict.key());
-            unlink(evict);
-            cache.remove(evict.key());
-            bytesCached -= evict.estimatedSizeOnHeap();
+            evict(evict, true);
         }
     }
 
-    private static <K, F extends Future<?>> F getFuture(NamedMap<Object, F> 
futuresMap, K key)
+    private void evict(Node<?, ?> evict, boolean unlink)
     {
-        F r = futuresMap.get(key);
+        logger.info("Evicting {} {}", evict.state(), evict.key());
+        if (unlink) unlink(evict);
+        Node<?, ?> self = cache.get(evict.key());
+        Invariants.checkState(self == evict, "Leaked node detected; was 
attempting to remove %s but cache had %s", evict, self);
+        cache.remove(evict.key());
+        bytesCached -= evict.lastQueriedEstimatedSizeOnHeap;
+    }
+
+    private static <K, V, F extends AsyncResult<V>> F 
getAsyncResult(NamedMap<Object, F> resultMap, K key)
+    {
+        F r = resultMap.get(key);
         if (r == null)
             return null;
 
-        if (!r.isDone())
+        // if the result was a failure, can not remove from the map as this 
would allow eviction
+        if (!r.isSuccess())
             return r;
 
         if (logger.isTraceEnabled())
-            logger.trace("Clearing future for {} from {}: {}", key, 
futuresMap.name, r);
-        futuresMap.remove(key);
+            logger.trace("Clearing result for {} from {}: {}", key, 
resultMap.name, r);
+        resultMap.remove(key);
         return null;
     }
 
-    private static <K, F extends Future<?>> void setFuture(Map<Object, F> 
futuresMap, K key, F future)
+    private static <K, F extends AsyncResult<?>> void 
setAsyncResult(Map<Object, F> resultsMap, K key, F result)
+    {
+        Preconditions.checkState(!resultsMap.containsKey(key));
+        resultsMap.put(key, result);
+    }
+
+    private static <K, V> boolean hasActiveAsyncResult(NamedMap<Object, 
AsyncResult<V>> resultMap, K key)
     {
-        Preconditions.checkState(!futuresMap.containsKey(key));
-        futuresMap.put(key, future);
+        // getResult only returns a result if it is not complete, so don't 
need to check if its been completed
+        return getAsyncResult(resultMap, key) != null;
     }
 
-    private static <K> void mergeFuture(Map<Object, Future<?>> futuresMap, K 
key, Future<?> future)
+    private static <K> void mergeAsyncResult(Map<Object, AsyncResult<Void>> 
resultMap, K key, AsyncResult<Void> result)
     {
-        Future<?> existing = futuresMap.get(key);
+        AsyncResult<Void> existing = resultMap.get(key);
         if (existing != null && !existing.isDone())
         {
-            logger.trace("Merging future {} with existing {}", future, 
existing);
-            future = FutureCombiner.allOf(ImmutableList.of(existing, future));
+            logger.trace("Merging result {} with existing {}", result, 
existing);
+            result = AsyncChains.reduce(ImmutableList.of(existing, result), 
(a, b) -> null).beginAsResult();

Review Comment:
   that method actually already exists :)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to