heesung-sn commented on code in PR #24363:
URL: https://github.com/apache/pulsar/pull/24363#discussion_r2118656479


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/cache/RangeCache.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bookkeeper.mledger.impl.cache;
+
+import io.netty.util.IllegalReferenceCountException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentNavigableMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * Special type of cache where get() and delete() operations can be done over 
a range of keys.
+ * The implementation avoids locks and synchronization by relying on 
ConcurrentSkipListMap for storing the entries.
+ * Since there are no locks, it's necessary to ensure that a single entry in 
the cache is removed exactly once.
+ * Removing an entry multiple times could result in the entries of the cache 
being released multiple times,
+ * even while they are still in use. This is prevented by using a custom 
wrapper around the value to store in the map
+ * that ensures that the value is removed from the map only if the exact same 
instance is present in the map.
+ * There's also a check that ensures that the value matches the key. This is 
used to detect races without impacting
+ * consistency.
+ */
+@Slf4j
+class RangeCache {
+    private final ConcurrentNavigableMap<Position, RangeCacheEntryWrapper> 
entries;
+    private final RangeCacheRemovalQueue removalQueue;

Review Comment:
   Thank you for answering my questions. I think this PR and direction looks 
good to me with the future improvements. 
   
   But I guess this requires more discussions in the Pulsar community, too.
   
   



-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to