kirktrue commented on code in PR #20324:
URL: https://github.com/apache/kafka/pull/20324#discussion_r2299515725


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/CommitOffsetsSharedState.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.clients.ApiVersions;
+import org.apache.kafka.clients.consumer.Consumer;
+import 
org.apache.kafka.clients.consumer.internals.events.CheckAndUpdatePositionsEvent;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.utils.LogContext;
+import org.apache.kafka.common.utils.Time;
+
+import java.time.Duration;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * This class stores shared state needed by both the application thread 
({@link AsyncKafkaConsumer}) and the
+ * background thread ({@link OffsetsRequestManager}) to determine if a costly 
call to check offsets can be skipped
+ * inside {@link Consumer#poll(Duration)}.
+ *
+ * <p/>
+ *
+ * This class compromises on the ideal of keeping the state only in the 
background thread. However, this class only
+ * relies on the {@link SubscriptionState} and {@link ConsumerMetadata} which 
are, unfortunately, already used
+ * sparingly in both the application and background threads. Both of those 
classes are heavily synchronized given
+ * their use by the {@link ClassicKafkaConsumer}, so their use in a 
multithreaded fashion is already established.
+ */
+public class CommitOffsetsSharedState implements MemberStateListener {

Review Comment:
   Generalized the name to `SharedConsumerState` for reuse elsewhere.



-- 
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: jira-unsubscr...@kafka.apache.org

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

Reply via email to