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


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/SharedConsumerState.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.utils.LogContext;
+import org.apache.kafka.common.utils.Time;
+
+import java.time.Duration;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * This class stores shared state needed by both the application thread 
({@link AsyncKafkaConsumer}) and the
+ * network thread ({@link ConsumerNetworkThread}) to avoid costly inter-thread 
communication, where possible.
+ * This class compromises on the ideal of keeping state only in the network 
thread. However, this class only
+ * relies on classes which are designed to be thread-safe, thus they can be 
used in both the application
+ * and network threads.
+ *
+ * <p/>
+ *
+ * The following thread-safe classes are used by this class:
+ *
+ * <ul>
+ *     <li>{@link ApiVersions}</li>
+ *     <li>{@link ConsumerMetadata}</li>
+ *     <li>{@link OffsetFetcherUtils}</li>
+ *     <li>{@link SharedExceptionReference}</li>
+ *     <li>{@link SubscriptionState}</li>
+ *     <li>{@link Time}</li>
+ * </ul>
+ *
+ * <p/>
+ *
+ * In general, callers from the application thread should not mutate any of 
the state contained within this class.
+ * It should be considered as <em>read-only</em>, and only the network thread 
should mutate the state.
+ */
+public class SharedConsumerState {
+
+    private final SubscriptionState subscriptions;
+    private final OffsetFetcherUtils offsetFetcherUtils;
+    private final SharedExceptionReference updatePositionsError;
+    private final SharedExceptionReference metadataError;
+
+    public SharedConsumerState(LogContext logContext,
+                               ConsumerMetadata metadata,
+                               SubscriptionState subscriptions,
+                               Time time,
+                               long retryBackoffMs) {
+        this(logContext, metadata, subscriptions, time, retryBackoffMs, new 
ApiVersions());
+    }
+
+    public SharedConsumerState(LogContext logContext,
+                               ConsumerMetadata metadata,
+                               SubscriptionState subscriptions,
+                               Time time,
+                               long retryBackoffMs,
+                               ApiVersions apiVersions) {
+        requireNonNull(logContext);
+        requireNonNull(metadata);
+        requireNonNull(subscriptions);
+        requireNonNull(time);
+        requireNonNull(apiVersions);
+
+        this.subscriptions = subscriptions;
+        this.offsetFetcherUtils = new OffsetFetcherUtils(
+            logContext,
+            metadata,
+            subscriptions,
+            time,
+            retryBackoffMs,
+            apiVersions
+        );
+        this.updatePositionsError = new SharedExceptionReference();
+        this.metadataError = new SharedExceptionReference();
+    }
+
+    OffsetFetcherUtils offsetFetcherUtils() {
+        return offsetFetcherUtils;
+    }
+
+    public SharedExceptionReference updatePositionsError() {

Review Comment:
   You're right. I've stared at `updatePositionsError` for so long and hard 
that its name being confusing didn't jump out at me. I've changed it to 
`positionsUpdateError` here and where it's referenced by the callers.



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