fvaleri commented on code in PR #13085:
URL: https://github.com/apache/kafka/pull/13085#discussion_r1064119776


##########
storage/src/main/java/org/apache/kafka/server/log/internals/FetchParams.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.server.log.internals;
+
+import org.apache.kafka.common.replica.ClientMetadata;
+import org.apache.kafka.common.utils.FetchRequestUtils;
+
+import java.util.Objects;
+import java.util.Optional;
+
+public class FetchParams {
+    private final short requestVersion;
+    private final int replicaId;
+    private final long maxWaitMs;
+    private final int minBytes;
+    private final int maxBytes;
+    private final FetchIsolation isolation;
+    private Optional<ClientMetadata> clientMetadata;
+
+    public FetchParams(short requestVersion,
+                       int replicaId,
+                       long maxWaitMs,
+                       int minBytes,
+                       int maxBytes,
+                       FetchIsolation isolation,
+                       Optional<ClientMetadata> clientMetadata) {
+        this.requestVersion = requestVersion;
+        this.replicaId = replicaId;
+        this.maxWaitMs = maxWaitMs;
+        this.minBytes = minBytes;
+        this.maxBytes = maxBytes;
+        this.isolation = isolation;
+        this.clientMetadata = clientMetadata;
+    }
+
+    public boolean isFromFollower() {
+        return FetchRequestUtils.isValidBrokerId(replicaId);
+    }
+
+    public boolean isFromConsumer() {
+        return FetchRequestUtils.isConsumer(replicaId);
+    }
+
+    public boolean fetchOnlyLeader() {
+        return isFromFollower() || (isFromConsumer() && 
!clientMetadata.isPresent());
+    }
+
+    public boolean hardMaxBytesLimit() {
+        return requestVersion <= 2;
+    }
+
+    public short requestVersion() {
+        return requestVersion;
+    }
+
+    public int replicaId() {
+        return replicaId;
+    }
+
+    public long maxWaitMs() {
+        return maxWaitMs;
+    }
+
+    public int minBytes() {
+        return minBytes;
+    }
+
+    public int maxBytes() {
+        return maxBytes;
+    }
+
+    public FetchIsolation isolation() {
+        return isolation;
+    }
+
+    public Optional<ClientMetadata> clientMetadata() {
+        return clientMetadata;
+    }
+
+    @Override
+    public boolean equals(Object o) {

Review Comment:
   Yes, they are needed for the following tests:
   
   - ReplicaAlterLogDirsThreadTest.shouldReplaceCurrentLogDirWhenCaughtUp
   - ReplicaAlterLogDirsThreadTest.shouldUpdateLeaderEpochAfterFencedEpochError
   
   They both call `mockFetchFromCurrentLog` that uses the equal matcher on a 
instance of `FetchParams`. I would prefer to not touch tests if possible.



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