Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.apache.kafka.streams.processor.internals;

import java.time.Duration;
import java.util.List;

public interface StateUpdater {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An implementation of the state updater is passed to the task manager in its constructor. Since the threading model of the state updater is encapsulated and one can pass the same state updater to multiple task managers there is no fixed 1:1 relationship between a restoration thread and a stream thread.


/**
* Adds a task (active or standby) to the state updater.
*
* The state of the task will be updated.
*
* @param task task
*/
void add(final Task task);

@cadonna cadonna Nov 15, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each time an active or standby task transits to state RESTORING it needs to be added to the state updater.


/**
* Removes a task (active and standby) from the state updater.
*
* A task is removed from the state updater irrespective of whether its state is up-to-date or not.
*
* @param task tasks to remove
*/
void remove(final Task task);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each time a task is suspended in state RESTORING, we need to remove it from the state updater.


/**
* Gets restored active tasks from state restoration/update
*
* @param timeout duration how long the calling thread should wait for restored active tasks
*
* @return list of active tasks with up-to-date states
*/
List<StreamTask> getRestoredActiveTasks(final Duration timeout);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the restoration of an active task is completed, the task is returned call to this method. The calling thread can decide how long to wait for the next restored active tasks.


/**
* Gets a list of tasks that failed during restoration.
*
* The exception that caused the failure can be retrieved by {@link Task#getException()}
*
* @return failed tasks
*/
List<Task> getFailedTasks();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a task fails during restoration it is returned by this method. The exception that caused the failure can be retrieved from the task itself with Task#getException().


/**
* Shuts down the state updater.
*
* @param timeout duration how long to wait until the state updater is shut down
*/
void shutdown(final Duration timeout);
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,11 @@ default boolean commitRequested() {
* @return This returns the time the task started idling. If it is not idling it returns empty.
*/
Optional<Long> timeCurrentIdlingStarted();

/**
* Gets the exception that caused the failure of the task.
*
* @return exception that caused the failure of the task
*/
Optional<RuntimeException> getException();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can narrow down the scope of this exception, if it is only going to be used during restoration time. But nevertheless we can discuss about this later.

}