jsancio commented on code in PR #22805:
URL: https://github.com/apache/kafka/pull/22805#discussion_r3615684644


##########
raft/src/main/java/org/apache/kafka/raft/internals/RecordsDecodingStrategy.java:
##########
@@ -0,0 +1,259 @@
+/*
+ * 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.raft.internals;
+
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.record.internal.DefaultRecordBatch;
+import org.apache.kafka.common.utils.Utils;
+import org.apache.kafka.common.utils.internals.BufferSupplier;
+import org.apache.kafka.common.utils.internals.ByteUtils;
+import org.apache.kafka.raft.Batch;
+import org.apache.kafka.raft.ControlRecord;
+import org.apache.kafka.server.common.serialization.RecordSerde;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.BiFunction;
+
+/**
+ * Decides which records {@link RecordsIterator} decodes when turning a batch 
into a {@link Batch}.
+ * A batch's records are decoded only when this strategy is interested in 
them; otherwise the batch
+ * is returned as a {@link Batch#notDecoded} batch carrying only the offset 
information.
+ *
+ * <p>Use one of the factory methods to select the behavior:
+ * <ul>
+ *   <li>{@link #dataAndControl} decodes both the control and data 
records.</li>
+ *   <li>{@link #controlOnly} decodes only the control records and skips the 
data records. Used by
+ *       the internal kraft partition listener, which needs no serde.</li>
+ *   <li>{@link #dataOnly} decodes only the data records and skips the control 
records.</li>
+ *   <li>{@link #none} skips both.</li>
+ * </ul>
+ */
+public final class RecordsDecodingStrategy<T> {
+    private final boolean decodeControlRecords;
+    private final boolean decodeDataRecords;
+    private final Optional<RecordSerde<T>> serde;
+
+    private RecordsDecodingStrategy(boolean decodeControlRecords, boolean 
decodeDataRecords, Optional<RecordSerde<T>> serde) {
+        this.decodeControlRecords = decodeControlRecords;
+        this.decodeDataRecords = decodeDataRecords;
+        this.serde = serde;
+    }

Review Comment:
   The variable `decodeDataRecord` is directly dependent on variable `serde`; 
for example when `decodeDataRecord` is `false`, `serde` is empty. Or another 
way of saying is that `decodeDataRecords` is always equal to 
`!serde.isEmpty()`. This means that you don't need this extra state or field.



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