Skip to content

MINOR: factor state checks into descriptive methods and clarify javadocs#11123

Merged
ableegoldman merged 2 commits intoapache:trunkfrom
ableegoldman:MINOR-factor-state-checks-into-descriptive-methods
Jul 26, 2021
Merged

MINOR: factor state checks into descriptive methods and clarify javadocs#11123
ableegoldman merged 2 commits intoapache:trunkfrom
ableegoldman:MINOR-factor-state-checks-into-descriptive-methods

Conversation

@ableegoldman
Copy link
Copy Markdown
Member

Just a bit of minor cleanup that (a) does some prepwork for another PR I'm working on, (b) updates the javadocs & exception messages to report a more useful error to the user and describe what they actually need to do, and (c) hopefully makes these state checks more future-proof by defining methods for each kind of check in one place that can be easily updated instead of tracking down every individual check.

return equals(NOT_RUNNING) || equals(ERROR);
}

public boolean hasStartedOrFinishedShuttingDown() {
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.

Technically this one is not used anywhere yet, but I intend to use it in #10788 so I just went ahead and added it here. Happy to remove it until it's actually needed if anyone prefers

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.

Maybe have it be isShuttingDown() || hasStartedOrFinishedShuttingDown() to be less brittle?

}
} else {
throw new IllegalStateException("Can only set UncaughtExceptionHandler in CREATED state. " +
throw new IllegalStateException("Can only set UncaughtExceptionHandler before calling start(). " +
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.

I feel we've had a number of users be confused by this error message before, because they don't know what it actually means for the state to be CREATED -- a more useful exception would be to describe what they did wrong/need to do right to fix this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree!

@ableegoldman
Copy link
Copy Markdown
Member Author

Call for review on this minor cleanup PR to make the state handling a bit more clear and (hopefully) safe -- @wcarlson5 @mjsax @lct45 @cadonna @showuon

Copy link
Copy Markdown
Member

@showuon showuon left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the refactor!

Comment on lines -1565 to +1585
* @throws StreamsNotStartedException If Streams state is {@link KafkaStreams.State#CREATED CREATED}. Just
* retry and wait until to {@link KafkaStreams.State#RUNNING RUNNING}.
* @throws StreamsNotStartedException If Streams has not yet been started. Just call {@link KafkaStreams#start()}
* and then retry this call.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch! We actually allow REBALANCING and RUNNING state in this method.

}
} else {
throw new IllegalStateException("Can only set UncaughtExceptionHandler in CREATED state. " +
throw new IllegalStateException("Can only set UncaughtExceptionHandler before calling start(). " +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree!

* Calling this method triggers a restore of local {@link StateStore}s on the next {@link #start() application start}.
*
* @throws IllegalStateException if this {@code KafkaStreams} instance is currently {@link State#RUNNING running}
* @throws IllegalStateException if this {@code KafkaStreams} instance has been started and hasn't fully shut down
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Copy Markdown
Contributor

@wcarlson5 wcarlson5 left a comment

Choose a reason for hiding this comment

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

LGTM

return equals(NOT_RUNNING) || equals(ERROR);
}

public boolean hasStartedOrFinishedShuttingDown() {
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.

Maybe have it be isShuttingDown() || hasStartedOrFinishedShuttingDown() to be less brittle?

@ableegoldman ableegoldman merged commit 246a8af into apache:trunk Jul 26, 2021
xdgrulez pushed a commit to xdgrulez/kafka that referenced this pull request Dec 22, 2021
…ocs (apache#11123)

Just a bit of minor cleanup that (a) does some prepwork for another PR I'm working on, (b) updates the javadocs & exception messages to report a more useful error to the user and describe what they actually need to do, and (c) hopefully makes these state checks more future-proof by defining methods for each kind of check in one place that can be easily updated instead of tracking down every individual check.

Reviewers: Walker Carlson <wcarlson@confluent.io>, Luke Chen <showuon@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants