Caideyipi commented on code in PR #18808: URL: https://github.com/apache/iotdb/pull/18808#discussion_r4244665718
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/SubscriptionQueueTimeTracker.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.iotdb.db.subscription.broker.consensus; + +import org.apache.iotdb.commons.utils.TestOnly; + +import java.util.concurrent.TimeUnit; +import java.util.function.LongSupplier; + +/** Monotonic timing that remains readable while a queue's prefetch worker is blocked. */ +class SubscriptionQueueTimeTracker { + + private final LongSupplier nanoTime; + + private volatile boolean started; + private boolean delivered; + private volatile long lastDeliveryTimeNs; + private volatile long lastDeliveryIntervalMs; + private volatile long maxDeliveryIntervalMs; + private volatile long lastPrefetchCompletionTimeNs; + private volatile long prefetchStartTimeNs; + private volatile boolean prefetchRunning; + private volatile long maxPrefetchDurationMs; + + SubscriptionQueueTimeTracker() { + this(System::nanoTime); + } + + @TestOnly + SubscriptionQueueTimeTracker(final LongSupplier nanoTime) { + this.nanoTime = nanoTime; + } + + synchronized void start() { + if (!started) { + final long nowNs = nanoTime.getAsLong(); + lastDeliveryTimeNs = nowNs; + lastPrefetchCompletionTimeNs = nowNs; + started = true; + } + } + + synchronized void recordDelivery() { Review Comment: The prefetch round itself is serialized by `ConsensusPrefetchSubtask`, so `beginPrefetch()` and `endPrefetch()` no longer synchronize on the tracker. `recordDelivery()` is different: `poll()` holds the queue read lock, which allows multiple consumers to poll concurrently, so its delivery interval update still needs synchronization. I pushed this adjustment in `0fe8d4bb1c1`. -- 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]
