Skip to content

Comments

MINOR: Replace generic Task type with StreamTask and StandbyTask#21502

Merged
mjsax merged 3 commits intoapache:trunkfrom
Nikita-Shupletsov:minor-use-stream-and-standby-tasks
Feb 19, 2026
Merged

MINOR: Replace generic Task type with StreamTask and StandbyTask#21502
mjsax merged 3 commits intoapache:trunkfrom
Nikita-Shupletsov:minor-use-stream-and-standby-tasks

Conversation

@Nikita-Shupletsov
Copy link
Contributor

@Nikita-Shupletsov Nikita-Shupletsov commented Feb 18, 2026

This PR improves type safety by replacing the generic Task type with
StreamTask and StandbyTask. As a side effect, we can avoid unnecessary
casts, usage of instanceof, or checking the task type via .isActiveTask.

Reviewers: Matthias J. Sax matthias@confluent.io

@github-actions github-actions bot added triage PRs from the community streams labels Feb 18, 2026
@mjsax mjsax added ci-approved and removed triage PRs from the community labels Feb 18, 2026
Copy link
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

Great cleanup! It makes me very happy to see all these unnecessary casts and instanceof stuff and others boiler plat go away!

// TODO: convert to StreamTask when we remove TaskManager#StateMachineTask with mocks
public Collection<Task> createTasks(final Consumer<byte[], byte[]> consumer,
public Collection<StreamTask> createTasks(final Consumer<byte[], byte[]> consumer,
final Map<TaskId, Set<TopicPartition>> tasksToBeCreated) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: fix indention

private Collection<Task> tryCloseCleanActiveTasks(final Collection<Task> activeTasksToClose,
private Collection<StreamTask> tryCloseCleanActiveTasks(final Collection<StreamTask> activeTasksToClose,
final boolean clean,
final AtomicReference<RuntimeException> firstException) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: fix indention

private Collection<Task> tryCloseCleanStandbyTasks(final Collection<Task> standbyTasksToClose,
private Collection<StandbyTask> tryCloseCleanStandbyTasks(final Collection<StandbyTask> standbyTasksToClose,
final boolean clean,
final AtomicReference<RuntimeException> firstException) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: fix intention

}

if (standbyTasksPerId.containsKey(taskId)) {
throw new IllegalStateException("Attempted to create an active task while we already own its standby: " + taskId);
Copy link
Member

Choose a reason for hiding this comment

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

Both original error messages say Attempted to create an active task -- so wondering why the original method is called addTask? Or was the original message not fully correct to begin with? In the end, we cannot have active and standby (with task task-id) at the same time, but it goes both ways. So it would also be a valid error message to say Attempted to create an standby task...?

Also, by extracting checkTaskDoesNotExist(), we actually get a single more general error message -- given that checkTaskDoesNotExist() is very short, might be better to keep the code inlined, and use two different error messages.

Copy link
Contributor Author

@Nikita-Shupletsov Nikita-Shupletsov Feb 18, 2026

Choose a reason for hiding this comment

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

yeah, there was addActiveTask with these errors, then it became a more generic addTask method, but the errors stayed the same

sounds good. will do

Copy link
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM. Can merge if CI passes.

private Stream<Task> activeTaskStream() {
return Stream.concat(
activeRunningTaskStream(),
stateUpdater.tasks().stream().filter(Task::isActive)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not 100% if stateUpdater.tasks() needs to return ReadOnlyTask. or maybe we should have a separate method to get all active tasks to call it here, as we do for standby tasks

@mjsax mjsax changed the title MINOR: Implement TODOs to use StreamTask and StandbyTask whenever it's possible. MINOR: Replace generic Task type with StreamTask and StandbyTask Feb 19, 2026
@mjsax mjsax merged commit 4297d99 into apache:trunk Feb 19, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants