Skip to content

KAFKA-7477: Improve Streams close timeout semantics#5747

Merged
mjsax merged 13 commits intoapache:trunkfrom
nizhikov:KAFKA-7477
Oct 9, 2018
Merged

KAFKA-7477: Improve Streams close timeout semantics#5747
mjsax merged 13 commits intoapache:trunkfrom
nizhikov:KAFKA-7477

Conversation

@nizhikov
Copy link
Copy Markdown
Contributor

@nizhikov nizhikov commented Oct 5, 2018

Second part of KIP-358.

This changes based on previous PR discussion.

Default close timeout is 30 seconds.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@nizhikov nizhikov changed the title KAFKA-7477 KAFKA-7477: Improve Streams close timeout semantics Oct 5, 2018
@nizhikov
Copy link
Copy Markdown
Contributor Author

nizhikov commented Oct 5, 2018

Hello, @vvcephei.

Can you take a look?

@nizhikov
Copy link
Copy Markdown
Contributor Author

nizhikov commented Oct 5, 2018

Tests passed.

@mjsax Can you take a look?

@mjsax mjsax added the streams label Oct 5, 2018
Copy link
Copy Markdown
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 for the PR. We need to preserve existing semantics. I guess, the simplest way will be, to introduce a private synchronized boolean close(final long timeout, final TimeUnit timeUnit, boolean newSemantics) and call it with true/false from new and old close(). The newSemantics flag can be passed into waitOnState() (or we duplicate the old one as waitOnStateBlocking that we only call for newSemantics==false?

If there is another more elegant way, we can do it differently, too. Just an idea.

Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java

private static final String JMX_PREFIX = "kafka.streams";
private static final int DEFAULT_CLOSE_TIMEOUT = 0;
private static final int DEFAULT_CLOSE_TIMEOUT = 30;
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.

Why this change?

Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
@mjsax
Copy link
Copy Markdown
Member

mjsax commented Oct 5, 2018

We should also add a test KafkaStreamsTest to test that the new method throws for negative values and does not block for zero (ie, please add two tests)

@nizhikov
Copy link
Copy Markdown
Contributor Author

nizhikov commented Oct 7, 2018

Hello, @mjsax

Looks like a didn't understand initial task properly :)
Thank you for the clarification!

  1. waitOnState reworked.
  2. Tests added.
  3. Current methods behaviour preserved.

Please, take a look.

@nizhikov
Copy link
Copy Markdown
Contributor Author

nizhikov commented Oct 7, 2018

Failure unrelated.

Retest this, please.

while (state != targetState) {
if (waitMs == 0) {
if (newSemantics)
return false;
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.

Nit: every conditional needs to have braces (per the code style)

not nit: I find this logic a little difficult to follow. Contrary to what @mjsax suggested, wouldn't it be pretty straightforward to map the old semantics on to the new ones like this:

  • negative numbers => 0
  • 0 => Long.MAX_VALUE
  • all other arguments stay the same
    ?

Then, the old close method could just transform its arguments and call the new method, with no need to have this "new semantics" flag and an early return in the middle of the loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vvcephei I like your proposal. Thanks!
Changed PR according to it.

Copy link
Copy Markdown
Contributor

@vvcephei vvcephei left a comment

Choose a reason for hiding this comment

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

Thanks for the update; this seems easier to follow to me. I had one more question...

Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java Outdated
Copy link
Copy Markdown
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 for updating the PR. Some more comments.

Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java Outdated
Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java Outdated
Comment thread streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java Outdated
@nizhikov
Copy link
Copy Markdown
Contributor Author

nizhikov commented Oct 8, 2018

@mjsax @vvcephei

Thanks for the review.
I addressed all your comments.

Copy link
Copy Markdown
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.

LGTM. Waiting for second +1 before merging.

@nizhikov
Copy link
Copy Markdown
Contributor Author

nizhikov commented Oct 8, 2018

Hello @guozhangwang @bbejeck

I've got +1 from @mjsax and need one more :)
Can you take a look at my PR?

Copy link
Copy Markdown
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

LGTM

@guozhangwang
Copy link
Copy Markdown
Contributor

LGTM!

@mjsax mjsax merged commit 6d16879 into apache:trunk Oct 9, 2018
mjsax pushed a commit that referenced this pull request Oct 9, 2018
Reviewers: Matthias J. Sax <matthias@confluent.io>, John Roesler <john@confluent.io>, Bill Bejeck <bill@confluent.io>, Guozhang Wang <guozhang@confluent.io>
@mjsax
Copy link
Copy Markdown
Member

mjsax commented Oct 9, 2018

Merged to trunk and cherry-picked to 2.1 branch.

pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
Reviewers: Matthias J. Sax <matthias@confluent.io>, John Roesler <john@confluent.io>, Bill Bejeck <bill@confluent.io>, Guozhang Wang <guozhang@confluent.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants