KAFKA-3648; maxTimeToBlock in BufferPool.allocate should be enforced#1304
KAFKA-3648; maxTimeToBlock in BufferPool.allocate should be enforced#1304zhuchen1018 wants to merge 6 commits intoapache:trunkfrom
Conversation
|
Can you do @ijuma Can you take a look? |
|
A minor suggestion, it would be better to use a new variable (maybe It would be good to have a test for this. @lindong28, do you know why we throw a |
|
@ijuma No. It seems that we should record waitTime before TimeoutException is thrown. |
|
Thanks for confirming. It would be good to fix that as part of this PR too. |
|
@ijuma The unit tests have been added and the two issues (a new variable & record waitTime before throwing TimeoutException) have been resolved. Can you take a look? |
|
LGTM |
| assertEquals("Allocation shouldn't have happened yet, waiting on memory.", 1L, allocation.getCount()); | ||
| doDealloc.countDown(); // return the memory | ||
| allocation.await(); | ||
| assertEquals("Allocation should succeed soon after de-allocation", true, allocation.await(1, TimeUnit.SECONDS)); |
There was a problem hiding this comment.
Nitpick: assertTrue can be used instead of assertEquals.
|
Thanks for the updates @zhuchen1018, I left a few more comments. Also, can you please update the PR title to: And the PR description could be: Thanks! |
maxTimeToBlock needs to be updated in each loop iteration. Also record waitTime before throwing TimeoutException.
|
@ijuma I have made changes as suggested. Can you please take another look? Thanks! |
| boolean waitingTimeElapsed = !moreMemory.await(remainingTimeToBlockNs, TimeUnit.NANOSECONDS); | ||
| long endWaitNs = time.nanoseconds(); | ||
| long timeNs = Math.max(0L, endWaitNs - startWaitNs); | ||
| this.waitTime.record(timeNs, TimeUnit.NANOSECONDS.toMillis(endWaitNs)); |
There was a problem hiding this comment.
Sorry, I just realised that what I recommended here is wrong, the second parameter needs to be time.milliseconds().
There was a problem hiding this comment.
@ijuma Do you mean changing this.waitTime.record(timeNs, TimeUnit.NANOSECONDS.toMillis(endWaitNs)) to this.waitTime.record(timeNs, time.milliseconds())? I think the only difference between the two is the time to do long timeNs = Math.max(0L, endWaitNs - startWaitNs), which shouldn't take much time. Do we need this extra accuracy at the cost of one extra system call time.millionseconds()?
There was a problem hiding this comment.
Yes, that's what I mean. The issue is not the accuracy, but that System.nanoTime is not specified to return wall-clock time. So, unfortunately we need time.milliseconds (which is the same as System.currentTimeMillis). My original suggestion had the goal of saving the system call indeed, but that's not possible while maintaining the current semantics. Unfortunately, our Time interface is misleading in this respect (I filed https://issues.apache.org/jira/browse/KAFKA-2607 a while back to improve this).
|
Thanks @zhuchen1018, left two comments (one of them was regarding a mistake on my part). With regards to the PR title and description, it seems like you updated the PR title with what should be the description (Git convention is that the PR title should be short and the description can be longer). |
maxTimeToBlock needs to be updated in each loop iteration. Also record waitTime before throwing TimeoutException.maxTimeToBlock needs to be updated in each loop iteration. Also record waitTime before throwing TimeoutException.KAFKA-3648; maxTimeToBlock in BufferPool.allocate should be enforced
maxTimeToBlock needs to be updated in each loop iteration. Also record waitTime before throwing TimeoutException.KAFKA-3648; maxTimeToBlock in BufferPool.allocate should be enforced`maxTimeToBlock` needs to be updated in each loop iteration. Also record waitTime before throwing `TimeoutException` Author: Chen Zhu <amandazhu19620701@gmail.com> Reviewers: Dong Lin <lindong28@gmail.com>, Ismael Juma <ismael@juma.me.uk> Closes #1304 from zhuchen1018/KAFKA-3648 (cherry picked from commit 94e12a2) Signed-off-by: Ismael Juma <ismael@juma.me.uk>
`maxTimeToBlock` needs to be updated in each loop iteration. Also record waitTime before throwing `TimeoutException` Author: Chen Zhu <amandazhu19620701@gmail.com> Reviewers: Dong Lin <lindong28@gmail.com>, Ismael Juma <ismael@juma.me.uk> Closes apache#1304 from zhuchen1018/KAFKA-3648
maxTimeToBlockneeds to be updated in each loop iteration. Also record waitTime before throwingTimeoutException