-
Notifications
You must be signed in to change notification settings - Fork 1
KAFKA-9113: StreamTask unit test #9
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
Changes from all commits
cd1fdc8
42f7905
4d7dcaa
2a98168
d1fbf9e
caa7dd2
02f5588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,11 +207,11 @@ boolean allPartitionsBuffered() { | |
| public void close() { | ||
| clear(); | ||
| partitionQueues.clear(); | ||
| streamTime = RecordQueue.UNKNOWN; | ||
|
Owner
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. @mjsax this is to skip resetting the partition time so that we do not need to re-initialize metadata upon resuming again. |
||
| } | ||
|
|
||
| public void clear() { | ||
| nonEmptyQueuesByTime.clear(); | ||
| streamTime = RecordQueue.UNKNOWN; | ||
| for (final RecordQueue queue : partitionQueues.values()) { | ||
| queue.clear(); | ||
| } | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,58 +79,69 @@ public boolean isActive() { | |
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * @throws StreamsException fatal error, should close the thread | ||
| */ | ||
| @Override | ||
| public void initializeIfNeeded() { | ||
| if (state() == State.CREATED) { | ||
| initializeStateStores(); | ||
| TaskUtils.registerStateStores(id, log, logPrefix, topology, stateMgr, stateDirectory, processorContext); | ||
|
|
||
| // no topology needs initialized, we can transit to RUNNING | ||
| // right after registered the stores | ||
| transitionTo(State.RESTORING); | ||
| transitionTo(State.RUNNING); | ||
|
|
||
| processorContext.initialize(); | ||
|
|
||
| log.debug("Initialized"); | ||
| } | ||
| } | ||
|
|
||
| private void initializeStateStores() { | ||
| TaskUtils.registerStateStores(topology, stateDirectory, id, logPrefix, log, processorContext, stateMgr); | ||
|
|
||
| processorContext.initialize(); | ||
| } | ||
|
|
||
| @Override | ||
| public void completeInitializationAfterRestore() { | ||
| throw new IllegalStateException("StandbyTask " + id + " should already be in running state."); | ||
| public void completeRestoration() { | ||
| throw new IllegalStateException("Standby task " + id + " should never be completing restoration"); | ||
| } | ||
|
|
||
| @Override | ||
| public void suspend() { | ||
| log.debug("No-op suspend."); | ||
| log.trace("No-op suspend with state {}", state()); | ||
| } | ||
|
|
||
| @Override | ||
| public void resume() { | ||
| log.debug("No-op resume"); | ||
| log.trace("No-op resume with state {}", state()); | ||
| } | ||
|
|
||
| /** | ||
| * <pre> | ||
| * - flush store | ||
| * - checkpoint store | ||
| * </pre> | ||
| * 1. flush store | ||
| * 2. write checkpoint file | ||
| * | ||
| * @throws TaskMigratedException all the task has been migrated | ||
| * @throws StreamsException fatal error, should close the thread | ||
| */ | ||
| @Override | ||
| public void commit() { | ||
| if (state() == State.RUNNING) { | ||
| stateMgr.flush(); | ||
| switch (state()) { | ||
| case RUNNING: | ||
| stateMgr.flush(); | ||
|
|
||
| // since there's no written offsets we can checkpoint with empty map, | ||
| // and the state current offset would be used to checkpoint | ||
| stateMgr.checkpoint(Collections.emptyMap()); | ||
| // since there's no written offsets we can checkpoint with empty map, | ||
| // and the state current offset would be used to checkpoint | ||
| stateMgr.checkpoint(Collections.emptyMap()); | ||
|
|
||
| log.debug("Committed"); | ||
| break; | ||
|
|
||
| case CLOSING: | ||
| // do nothing and also not throw | ||
| log.trace("Skip committing since task is closing"); | ||
|
|
||
| break; | ||
|
|
||
| default: | ||
| throw new IllegalStateException("Illegal state " + state() + " while committing standby task " + id); | ||
|
|
||
| log.debug("Committed"); | ||
| } else { | ||
| throw new IllegalStateException("Illegal state " + state() + " while committing standby task " + id); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -145,37 +156,29 @@ public void closeDirty() { | |
| } | ||
|
|
||
| /** | ||
| * 1. when unclean close, we do not need to commit; | ||
| * 2. when unclean close, we do not throw any exception; | ||
| * 1. commit if we are running and clean close; | ||
| * 2. close the state manager. | ||
| * | ||
| * @throws TaskMigratedException all the task has been migrated | ||
| * @throws StreamsException fatal error, should close the thread | ||
| */ | ||
| private void close(final boolean clean) { | ||
| switch (state()) { | ||
| case CREATED: | ||
| transitionTo(State.CLOSING); | ||
| // the task is created and not initialized, do nothing | ||
| break; | ||
|
|
||
| case RUNNING: | ||
| // No resources are destroyed here, so we can do this before transit to CLOSING | ||
| if (clean) { | ||
| if (state() == State.CREATED) { | ||
| // the task is created and not initialized, do nothing | ||
| transitionTo(State.CLOSING); | ||
| } else { | ||
| if (state() == State.RUNNING) { | ||
| if (clean) | ||
| commit(); | ||
| } | ||
|
|
||
| transitionTo(State.CLOSING); | ||
| } | ||
|
|
||
| try { | ||
| TaskUtils.closeStateManager(log, logPrefix, stateMgr, stateDirectory, id); | ||
| } catch (final RuntimeException error) { | ||
| if (clean) { | ||
|
Owner
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. This is merged into TaskUtils.closeStateManager |
||
| throw error; | ||
| } else { | ||
| log.warn("Closing standby task " + id + " uncleanly throws an exception " + error); | ||
| } | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| if (state() == State.CLOSING) { | ||
| TaskUtils.closeStateManager(id, log, logPrefix, clean, stateMgr, stateDirectory); | ||
| } else { | ||
| throw new IllegalStateException("Illegal state " + state() + " while closing standby task " + id); | ||
| } | ||
| } | ||
|
|
||
| closeTaskSensor.record(); | ||
|
|
||
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.
Further simplified this transition -- suspended must first transit to restoring and then running.