Caideyipi commented on code in PR #16425:
URL: https://github.com/apache/iotdb/pull/16425#discussion_r2357741353


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/dualkeycache/impl/FIFOCacheEntryManager.java:
##########
@@ -171,28 +186,40 @@ public int hashCode() {
   private static class FIFOLinkedList<SK, V> {
 
     // head.next is the newest
-    private final FIFOCacheEntry head;
-    private final FIFOCacheEntry tail;
+    private final FIFOCacheEntry<SK, V> head;
+    private final FIFOCacheEntry<SK, V> tail;
 
     public FIFOLinkedList() {
-      head = new FIFOCacheEntry(null, null, null);
-      tail = new FIFOCacheEntry(null, null, null);
+      head = new FIFOCacheEntry<>(null, null, null);
+      tail = new FIFOCacheEntry<>(null, null, null);
       head.next = tail;
       tail.pre = head;
     }
 
-    synchronized void add(FIFOCacheEntry cacheEntry) {
-      cacheEntry.next = head.next;
+    synchronized void add(final FIFOCacheEntry<SK, V> cacheEntry) {
+      FIFOCacheEntry<SK, V> nextEntry;
+
+      do {
+        nextEntry = head.next;
+      } while (nextEntry.isInvalidated.get());

Review Comment:
   This is because the "invalidate" does not take lock, and we need 
"isInvalidated" to protect the correctness. The head.next is supposed to be 
altered by the invalidation thread.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/dualkeycache/impl/FIFOCacheEntryManager.java:
##########
@@ -171,28 +186,40 @@ public int hashCode() {
   private static class FIFOLinkedList<SK, V> {
 
     // head.next is the newest
-    private final FIFOCacheEntry head;
-    private final FIFOCacheEntry tail;
+    private final FIFOCacheEntry<SK, V> head;
+    private final FIFOCacheEntry<SK, V> tail;
 
     public FIFOLinkedList() {
-      head = new FIFOCacheEntry(null, null, null);
-      tail = new FIFOCacheEntry(null, null, null);
+      head = new FIFOCacheEntry<>(null, null, null);
+      tail = new FIFOCacheEntry<>(null, null, null);
       head.next = tail;
       tail.pre = head;
     }
 
-    synchronized void add(FIFOCacheEntry cacheEntry) {
-      cacheEntry.next = head.next;
+    synchronized void add(final FIFOCacheEntry<SK, V> cacheEntry) {
+      FIFOCacheEntry<SK, V> nextEntry;
+
+      do {
+        nextEntry = head.next;
+      } while (nextEntry.isInvalidated.get());
+
+      cacheEntry.next = nextEntry;
       cacheEntry.pre = head;
-      head.next.pre = cacheEntry;
+      nextEntry.pre = cacheEntry;
       head.next = cacheEntry;
     }
 
-    synchronized FIFOCacheEntry evict() {
-      if (tail.pre == head) {
-        return null;
-      }
-      FIFOCacheEntry cacheEntry = tail.pre;
+    synchronized FIFOCacheEntry<SK, V> evict() {
+      FIFOCacheEntry<SK, V> cacheEntry;
+
+      do {
+        cacheEntry = tail.pre;
+        if (cacheEntry == head) {
+          return null;
+        }
+
+      } while (cacheEntry.isInvalidated.compareAndSet(false, true));

Review Comment:
   Same as above



-- 
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]

Reply via email to