Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

zhuchen1018
Copy link
Contributor

No description provided.

@zhuchen1018
Copy link
Contributor Author

@ijuma Do you have time to take a look? Thanks!

@ijuma
Copy link
Contributor

ijuma commented May 4, 2016

Thanks for the PR. The change looks good. The usual question follows: can we include a test please?

@zhuchen1018
Copy link
Contributor Author

@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 finally than testing any kafka-specific logic. If we should add tests for something as straightforward as this, we should probably add test for a bunch of other methods that use finally to enforce something, which doesn't seem feasible. What do you think?

@ijuma
Copy link
Contributor

ijuma commented May 4, 2016

@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.

@onurkaraman
Copy link
Contributor

btw the corresponding ticket is KAFKA-3655, not KAFKA-3651 as the PR title suggests.

@zhuchen1018 zhuchen1018 changed the title KAFKA-3651; awaitFlushCompletion() in RecordAccumulator should always decrement flushesInProgress count KAFKA-3655; awaitFlushCompletion() in RecordAccumulator should always decrement flushesInProgress count May 4, 2016
@zhuchen1018
Copy link
Contributor Author

zhuchen1018 commented May 4, 2016

@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 beginFlush, call awaitFlushCompletion, interrupt the thread, and verify that flushInProgress() == false. Say it is useful to test it, should we similarly test that appendsInProgress does't change before and after RecordAccumulator.append()? Should all future developers who use finally to enforce that the statement in the finally is executed, to always verify this by writing tests for exceptions that may be thrown?

@ijuma
Copy link
Contributor

ijuma commented May 4, 2016

@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 finally works correctly. It's also a bit subjective what is worth testing and what isn't. However, a simple rule is that if we have a bug for something, we should include a test with the fix unless there is a good reason not to (test is brittle, takes too long, too complex, etc.). I think this is a fair rule and it doesn't overburden contributors.

@zhuchen1018
Copy link
Contributor Author

@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 finally, it probably indicates that the benefits of these tests are not worth the developer's time; if this is not worth developer's time who write the feature, then we shouldn't require contributors who fix the bug to write the test. It would be a fair rule to hold developers of the feature to no lower standard than those who help fix their code, right?

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 :)

@ijuma
Copy link
Contributor

ijuma commented May 4, 2016

@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:

  • I think focusing on a language construct (finally) is perhaps the wrong way to think about it. Let's describe the issue as an interruptible method. It is a good idea to have a test that causes the method to be interrupted because this is a common source of bugs (examples are both the issue in this PR and in ByteBuffer.allocate where there were actually multiple bugs and PRs that you were involved with).
  • When someone contributes a new feature, they contribute a bunch of tests and the reviewer tries to ensure that the test coverage is good. This is a bit of a subjective thing at the moment as we don't yet use coverage tools (and they have limits as well). Things will be missed, that's just the nature of it.
  • When someone contributes a bug fix, there is evidence that a test would have been useful so we take that into account.
  • When someone files a PR, it's worth being aware that reviewer time is also limited. Your PR is more likely to be merged faster if it fits the project guidelines.
  • I hope that instead of a growing number of bug fixes, we write code with less bugs. We will see!

OK, that's all I have to say for now. :)

@zhuchen1018
Copy link
Contributor Author

@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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is 1 second enough?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ijuma
Copy link
Contributor

ijuma commented May 6, 2016

Thanks @zhuchen1018, a couple of minor comments. Looks good otherwise. Will merge as soon as they are addressed.

@ijuma
Copy link
Contributor

ijuma commented May 6, 2016

LGTM

@asfgit asfgit closed this in 717eea8 May 6, 2016
asfgit pushed a commit that referenced this pull request May 6, 2016
… 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>
gfodor pushed a commit to AltspaceVR/kafka that referenced this pull request Jun 3, 2016
… decrement flushesInProgress count

Author: Chen Zhu <amandazhu19620701@gmail.com>

Reviewers: Ismael Juma <ismael@juma.me.uk>

Closes apache#1315 from zhuchen1018/KAFKA-3655
efeg added a commit to efeg/kafka that referenced this pull request May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants