Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -30,27 +30,35 @@ public class TaskMigratedException extends StreamsException {

private final Task task;

public TaskMigratedException(final Task task) {
this(task, null);
// this is for unit test only
public TaskMigratedException() {
super("A task has been migrated unexpectedly", null);

this.task = null;
}

public TaskMigratedException(final Task task,
final TopicPartition topicPartition,
final long endOffset,
final long pos) {
super(String.format("Log end offset of %s should not change while restoring: old end offset %d, current offset %d%n%s",
super(String.format("Log end offset of %s should not change while restoring: old end offset %d, current offset %d",
topicPartition,
endOffset,
pos,
task.toString("> ")),
pos),
null);

this.task = task;
}

public TaskMigratedException(final Task task) {
super(String.format("Task %s is unexpectedly closed during processing", task.id()), null);

this.task = task;
}

public TaskMigratedException(final Task task,
final Throwable throwable) {
super(task.toString(), throwable);
super(String.format("Client request for task %s has been fenced due to a rebalance", task.id()), throwable);

this.task = task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ private void addRecordsToTasks(final ConsumerRecords<byte[], byte[]> records) {
final StreamTask task = taskManager.activeTask(partition);

if (task.isClosed()) {
log.warn("Stream task {} is already closed, probably because it got unexpectedly migrated to another thread already. " +
log.info("Stream task {} is already closed, probably because it got unexpectedly migrated to another thread already. " +
"Notifying the thread to trigger a new rebalance immediately.", task.id());
throw new TaskMigratedException(task);
}
Expand Down Expand Up @@ -1032,7 +1032,7 @@ private void maybeUpdateStandbyTasks(final long now) {
final StandbyTask task = taskManager.standbyTask(partition);

if (task.isClosed()) {
log.warn("Standby task {} is already closed, probably because it got unexpectly migrated to another thread already. " +
log.info("Standby task {} is already closed, probably because it got unexpectedly migrated to another thread already. " +
"Notifying the thread to trigger a new rebalance immediately.", task.id());
throw new TaskMigratedException(task);
}
Expand Down Expand Up @@ -1065,7 +1065,7 @@ private void maybeUpdateStandbyTasks(final long now) {
}

if (task.isClosed()) {
log.warn("Standby task {} is already closed, probably because it got unexpectedly migrated to another thread already. " +
log.info("Standby task {} is already closed, probably because it got unexpectedly migrated to another thread already. " +
"Notifying the thread to trigger a new rebalance immediately.", task.id());
throw new TaskMigratedException(task);
}
Expand All @@ -1084,7 +1084,7 @@ private void maybeUpdateStandbyTasks(final long now) {
final StandbyTask task = taskManager.standbyTask(partition);

if (task.isClosed()) {
log.warn("Standby task {} is already closed, probably because it got unexpectly migrated to another thread already. " +
log.info("Standby task {} is already closed, probably because it got unexpectedly migrated to another thread already. " +
"Notifying the thread to trigger a new rebalance immediately.", task.id());
throw new TaskMigratedException(task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void shouldCloseTaskOnSuspendWhenRuntimeException() {
public void shouldCloseTaskOnSuspendIfTaskMigratedException() {
mockTaskInitialization();
t1.suspend();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand Down Expand Up @@ -226,7 +226,7 @@ public void shouldCloseTaskOnResumeSuspendedIfTaskMigratedException() {
mockRunningTaskSuspension();
t1.resume();
t1.initializeTopology();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand Down Expand Up @@ -267,7 +267,7 @@ public void shouldCommitRunningTasks() {
public void shouldCloseTaskOnCommitIfTaskMigratedException() {
mockTaskInitialization();
t1.commit();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand Down Expand Up @@ -319,7 +319,7 @@ public void shouldCloseTaskOnMaybeCommitIfTaskMigratedException() {
mockTaskInitialization();
EasyMock.expect(t1.commitNeeded()).andReturn(true);
t1.commit();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand All @@ -338,7 +338,7 @@ public void shouldCloseTaskOnMaybeCommitIfTaskMigratedException() {
public void shouldCloseTaskOnProcessesIfTaskMigratedException() {
mockTaskInitialization();
t1.process();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand Down Expand Up @@ -370,7 +370,7 @@ public void shouldPunctuateRunningTasks() {
public void shouldCloseTaskOnMaybePunctuateStreamTimeIfTaskMigratedException() {
mockTaskInitialization();
t1.maybePunctuateStreamTime();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand All @@ -390,7 +390,7 @@ public void shouldCloseTaskOnMaybePunctuateSystemTimeIfTaskMigratedException() {
mockTaskInitialization();
EasyMock.expect(t1.maybePunctuateStreamTime()).andReturn(true);
t1.maybePunctuateSystemTime();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
EasyMock.expectLastCall().andThrow(new TaskMigratedException());
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
Expand Down