You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "jeffkbkim (via GitHub)" <gi...@apache.org> on 2024/12/06 19:47:27 UTC
[PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
jeffkbkim opened a new pull request, #18083:
URL: https://github.com/apache/kafka/pull/18083
In CoordinatorWriteEvent/CoordinatorCompleteTransactionEvent#complete, we record the event purgatory time. This can throw an exception if a value that is greater than 1 minute is recorded. Handle this case.
Furthermore, this occurs even when the write event has already been completed via timeout, and is completed again via HWM update. Ensure a complete noop when completing a txn/write event a second time.
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "jeffkbkim (via GitHub)" <gi...@apache.org>.
jeffkbkim merged PR #18083:
URL: https://github.com/apache/kafka/pull/18083
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "dimitarndimitrov (via GitHub)" <gi...@apache.org>.
dimitarndimitrov commented on code in PR #18083:
URL: https://github.com/apache/kafka/pull/18083#discussion_r1875537267
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
+ Duration writeTimeout = Duration.ofMillis(MAX_LATENCY_MS + 1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ writer.commit(TP, 1);
+
+ // We should still have one pending event and the pending high watermark should be updated.
+ assertEquals(1, processor.size());
+ assertEquals(1, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ // Advance the clock past MAX_LATENCY_MS. Recorded event purgatory time should be capped at MAX_LATENCY_MS.
+ timer.advanceClock(MAX_LATENCY_MS + 500L);
+ // Poll once to process the high watermark update and complete the writes.
+ processor.poll();
+ long purgatoryTimeMs = timer.time().milliseconds() - writeTimestamp;
+
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+ assertEquals(1, runtime.contextOrThrow(TP).coordinator.lastCommittedOffset());
+ assertTrue(write1.isDone());
+ assertTrue(purgatoryTimeMs > MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(0)).recordEventPurgatoryTime(purgatoryTimeMs);
+ }
+
+ @Test
+ public void testWriteEventCompletesOnce() throws Exception {
+ // Completes once via timeout, then again with HWM update
+ Duration writeTimeout = Duration.ofMillis(1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
Review Comment:
nit: All of this seems to be shared with the previous test. Should we extract it and share it?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #18083:
URL: https://github.com/apache/kafka/pull/18083#discussion_r1874372172
##########
coordinator-common/src/main/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntime.java:
##########
@@ -1667,7 +1676,7 @@ public void complete(Throwable exception) {
if (deferredEventQueuedTimestamp != NOT_QUEUED) {
// Only record the purgatory time if the event was deferred.
- runtimeMetrics.recordEventPurgatoryTime(purgatoryTimeMs);
+ runtimeMetrics.recordEventPurgatoryTime(Math.min(purgatoryTimeMs, MAX_LATENCY_MS));
Review Comment:
ditto.
##########
coordinator-common/src/main/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntime.java:
##########
@@ -1378,7 +1383,7 @@ public void complete(Throwable exception) {
if (deferredEventQueuedTimestamp != NOT_QUEUED) {
// Only record the purgatory time if the event was deferred.
- runtimeMetrics.recordEventPurgatoryTime(purgatoryTimeMs);
+ runtimeMetrics.recordEventPurgatoryTime(Math.min(MAX_LATENCY_MS, purgatoryTimeMs));
Review Comment:
In my opinion, this gating should not be in the runtime because it depends on the underlying implementation of the metric. Could we move it into the runtime metrics implementation?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "jeffkbkim (via GitHub)" <gi...@apache.org>.
jeffkbkim commented on code in PR #18083:
URL: https://github.com/apache/kafka/pull/18083#discussion_r1876539847
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
Review Comment:
ah, thought i removed it. thanks
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #18083:
URL: https://github.com/apache/kafka/pull/18083#discussion_r1876533495
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
+ Duration writeTimeout = Duration.ofMillis(MAX_LATENCY_MS + 1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ writer.commit(TP, 1);
+
+ // We should still have one pending event and the pending high watermark should be updated.
+ assertEquals(1, processor.size());
+ assertEquals(1, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ // Advance the clock past MAX_LATENCY_MS. Recorded event purgatory time should be capped at MAX_LATENCY_MS.
+ timer.advanceClock(MAX_LATENCY_MS + 500L);
+ // Poll once to process the high watermark update and complete the writes.
+ processor.poll();
+ long purgatoryTimeMs = timer.time().milliseconds() - writeTimestamp;
+
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+ assertEquals(1, runtime.contextOrThrow(TP).coordinator.lastCommittedOffset());
+ assertTrue(write1.isDone());
+ assertTrue(purgatoryTimeMs > MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(0)).recordEventPurgatoryTime(purgatoryTimeMs);
+ }
+
+ @Test
+ public void testWriteEventCompletesOnce() throws Exception {
Review Comment:
Should we add a similar test for the other event that you updated?
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
Review Comment:
Do we still need this test?
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
+ Duration writeTimeout = Duration.ofMillis(MAX_LATENCY_MS + 1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ writer.commit(TP, 1);
+
+ // We should still have one pending event and the pending high watermark should be updated.
+ assertEquals(1, processor.size());
+ assertEquals(1, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ // Advance the clock past MAX_LATENCY_MS. Recorded event purgatory time should be capped at MAX_LATENCY_MS.
+ timer.advanceClock(MAX_LATENCY_MS + 500L);
+ // Poll once to process the high watermark update and complete the writes.
+ processor.poll();
+ long purgatoryTimeMs = timer.time().milliseconds() - writeTimestamp;
+
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+ assertEquals(1, runtime.contextOrThrow(TP).coordinator.lastCommittedOffset());
+ assertTrue(write1.isDone());
+ assertTrue(purgatoryTimeMs > MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(0)).recordEventPurgatoryTime(purgatoryTimeMs);
+ }
+
+ @Test
+ public void testWriteEventCompletesOnce() throws Exception {
+ // Completes once via timeout, then again with HWM update
Review Comment:
nit: `.`
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "jeffkbkim (via GitHub)" <gi...@apache.org>.
jeffkbkim commented on code in PR #18083:
URL: https://github.com/apache/kafka/pull/18083#discussion_r1876371147
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
+ Duration writeTimeout = Duration.ofMillis(MAX_LATENCY_MS + 1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ writer.commit(TP, 1);
+
+ // We should still have one pending event and the pending high watermark should be updated.
+ assertEquals(1, processor.size());
+ assertEquals(1, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ // Advance the clock past MAX_LATENCY_MS. Recorded event purgatory time should be capped at MAX_LATENCY_MS.
+ timer.advanceClock(MAX_LATENCY_MS + 500L);
+ // Poll once to process the high watermark update and complete the writes.
+ processor.poll();
+ long purgatoryTimeMs = timer.time().milliseconds() - writeTimestamp;
+
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+ assertEquals(1, runtime.contextOrThrow(TP).coordinator.lastCommittedOffset());
+ assertTrue(write1.isDone());
+ assertTrue(purgatoryTimeMs > MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(0)).recordEventPurgatoryTime(purgatoryTimeMs);
+ }
+
+ @Test
+ public void testWriteEventCompletesOnce() throws Exception {
+ // Completes once via timeout, then again with HWM update
+ Duration writeTimeout = Duration.ofMillis(1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
Review Comment:
Moved the limit test to CoordinatorRuntimeMetricsImplTest
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18174: Subsequent write event completions should be a noop [kafka]
Posted by "dimitarndimitrov (via GitHub)" <gi...@apache.org>.
dimitarndimitrov commented on code in PR #18083:
URL: https://github.com/apache/kafka/pull/18083#discussion_r1875537267
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeTest.java:
##########
@@ -4410,6 +4411,138 @@ public void testRecordEventPurgatoryTime() throws Exception {
verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(writeTimeout.toMillis() + 1);
}
+ @Test
+ public void testRecordEventPurgatoryTimeLimit() throws Exception {
+ Duration writeTimeout = Duration.ofMillis(MAX_LATENCY_MS + 1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ writer.commit(TP, 1);
+
+ // We should still have one pending event and the pending high watermark should be updated.
+ assertEquals(1, processor.size());
+ assertEquals(1, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+
+ // Advance the clock past MAX_LATENCY_MS. Recorded event purgatory time should be capped at MAX_LATENCY_MS.
+ timer.advanceClock(MAX_LATENCY_MS + 500L);
+ // Poll once to process the high watermark update and complete the writes.
+ processor.poll();
+ long purgatoryTimeMs = timer.time().milliseconds() - writeTimestamp;
+
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
+ assertEquals(1, runtime.contextOrThrow(TP).coordinator.lastCommittedOffset());
+ assertTrue(write1.isDone());
+ assertTrue(purgatoryTimeMs > MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(1)).recordEventPurgatoryTime(MAX_LATENCY_MS);
+ verify(runtimeMetrics, times(0)).recordEventPurgatoryTime(purgatoryTimeMs);
+ }
+
+ @Test
+ public void testWriteEventCompletesOnce() throws Exception {
+ // Completes once via timeout, then again with HWM update
+ Duration writeTimeout = Duration.ofMillis(1000L);
+ MockTimer timer = new MockTimer();
+ MockPartitionWriter writer = new MockPartitionWriter();
+ ManualEventProcessor processor = new ManualEventProcessor();
+ CoordinatorRuntimeMetrics runtimeMetrics = mock(CoordinatorRuntimeMetrics.class);
+
+ CoordinatorRuntime<MockCoordinatorShard, String> runtime =
+ new CoordinatorRuntime.Builder<MockCoordinatorShard, String>()
+ .withTime(timer.time())
+ .withTimer(timer)
+ .withDefaultWriteTimeOut(writeTimeout)
+ .withLoader(new MockCoordinatorLoader())
+ .withEventProcessor(processor)
+ .withPartitionWriter(writer)
+ .withCoordinatorShardBuilderSupplier(new MockCoordinatorShardBuilderSupplier())
+ .withCoordinatorRuntimeMetrics(runtimeMetrics)
+ .withCoordinatorMetrics(mock(CoordinatorMetrics.class))
+ .withSerializer(new StringSerializer())
+ .withExecutorService(mock(ExecutorService.class))
+ .build();
+
+ // Loads the coordinator. Poll once to execute the load operation and once
+ // to complete the load.
+ runtime.scheduleLoadOperation(TP, 10);
+ processor.poll();
+ processor.poll();
+
+ // write#1 will be committed and update the high watermark. Record time spent in purgatory.
+ CompletableFuture<String> write1 = runtime.scheduleWriteOperation("write#1", TP, writeTimeout,
+ state -> new CoordinatorResult<>(List.of("record1"), "response1")
+ );
+
+ processor.poll();
+
+ // Records have been written to the log.
+ long writeTimestamp = timer.time().milliseconds();
+ assertEquals(Collections.singletonList(
+ records(writeTimestamp, "record1")
+ ), writer.entries(TP));
+
+ // There is no pending high watermark.
+ assertEquals(NO_OFFSET, runtime.contextOrThrow(TP).highWatermarklistener.lastHighWatermark());
Review Comment:
nit: All of this seems to be shared with the previous test. Should we extract it and deduplicate it?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org