-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-19864: Handle TimeoutException from initializeIfNeeded() in StateUpdater Code #20829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1178,6 +1178,36 @@ public void shouldRetryInitializationWhenLockExceptionInStateUpdater() { | |
|
|
||
| verify(task00).initializeIfNeeded(); | ||
| verify(task01).initializeIfNeeded(); | ||
| verify(task00, never()).clearTaskTimeout(); | ||
| verify(task01).clearTaskTimeout(); | ||
| verify(tasks).addPendingTasksToInit( | ||
| argThat(tasksToInit -> tasksToInit.contains(task00) && !tasksToInit.contains(task01)) | ||
| ); | ||
| verify(stateUpdater, never()).add(task00); | ||
| verify(stateUpdater).add(task01); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldRetryInitializationWhenTimeoutExceptionInStateUpdater() { | ||
| final StreamTask task00 = statefulTask(taskId00, taskId00ChangelogPartitions) | ||
| .withInputPartitions(taskId00Partitions) | ||
| .inState(State.RESTORING).build(); | ||
| final StandbyTask task01 = standbyTask(taskId01, taskId01ChangelogPartitions) | ||
| .withInputPartitions(taskId01Partitions) | ||
| .inState(State.RUNNING).build(); | ||
| final TasksRegistry tasks = mock(TasksRegistry.class); | ||
| when(tasks.drainPendingTasksToInit()).thenReturn(Set.of(task00, task01)); | ||
| final TimeoutException timeoutException = new TimeoutException("Timed out!"); | ||
| doThrow(timeoutException).when(task00).initializeIfNeeded(); | ||
| taskManager = setUpTaskManagerWithStateUpdater(StreamsConfigUtils.ProcessingMode.AT_LEAST_ONCE, tasks, false); | ||
|
|
||
| taskManager.checkStateUpdater(time.milliseconds(), noOpResetter); | ||
|
|
||
| verify(task00).initializeIfNeeded(); | ||
| verify(task01).initializeIfNeeded(); | ||
| verify(task00).maybeInitTaskTimeoutOrThrow(anyLong(), eq(timeoutException)); | ||
| verify(task00, never()).clearTaskTimeout(); | ||
| verify(task01).clearTaskTimeout(); | ||
| verify(tasks).addPendingTasksToInit( | ||
| argThat(tasksToInit -> tasksToInit.contains(task00) && !tasksToInit.contains(task01)) | ||
| ); | ||
|
|
@@ -1565,7 +1595,7 @@ private void verifyTransitionToRunningOfRestoredTask(final Set<StreamTask> resto | |
| final TasksRegistry tasks) { | ||
| for (final StreamTask restoredTask : restoredTasks) { | ||
| verify(restoredTask).completeRestoration(noOpResetter); | ||
| verify(restoredTask).clearTaskTimeout(); | ||
| verify(restoredTask, atLeastOnce()).clearTaskTimeout(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this because, one of the tests |
||
| verify(tasks).addTask(restoredTask); | ||
| verify(consumer).resume(restoredTask.inputPartitions()); | ||
| } | ||
|
|
@@ -2872,40 +2902,48 @@ public void shouldAddNewActiveTasks() { | |
|
|
||
| @Test | ||
| public void shouldNotCompleteRestorationIfTasksCannotInitialize() { | ||
| final StreamTask task00 = statefulTask(taskId00, taskId00ChangelogPartitions) | ||
| .withInputPartitions(taskId00Partitions) | ||
| .inState(State.CREATED) | ||
| .build(); | ||
| final StreamTask task01 = statefulTask(taskId01, taskId01ChangelogPartitions) | ||
| .withInputPartitions(taskId01Partitions) | ||
| .inState(State.CREATED) | ||
| .build(); | ||
|
|
||
| final TasksRegistry tasks = mock(TasksRegistry.class); | ||
| final TaskManager taskManager = setUpTaskManagerWithStateUpdater(ProcessingMode.AT_LEAST_ONCE, tasks); | ||
| final Map<TaskId, Set<TopicPartition>> assignment = mkMap( | ||
| mkEntry(taskId00, taskId00Partitions), | ||
| mkEntry(taskId01, taskId01Partitions) | ||
| ); | ||
| final Task task00 = new StateMachineTask(taskId00, taskId00Partitions, true, stateManager) { | ||
| @Override | ||
| public void initializeIfNeeded() { | ||
| throw new LockException("can't lock"); | ||
| } | ||
| }; | ||
| final Task task01 = new StateMachineTask(taskId01, taskId01Partitions, true, stateManager) { | ||
| @Override | ||
| public void initializeIfNeeded() { | ||
| throw new TimeoutException("timed out"); | ||
| } | ||
| }; | ||
|
|
||
| when(activeTaskCreator.createTasks(any(), eq(assignment))).thenReturn(asList(task00, task01)); | ||
|
|
||
| when(activeTaskCreator.createTasks(any(), eq(assignment))) | ||
| .thenReturn(asList(task00, task01)); | ||
| taskManager.handleAssignment(assignment, emptyMap()); | ||
|
|
||
| assertThat(task00.state(), is(Task.State.CREATED)); | ||
| assertThat(task01.state(), is(Task.State.CREATED)); | ||
| verify(tasks).addPendingTasksToInit(asList(task00, task01)); | ||
|
|
||
| assertThat(taskManager.tryToCompleteRestoration(time.milliseconds(), null), is(false)); | ||
| when(tasks.drainPendingTasksToInit()).thenReturn(Set.of(task00, task01)); | ||
| final LockException lockException = new LockException("can't lock"); | ||
| final TimeoutException timeoutException = new TimeoutException("timeout during init"); | ||
| doThrow(lockException).when(task00).initializeIfNeeded(); | ||
| doThrow(timeoutException).when(task01).initializeIfNeeded(); | ||
| when(tasks.hasPendingTasksToInit()).thenReturn(true); | ||
|
|
||
| assertThat(task00.state(), is(Task.State.CREATED)); | ||
| assertThat(task01.state(), is(Task.State.CREATED)); | ||
| assertThat( | ||
| taskManager.activeTaskMap(), | ||
| Matchers.equalTo(mkMap(mkEntry(taskId00, task00), mkEntry(taskId01, task01))) | ||
| ); | ||
| assertThat(taskManager.standbyTaskMap(), Matchers.anEmptyMap()); | ||
| verify(changeLogReader).enforceRestoreActive(); | ||
| final boolean restorationComplete = taskManager.checkStateUpdater(time.milliseconds(), noOpResetter); | ||
|
|
||
| assertFalse(restorationComplete); | ||
| verify(task00).initializeIfNeeded(); | ||
| verify(task01).initializeIfNeeded(); | ||
| verify(task00, never()).maybeInitTaskTimeoutOrThrow(anyLong(), any()); | ||
| verify(task01).maybeInitTaskTimeoutOrThrow(anyLong(), eq(timeoutException)); | ||
| verify(task00, never()).clearTaskTimeout(); | ||
| verify(task01, never()).clearTaskTimeout(); | ||
| verify(tasks).addPendingTasksToInit(Collections.singleton(task00)); | ||
| verify(tasks).addPendingTasksToInit(Collections.singleton(task01)); | ||
| verify(stateUpdater, never()).add(task00); | ||
| verify(stateUpdater, never()).add(task01); | ||
| verifyNoInteractions(consumer); | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment when this can happen: Either during producer initialization, or while fetching committed offset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment in a0e55f0