-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
KAFKA-3655; awaitFlushCompletion() in RecordAccumulator should always decrement flushesInProgress count #1315
Conversation
… decrement flushesInProgress count
@ijuma Do you have time to take a look? Thanks! |
Thanks for the PR. The change looks good. The usual question follows: can we include a test please? |
@ijuma It is possible to write a test case for this. But I don't feel its value is worth the extra code here in this particular case. Adding unit tests for bug fixes is useful to make sure that we will not have the same bug again in the future. And it is generally for detecting bugs that is not evident by simply looking at the code. However, the bug fixed in this patch is really straightforward and shouldn't happen again if anyone change this method in the future. A unit test for this bug should validate that flushesInProgress is decremented in the event of InterruptedException, which is essentially testing the usage of |
@zhuchen1018, The fact that the bug exists in the first place implies that a test is worth it. Why do you think we can't regress on this? The code could be refactored and anything can happen at that point. Unless the test is slow or particularly complex, I don't see the harm in adding it. |
btw the corresponding ticket is KAFKA-3655, not KAFKA-3651 as the PR title suggests. |
@ijuma Thanks for the explanation. I agree a test can be useful here. I am going to write test for this particular patch. But I would like to discuss it a bit more to understand the best practice for adding tests in kafka , which hopefully can encourage more contributions in the open source community. I think Kafka open source community should probably have a uniform standard for what should be tested. The standard should be enforced consistently for at least new patches. Bug is good for detecting something that were missed by originally developers and reviewers; once a bug is detected, we should start to require higher standard for tests by original developers so that similar issues can be covered in the future. Does this sound reasonable? For this particular patch, I suppose that we can add a test like this: call |
@zhuchen1018 I agree that it would be good to be consistent around this. Your description regarding tests for bugs sounds reasonable to me. We should also do better on requiring good test coverage for new work (it's a process and it will take some time before we have a clear process for this). For this PR, I'm happy if you add the first test you described. As you said in another comment, we could write tests for a lot of tests if we want to ensure that our |
@ijuma Sure, I certainly agree that it is a good principle and common to "add test for a bug". Because the fact that there is a bug indicates this is probably hard to detect. But I feel that, if we couldn't require developers who originally write these code to add test for It would be good to take cost of time into account and be consistent about a standard for test since there will be growing number of these bug fixes moving forward. The argument I make here is for long term development rather than trying to avoid adding test for a specific bug :) |
@zhuchen1018 I think we're going in circles a bit. I'll leave some thoughts and if you want to discuss the topic more generally, then please start a mailing list thread. So here it goes:
OK, that's all I have to say for now. :) |
@ijuma Thanks again for the review and explanation. I have added unit test. Can you take a look? |
|
||
accum.beginFlush(); | ||
assertTrue(accum.flushInProgress()); | ||
delayedInterrupt(Thread.currentThread(), 2000L); |
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.
Is 1 second enough?
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.
@ijuma Are you talking about the maxBlockTimeMs
? It should not matter since buffer should be allocated immediately for accum.append(...)
, right?
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.
I was talking about the delayed interrupt time. Ideally, the shorter it is, the faster the test terminates. So I thought we could use 1s instead of 2s.
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.
I see. 1 sec should be enough. Fixed now.
Thanks @zhuchen1018, a couple of minor comments. Looks good otherwise. Will merge as soon as they are addressed. |
LGTM |
… decrement flushesInProgress count Author: Chen Zhu <amandazhu19620701@gmail.com> Reviewers: Ismael Juma <ismael@juma.me.uk> Closes #1315 from zhuchen1018/KAFKA-3655 (cherry picked from commit 717eea8) Signed-off-by: Ismael Juma <ismael@juma.me.uk>
… decrement flushesInProgress count Author: Chen Zhu <amandazhu19620701@gmail.com> Reviewers: Ismael Juma <ismael@juma.me.uk> Closes apache#1315 from zhuchen1018/KAFKA-3655
…oop implementation. (apache#1315)
No description provided.