lhotari commented on code in PR #26127:
URL: https://github.com/apache/pulsar/pull/26127#discussion_r3505018202


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedgerConfig.java:
##########


Review Comment:
   The build warns about invalid javadoc, fix would be to replace `<` with 
`&lt;`.



##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java:
##########
@@ -2793,10 +2793,13 @@ The max allowed delay for delayed delivery (in 
milliseconds). If the broker rece
     private int managedLedgerMaxUnackedRangesToPersistInMetadataStore = 200000;
     @FieldContext(
             category = CATEGORY_STORAGE_OFFLOADING,
-            doc = "When set to true, a BitSet will be used to track 
acknowledged messages that come after the \"mark "
-                    + "delete position\" for each 
subscription.\n\nRoaringBitmap is used as a memory efficient BitSet "
-                    + "implementation for the acknowledged messages tracking. 
Unacknowledged ranges are the message "
-                    + "ranges excluding the acknowledged messages.")
+            doc = "Deprecated since 5.0.0 — no-op, retained for config-file 
backward compatibility.\n\n"
+                    + "Historically selected between a bitmap-backed range set 
(true, default) and a "
+                    + "DefaultRangeSet (false) for tracking acknowledged 
messages after the mark-delete "
+                    + "position. Since 5.0.0 the cursor always uses the 
bitmap-backed PositionRangeSet "
+                    + "(equivalent to the former 'true' path), so this setting 
has no effect. Setting it "
+                    + "to false is silently ignored.")
+    @Deprecated
     private boolean managedLedgerUnackedRangesOpenCacheSetEnabled = true;

Review Comment:
   could we just remove this? I don't see a reason to keep it.



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionRangeSet.java:
##########
@@ -0,0 +1,518 @@
+/*
+ * 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;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.BoundType;
+import com.google.common.collect.Range;
+import io.github.merlimat.slog.Logger;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Objects;
+import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.bookkeeper.mledger.Position;
+import org.apache.bookkeeper.mledger.PositionFactory;
+import org.apache.commons.lang3.mutable.MutableInt;
+import org.apache.pulsar.common.util.collections.LongPairRangeSet;
+import org.roaringbitmap.RoaringBitSet;
+
+/**
+ * Tracks deleted-message positions as ranges of {@link Position}s.
+ *
+ * <p>The implementation stores positions in a two-level structure:
+ * the ledger id is used as the map key, and the corresponding entry ids are 
stored in a
+ * {@link RoaringBitSet}. Bit {@code n} in the bitmap of ledger {@code L} 
represents the position
+ * {@code (L, n)}.
+ *
+ * <p>This implementation replaces the previous {@code 
RangeSetWrapper<Position>} backed by
+ * {@code OpenLongPairRangeSet}. Keeping the storage layout ledger-oriented 
avoids the overhead of
+ * creating and comparing {@link Position} range objects while preserving the 
same
+ * {@link LongPairRangeSet} semantics.
+ *
+ * <h2>Thread Safety</h2>
+ *
+ * <p>This class is not thread-safe. All methods require the caller to provide 
external
+ * synchronization. In normal usage, callers must hold the owning {@link 
ManagedCursorImpl}'s
+ * cursor lock before accessing this class.
+ *
+ * <p>The class intentionally does not maintain internal locking. The cursor 
lock is the single
+ * synchronization boundary for both this structure and related cursor state.
+ *
+ * <h2>Persistence Compatibility</h2>
+ *
+ * <p>The persisted representation remains compatible with the existing format:
+ * {@link #toRanges(int)} and {@link #build(Map)} use the {@link 
BitSet#toLongArray()} /
+ * {@link BitSet#valueOf(long[])} contract.
+ *
+ * <p>The internal {@link RoaringBitSet} representation is an implementation 
detail and is not used
+ * for serialization, avoiding any wire-format change.
+ *
+ * <p>Entry ids are stored as bitmap indexes and therefore use {@code int} 
values. This is safe
+ * because {@code managedLedgerMaxEntriesPerLedger} is an {@code int}, so 
valid entry ids are within
+ * {@code [0, Integer.MAX_VALUE]}.
+ */
+class PositionRangeSet implements LongPairRangeSet<Position> {
+
+    private static final Logger log = Logger.get(PositionRangeSet.class);
+
+    private static final long EARLIEST_KEY = -1L;
+    private static final long EARLIEST_VALUE = -1L;
+    private static final long LATEST_KEY = Long.MAX_VALUE;
+    private static final long LATEST_VALUE = Long.MAX_VALUE;
+
+    private final NavigableMap<Long, RoaringBitSet> rangeBitSetMap = new 
TreeMap<>();
+    private final LongPairConsumer<Position> consumer;
+    private final boolean enableMultiEntry;
+
+    private RoaringBitSet dirtyLedgers = new RoaringBitSet();

Review Comment:
   Replace `RoaringBitSet` with `LongBitmap`. One of the reasons to replace 
`RangeSetWrapper` is to be able to do this. Another reason is that some 
operations in `RoaringBitSet` might not be optimal due to the need to use the 
`java.util.BitSet` interface.
   You might need to add new methods to `LongBitmap` as part of this 
replacement.



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