adixitconfluent commented on code in PR #16969:
URL: https://github.com/apache/kafka/pull/16969#discussion_r1739613663


##########
core/src/main/java/kafka/server/share/DelayedShareFetch.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * 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 kafka.server.share;
+
+import kafka.server.DelayedOperation;
+import kafka.server.LogReadResult;
+import kafka.server.QuotaFactory;
+import kafka.server.ReplicaManager;
+
+import org.apache.kafka.common.TopicIdPartition;
+import org.apache.kafka.common.requests.FetchRequest;
+import org.apache.kafka.storage.internals.log.FetchPartitionData;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import scala.Option;
+import scala.Tuple2;
+import scala.collection.Seq;
+import scala.jdk.javaapi.CollectionConverters;
+import scala.runtime.BoxedUnit;
+
+/**
+ * A delayed share fetch operation has been introduced in case there is no 
share partition for which we can acquire records. We will try to wait
+ * for MaxWaitMs for records to be released else complete the share fetch 
request.
+ */
+public class DelayedShareFetch extends DelayedOperation {
+    private final SharePartitionManager.ShareFetchPartitionData 
shareFetchPartitionData;
+    private final ReplicaManager replicaManager;
+    private final Map<SharePartitionManager.SharePartitionKey, SharePartition> 
partitionCacheMap;
+    private final Map<TopicIdPartition, FetchRequest.PartitionData> 
topicPartitionDataFromTryComplete = new LinkedHashMap<>();
+
+    private static final Logger log = 
LoggerFactory.getLogger(DelayedShareFetch.class);
+
+    DelayedShareFetch(
+            SharePartitionManager.ShareFetchPartitionData 
shareFetchPartitionData,
+            ReplicaManager replicaManager,
+            Map<SharePartitionManager.SharePartitionKey, SharePartition> 
partitionCacheMap) {
+        super(shareFetchPartitionData.fetchParams().maxWaitMs, Option.empty());
+        this.shareFetchPartitionData = shareFetchPartitionData;
+        this.replicaManager = replicaManager;
+        this.partitionCacheMap = partitionCacheMap;
+    }
+
+    @Override
+    public void onExpiration() {
+    }
+
+    /**
+     * Complete the share fetch operation by fetching records for all 
partitions in the share fetch request irrespective
+     * of whether they have any acquired records. This is called when the 
fetch operation is forced to complete either

Review Comment:
   There can be a case where no acknowledgement comes for the share partitions 
corresponding to the purgatory entry. So after maxWaitMs, that entry will enter 
`onComplete`, it won't be able to acquire any partitions and en empty future is 
returned.



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