-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: Fix Deadlock in StreamThread #2791
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 1 commit
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 |
|---|---|---|
|
|
@@ -189,8 +189,12 @@ public boolean isValidTransition(final State newState) { | |
| return validTransitions.contains(newState.ordinal()); | ||
| } | ||
| } | ||
|
|
||
| private final Object stateLock = new Object(); | ||
|
|
||
| private volatile State state = State.CREATED; | ||
| private StateListener stateListener = null; | ||
|
|
||
| private KafkaStreams.StateListener stateListener = null; | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -208,25 +212,26 @@ public interface StateListener { | |
| } | ||
|
|
||
| /** | ||
| * An app can set a single {@link StateListener} so that the app is notified when state changes. | ||
| * An app can set a single {@link KafkaStreams.StateListener} so that the app is notified when state changes. | ||
| * @param listener a new state listener | ||
| */ | ||
| public void setStateListener(final StateListener listener) { | ||
| public void setStateListener(final KafkaStreams.StateListener listener) { | ||
| stateListener = listener; | ||
| } | ||
|
|
||
| private synchronized void setState(final State newState) { | ||
| final State oldState = state; | ||
| if (!state.isValidTransition(newState)) { | ||
| log.warn("{} Unexpected state transition from {} to {}.", logPrefix, oldState, newState); | ||
| } else { | ||
| log.info("{} State transition from {} to {}.", logPrefix, oldState, newState); | ||
| } | ||
|
|
||
| state = newState; | ||
|
|
||
| if (stateListener != null) { | ||
| stateListener.onChange(state, oldState); | ||
| private void setState(final State newState) { | ||
| synchronized (this.stateLock) { | ||
| final State oldState = state; | ||
| if (!state.isValidTransition(newState)) { | ||
| log.warn( | ||
|
Member
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. Nit: fix line break |
||
| "{} Unexpected state transition from {} to {}.", logPrefix, oldState, newState); | ||
| } else { | ||
| log.info("{} State transition from {} to {}.", logPrefix, oldState, newState); | ||
| } | ||
| state = newState; | ||
| if (stateListener != null) { | ||
| stateListener.onChange(state, oldState); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -248,7 +253,7 @@ public synchronized State state() { | |
| return Collections.unmodifiableMap(metrics.metrics()); | ||
| } | ||
|
|
||
| private class StreamStateListener implements StreamThread.StateListener { | ||
| private final class StreamStateListener implements StreamThread.StateListener { | ||
| @Override | ||
| public synchronized void onChange(final StreamThread thread, | ||
|
Member
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. @dguy @enothereska This
Contributor
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. It looks like there should only be a single
Member
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. Thanks @dguy. That makes sense. @original-brownbear, maybe you can do a follow-up that does that.
Member
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. @ijuma put it on my todos, will get to this in about ~12h :) |
||
| final StreamThread.State newState, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ public boolean isValidTransition(final State newState) { | |
| } | ||
|
|
||
| private volatile State state = State.NOT_RUNNING; | ||
| private StateListener stateListener = null; | ||
| private StreamThread.StateListener stateListener = null; | ||
|
|
||
| /** | ||
| * Listen to state change events | ||
|
|
@@ -141,10 +141,10 @@ public interface StateListener { | |
| } | ||
|
|
||
| /** | ||
| * Set the {@link StateListener} to be notified when state changes. Note this API is internal to | ||
| * Set the {@link StreamThread.StateListener} to be notified when state changes. Note this API is internal to | ||
| * Kafka Streams and is not intended to be used by an external application. | ||
| */ | ||
| public void setStateListener(final StateListener listener) { | ||
| public void setStateListener(final StreamThread.StateListener listener) { | ||
| this.stateListener = listener; | ||
| } | ||
|
|
||
|
|
@@ -463,7 +463,7 @@ private RuntimeException performOnAllTasks(final AbstractTaskAction action, | |
| action.apply(task); | ||
| } catch (RuntimeException t) { | ||
| log.error("{} Failed while executing {} {} due to {}: ", | ||
| StreamThread.this.logPrefix, | ||
| this.logPrefix, | ||
|
Member
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. Nit: also remove |
||
| task.getClass().getSimpleName(), | ||
| task.id(), | ||
| exceptionMessage, | ||
|
|
||
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.
Nit: remove
this