Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

<!-- Raft -->
<suppress checks="NPathComplexity"
files="(DynamicVoter|RecordsIterator).java"/>
files="(DynamicVoter|DecodingStrategy).java"/>

<suppress checks="JavaNCSS"
files="(KafkaRaftClientTest).java"/>
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.apache.kafka.common.utils.Utils
import org.apache.kafka.common.utils.internals.ConfigUtils
import org.apache.kafka.network.SocketServer
import org.apache.kafka.raft.KafkaRaftClient
import org.apache.kafka.raft.internals.RecordsDecodingStrategy
import org.apache.kafka.server.{DynamicThreadPool, ProcessRole}
import org.apache.kafka.server.common.{ApiMessageAndVersion, DirectoryEventHandler}
import org.apache.kafka.server.config.{BrokerReconfigurable => JBrokerReconfigurable, DynamicConfig, DynamicProducerStateManagerConfig, ServerConfigs, ServerLogConfigs, DynamicBrokerConfig => JDynamicBrokerConfig}
Expand Down Expand Up @@ -106,7 +107,7 @@ object DynamicBrokerConfig {
Using.resource(
RecordsSnapshotReader.of(
rawSnapshotReader,
raftManager.recordSerde,
RecordsDecodingStrategy.dataAndControl(raftManager.recordSerde),
BufferSupplier.create(),
KafkaRaftClient.MAX_BATCH_SIZE_BYTES,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.kafka.raft.errors.BufferAllocationException;
import org.apache.kafka.raft.errors.NotLeaderException;
import org.apache.kafka.raft.internals.MemoryBatchReader;
import org.apache.kafka.raft.internals.RecordsDecodingStrategy;
import org.apache.kafka.server.common.ApiMessageAndVersion;
import org.apache.kafka.server.common.KRaftVersion;
import org.apache.kafka.server.common.OffsetAndEpoch;
Expand Down Expand Up @@ -479,7 +480,7 @@ private void scheduleLogCheck() {
listenerData.handleLoadSnapshot(
RecordsSnapshotReader.of(
snapshot.get(),
MetadataRecordSerde.INSTANCE,
RecordsDecodingStrategy.dataAndControl(MetadataRecordSerde.INSTANCE),
BufferSupplier.create(),
Integer.MAX_VALUE,
true,
Expand Down
37 changes: 37 additions & 0 deletions raft/src/main/java/org/apache/kafka/raft/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,41 @@ public static <T> Batch<T> data(
List.of()
);
}

/**
* Create a batch whose records were not decoded, carrying only the offset information.
*
* @param baseOffset offset of the first record in the batch
* @param epoch epoch of the leader that created this batch
* @param appendTimestamp timestamp in milliseconds of when the batch was appended
* @param sizeInBytes number of bytes used by this batch
* @param numRecords the number of records in this batch
*/
public static <T> Batch<T> notDecoded(
long baseOffset,
int epoch,
long appendTimestamp,
int sizeInBytes,
int numRecords
) {
if (numRecords < 1) {
throw new IllegalArgumentException(
String.format(
"Batch must contain at least one record; baseOffset = %d; epoch = %d",
baseOffset,
epoch
)
);
}

return new Batch<>(
baseOffset,
epoch,
appendTimestamp,
sizeInBytes,
baseOffset + numRecords - 1,
List.of(),
List.of()
);
}
}
4 changes: 2 additions & 2 deletions raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.apache.kafka.raft.internals.KafkaRaftMetrics;
import org.apache.kafka.raft.internals.MemoryBatchReader;
import org.apache.kafka.raft.internals.RecordsBatchReader;
import org.apache.kafka.raft.internals.RecordsDecodingStrategy;
import org.apache.kafka.raft.internals.RemoveVoterHandler;
import org.apache.kafka.raft.internals.RequestSendResult;
import org.apache.kafka.raft.internals.ThresholdPurgatory;
Expand Down Expand Up @@ -452,7 +453,7 @@ private void updateListenersProgress(long highWatermark) {
private Optional<SnapshotReader<T>> latestSnapshot() {
return log.latestSnapshot().map(reader ->
RecordsSnapshotReader.of(reader,
serde,
RecordsDecodingStrategy.dataAndControl(serde),
BufferSupplier.create(),
MAX_BATCH_SIZE_BYTES,
true, /* Validate batch CRC*/
Expand Down Expand Up @@ -498,7 +499,6 @@ public void initialize(
partitionState = new KRaftControlRecordStateMachine(
staticVoters,
log,
serde,
MAX_BATCH_SIZE_BYTES,
logContext,
kafkaRaftMetrics,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.kafka.raft.RaftLog;
import org.apache.kafka.raft.VoterSet;
import org.apache.kafka.server.common.KRaftVersion;
import org.apache.kafka.server.common.serialization.RecordSerde;
import org.apache.kafka.snapshot.RawSnapshotReader;
import org.apache.kafka.snapshot.RecordsSnapshotReader;
import org.apache.kafka.snapshot.SnapshotReader;
Expand All @@ -54,7 +53,6 @@ public final class KRaftControlRecordStateMachine {

private final LogContext logContext;
private final RaftLog log;
private final RecordSerde<?> serde;
private final Logger logger;
private final int maxBatchSizeBytes;

Expand All @@ -80,14 +78,12 @@ public final class KRaftControlRecordStateMachine {
*
* @param staticVoterSet the set of voter statically configured
* @param log the on disk topic partition
* @param serde the record decoder for data records
* @param maxBatchSizeBytes the maximum size of record batch
* @param logContext the log context
*/
public KRaftControlRecordStateMachine(
VoterSet staticVoterSet,
RaftLog log,
RecordSerde<?> serde,
int maxBatchSizeBytes,
LogContext logContext,
KafkaRaftMetrics kafkaRaftMetrics,
Expand All @@ -96,7 +92,6 @@ public KRaftControlRecordStateMachine(
this.logContext = logContext;
this.log = log;
this.voterSetHistory = new VoterSetHistory(staticVoterSet, logContext);
this.serde = serde;
this.maxBatchSizeBytes = maxBatchSizeBytes;
this.logger = logContext.logger(getClass());
this.kafkaRaftMetrics = kafkaRaftMetrics;
Expand Down Expand Up @@ -237,7 +232,7 @@ private void maybeLoadLog() {
);
try (RecordsIterator<?> iterator = new RecordsIterator<>(
info.records,
serde,
RecordsDecodingStrategy.controlOnly(),
bufferSupplier,
maxBatchSizeBytes,
true, // Validate batch CRC
Expand Down Expand Up @@ -269,7 +264,7 @@ private void maybeLoadSnapshot() {
try (BufferSupplier bufferSupplier = BufferSupplier.create();
SnapshotReader<?> reader = RecordsSnapshotReader.of(
rawSnapshot,
serde,
RecordsDecodingStrategy.controlOnly(),
bufferSupplier,
maxBatchSizeBytes,
true, // Validate batch CRC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static <T> RecordsBatchReader<T> of(
) {
return new RecordsBatchReader<>(
baseOffset,
new RecordsIterator<>(records, serde, bufferSupplier, maxBatchSize, doCrcValidation, logContext),
new RecordsIterator<>(records, RecordsDecodingStrategy.dataAndControl(serde), bufferSupplier, maxBatchSize, doCrcValidation, logContext),
closeListener
);
}
Expand Down
Loading
Loading