You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/10 13:54:12 UTC

[GitHub] [pulsar] coderzc commented on a diff in pull request #17611: [feat][broker][PIP-195] Implement delayed message index bucket snapshot (create/load) - part2

coderzc commented on code in PR #17611:
URL: https://github.com/apache/pulsar/pull/17611#discussion_r991316789


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/BucketDelayedDeliveryTracker.java:
##########
@@ -0,0 +1,628 @@
+/**
+ * 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.pulsar.broker.delayed;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.bookkeeper.mledger.util.Futures.executeWithRetry;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeMap;
+import com.google.common.collect.Table;
+import com.google.common.collect.TreeRangeMap;
+import com.google.protobuf.ByteString;
+import io.netty.util.Timeout;
+import io.netty.util.Timer;
+import java.time.Clock;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.CompletableFuture;
+import javax.annotation.concurrent.ThreadSafe;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.ManagedCursor;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.bookkeeper.mledger.impl.PositionImpl;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.mutable.MutableLong;
+import org.apache.pulsar.broker.delayed.proto.DelayedMessageIndexBucketSnapshotFormat.DelayedIndex;
+import org.apache.pulsar.broker.delayed.proto.DelayedMessageIndexBucketSnapshotFormat.SnapshotMetadata;
+import org.apache.pulsar.broker.delayed.proto.DelayedMessageIndexBucketSnapshotFormat.SnapshotSegment;
+import org.apache.pulsar.broker.delayed.proto.DelayedMessageIndexBucketSnapshotFormat.SnapshotSegmentMetadata;
+import org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers;
+import org.apache.pulsar.common.util.FutureUtil;
+import org.apache.pulsar.common.util.collections.TripleLongPriorityQueue;
+
+@Slf4j
+@ThreadSafe
+public class BucketDelayedDeliveryTracker extends InMemoryDelayedDeliveryTracker {
+
+    public static final String DELAYED_BUCKET_KEY_PREFIX = "#pulsar.internal.delayed.bucket";
+
+    public static final String DELIMITER = "_";
+
+    private final long minIndexCountPerBucket;
+
+    private final long timeStepPerBucketSnapshotSegment;
+
+    private final int maxNumBuckets;
+
+    private final ManagedCursor cursor;
+
+    public final BucketSnapshotStorage bucketSnapshotStorage;
+
+    private long numberDelayedMessages;
+
+    private final Bucket lastMutableBucket;
+
+    private final TripleLongPriorityQueue sharedBucketPriorityQueue;
+
+    private final RangeMap<Long, Bucket> immutableBuckets;
+
+    private final Table<Long, Long, Bucket> snapshotSegmentLastIndexTable;
+
+    BucketDelayedDeliveryTracker(PersistentDispatcherMultipleConsumers dispatcher,
+                                 Timer timer, long tickTimeMillis,
+                                 boolean isDelayedDeliveryDeliverAtTimeStrict,
+                                 BucketSnapshotStorage bucketSnapshotStorage,
+                                 long minIndexCountPerBucket, long timeStepPerBucketSnapshotSegment,
+                                 int maxNumBuckets) {
+        this(dispatcher, timer, tickTimeMillis, Clock.systemUTC(), isDelayedDeliveryDeliverAtTimeStrict,
+                bucketSnapshotStorage, minIndexCountPerBucket, timeStepPerBucketSnapshotSegment, maxNumBuckets);
+    }
+
+    BucketDelayedDeliveryTracker(PersistentDispatcherMultipleConsumers dispatcher,
+                                 Timer timer, long tickTimeMillis, Clock clock,
+                                 boolean isDelayedDeliveryDeliverAtTimeStrict,
+                                 BucketSnapshotStorage bucketSnapshotStorage,
+                                 long minIndexCountPerBucket, long timeStepPerBucketSnapshotSegment,
+                                 int maxNumBuckets) {
+        super(dispatcher, timer, tickTimeMillis, clock, isDelayedDeliveryDeliverAtTimeStrict);
+        this.minIndexCountPerBucket = minIndexCountPerBucket;
+        this.timeStepPerBucketSnapshotSegment = timeStepPerBucketSnapshotSegment;
+        this.maxNumBuckets = maxNumBuckets;
+        this.cursor = dispatcher.getCursor();
+        this.sharedBucketPriorityQueue = new TripleLongPriorityQueue();
+        this.immutableBuckets = TreeRangeMap.create();
+        this.snapshotSegmentLastIndexTable = HashBasedTable.create();
+
+        this.bucketSnapshotStorage = bucketSnapshotStorage;
+
+        numberDelayedMessages = recoverBucketSnapshot();
+
+        this.lastMutableBucket = new Bucket(-1L, -1L, new HashMap<>());
+    }
+
+    @SneakyThrows

Review Comment:
   I remove it.



-- 
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-unsubscribe@pulsar.apache.org

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