dajac commented on code in PR #16059:
URL: https://github.com/apache/kafka/pull/16059#discussion_r1613028497
##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/runtime/CoordinatorRuntime.java:
##########
@@ -1365,6 +1368,11 @@ public void onHighWatermarkUpdated(
}
}
+ /**
+ * 16KB. Used for initial buffer size for write operations.
+ */
+ static final int SIXTEEN_KB = 16384;
Review Comment:
nit: Should we call it `MIN_BUFFER_SIZE`?
##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/runtime/CoordinatorRuntimeTest.java:
##########
@@ -3007,6 +3010,57 @@ public void
testCoordinatorCompleteTransactionEventWriteTimeoutTaskIsCancelledWh
timer.taskQueue().forEach(taskEntry ->
assertTrue(taskEntry.cancelled()));
}
+ @Test
+ public void testAppendRecordBatchSize() {
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ StringSerializer serializer = new StringSerializer();
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(DEFAULT_WRITE_TIMEOUT)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(new DirectEventProcessor())
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new
MockCoordinatorShardBuilderSupplier())
+
.withCoordinatorRuntimeMetrics(mock(GroupCoordinatorRuntimeMetrics.class))
+ .withCoordinatorMetrics(mock(GroupCoordinatorMetrics.class))
+ .withSerializer(serializer)
+ .build();
+
+ // Schedule the loading.
+ runtime.scheduleLoadOperation(TP, 10);
+
+ // Verify the initial state.
+ CoordinatorRuntime<MockCoordinatorShard, String>.CoordinatorContext
ctx = runtime.contextOrThrow(TP);
+ assertEquals(0L, ctx.coordinator.lastWrittenOffset());
+ assertEquals(0L, ctx.coordinator.lastCommittedOffset());
+ assertEquals(Collections.singletonList(0L),
ctx.coordinator.snapshotRegistry().epochsList());
+
+ int maxBatchSize = writer.config(TP).maxMessageSize();
+ assertTrue(maxBatchSize > SIXTEEN_KB);
+
+ // Generate enough records to create a batch that has 16KB < batchSize
< maxBatchSize
+ List<String> records = new ArrayList<>();
+ for (int i = 0; i < 3000; i++) {
+ records.add("record-" + i);
+ }
+
+ // Write #1.
+ CompletableFuture<String> write1 =
runtime.scheduleWriteOperation("write#1", TP, DEFAULT_WRITE_TIMEOUT,
+ state -> new CoordinatorResult<>(records, "response1")
+ );
+
+ // Verify that the write has not completed exceptionally.
+ // This will catch any exceptions thrown including
RecordTooLargeException.
+ assertFalse(write1.isCompletedExceptionally());
+
+ int batchSize = writer.lastBatch.sizeInBytes();
Review Comment:
Could we use `writer.entries(TP).get(0).sizeInBytes()`?
--
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]