jsancio commented on code in PR #12711:
URL: https://github.com/apache/kafka/pull/12711#discussion_r996492362
##########
metadata/src/main/java/org/apache/kafka/metadata/util/SnapshotFileReader.java:
##########
@@ -131,6 +132,10 @@ private void handleControlBatch(FileChannelRecordBatch
batch) {
batch.partitionLeaderEpoch()
));
break;
Review Comment:
Hmm. Probably outside the scope of this PR but this doesn't look correct.
First, snapshot doesn't include this record. Second, KRaft mainly uses this
control record so that the the current leader epoch to gets committed into the
log. KRaft doesn't really read this value.
I am not sure that the `kafka-metadata-shell` should rely on the
`LeaderChangeMessage` to determine the leader.
##########
metadata/src/test/java/org/apache/kafka/metadata/util/SnapshotFileReaderTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.metadata.util;
+
+import org.apache.kafka.common.header.Header;
+import org.apache.kafka.common.message.SnapshotFooterRecord;
+import org.apache.kafka.common.message.SnapshotHeaderRecord;
+import org.apache.kafka.common.protocol.ApiMessage;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.record.ControlRecordType;
+import org.apache.kafka.common.record.DefaultRecord;
+import org.apache.kafka.common.record.FileLogInputStream;
+import org.apache.kafka.common.record.Record;
+import org.apache.kafka.common.utils.ByteBufferOutputStream;
+import org.apache.log4j.Logger;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+
+final public class SnapshotFileReaderTest {
+ @Test
+ public void testHeaderFooterControlRecord() throws Exception {
+ SnapshotFileReader mockReader = Mockito.mock(SnapshotFileReader.class);
+
Mockito.doCallRealMethod().when(mockReader).handleControlBatch(any(FileLogInputStream.FileChannelRecordBatch.class));
+
+ SnapshotHeaderRecord snapshotHeaderMessage = new
SnapshotHeaderRecord().setVersion((short) 0).setLastContainedLogTimestamp(1);
+ SnapshotFooterRecord snapshotFooterMessage = new
SnapshotFooterRecord().setVersion((short) 0);
+ Record snapshotHeaderRecord =
generateControlRecord(snapshotHeaderMessage,
ControlRecordType.SNAPSHOT_HEADER.getType());
+ Record snapshotFooterRecord =
generateControlRecord(snapshotFooterMessage,
ControlRecordType.SNAPSHOT_FOOTER.getType());
+
+ FileLogInputStream.FileChannelRecordBatch mockBatch =
Mockito.mock(FileLogInputStream.FileChannelRecordBatch.class);
+ Iterator<Record> recordIterator = Arrays.asList(snapshotHeaderRecord,
snapshotFooterRecord).iterator();
+ Mockito.when(mockBatch.iterator()).thenReturn(recordIterator);
+
+ LogCaptureAppender appender = new LogCaptureAppender();
+ Logger.getRootLogger().addAppender(appender);
+ try {
+ mockReader.handleControlBatch(mockBatch);
+ // should not log any messages
+ assertThat(appender.getMessages(),
not(hasItem(containsString("Ignoring control record"))));
Review Comment:
I tend to agree with you. For example, would it be better to add a
`MetadataShellTest` type and create a similar test there that looks like at the
`stdout`?
--
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]