ChenSammi commented on code in PR #6731:
URL: https://github.com/apache/ozone/pull/6731#discussion_r1634966864


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -265,6 +271,46 @@ public void run() {
     }
   }
 
+  /**
+   * A cache to store committed transaction IDs with a fixed maximum size,
+   * ensuring the oldest entries are evicted when capacity is exceeded.
+   */
+  public static final class CommittedTransactionCache {
+    private final Set<Long> committedTransactionIds;
+    private final int maxCacheSize;
+
+    public CommittedTransactionCache(int maxCacheSize) {
+      this.committedTransactionIds = new LinkedHashSet<>(maxCacheSize);
+      this.maxCacheSize = maxCacheSize;
+    }
+
+    public boolean contains(Long txID) {
+      return committedTransactionIds.contains(txID);
+    }
+
+    public int getCacheSize() {
+      return committedTransactionIds.size();
+    }
+
+    public void adds(List<Long> txIDs) {
+      committedTransactionIds.addAll(txIDs);
+      ensureCapacity();
+    }
+
+    private void ensureCapacity() {
+      int size = committedTransactionIds.size();
+      if (size > maxCacheSize) {
+        int numToRemove = size - maxCacheSize;
+        Iterator<Long> it = committedTransactionIds.iterator();
+        while (numToRemove > 0 && it.hasNext()) {

Review Comment:
   So it is a FIFO cache. @xichen01 , do you have any idea about the duplicate 
pattern?  Which policy will be more suitable,  FIFO or LRU? 



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