SteveYurongSu commented on code in PR #12138: URL: https://github.com/apache/iotdb/pull/12138#discussion_r1532011178
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/SubscriptionPrefetchingQueue.java: ########## @@ -0,0 +1,253 @@ +/* + * 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; + +import org.apache.iotdb.commons.pipe.datastructure.queue.ConcurrentIterableLinkedQueue; +import org.apache.iotdb.commons.pipe.event.EnrichedEvent; +import org.apache.iotdb.commons.pipe.task.connection.BoundedBlockingPendingQueue; +import org.apache.iotdb.commons.subscription.config.SubscriptionConfig; +import org.apache.iotdb.db.pipe.event.UserDefinedEnrichedEvent; +import org.apache.iotdb.db.pipe.event.common.tablet.PipeInsertNodeTabletInsertionEvent; +import org.apache.iotdb.db.pipe.event.common.tablet.PipeRawTabletInsertionEvent; +import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent; +import org.apache.iotdb.pipe.api.event.Event; +import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent; +import org.apache.iotdb.rpc.subscription.payload.response.EnrichedTablets; +import org.apache.iotdb.tsfile.write.record.Tablet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class SubscriptionPrefetchingQueue { + + private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionBroker.class); + + private final String brokerId; // consumer group id + + private final String topicName; + + private final BoundedBlockingPendingQueue<Event> inputPendingQueue; + + private final SortedMap<String, SerializedEnrichedEvent> uncommittedEvents; + private final ReentrantReadWriteLock uncommittedEventsLock; + private final ConcurrentIterableLinkedQueue<SerializedEnrichedEvent> prefetchingQueue; + + // TODO: Consider the stale subscription commit ID; after restarting, the subscription commit ID + // from before the restart should not be accepted. + private final AtomicLong subscriptionCommitIdGenerator = new AtomicLong(0); + + public SubscriptionPrefetchingQueue( + String brokerId, String topicName, BoundedBlockingPendingQueue<Event> inputPendingQueue) { + this.brokerId = brokerId; + this.topicName = topicName; + this.inputPendingQueue = inputPendingQueue; + this.uncommittedEvents = new TreeMap<>(); + this.uncommittedEventsLock = new ReentrantReadWriteLock(true); + this.prefetchingQueue = new ConcurrentIterableLinkedQueue<>(); + } + + /////////////////////////////// provided for SubscriptionBroker /////////////////////////////// + + public SerializedEnrichedEvent poll() { Review Comment: add sync for method level? -- 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]
