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-5872: Fix transient failure in SslSelectorTest.testMuteOnOOM #3836

Conversation

rajinisivaram
Copy link
Contributor

No description provided.

@rajinisivaram
Copy link
Contributor Author

@radai-rosenblatt @ijuma Can you review, please? Thank you!

Copy link
Contributor

@ijuma ijuma 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. The fix itself is fine, just a few suggestions based on looking at the code around it.

@@ -498,6 +498,7 @@ void pollSelectionKeys(Set<SelectionKey> selectionKeys,

if (!outOfMemory && memoryPool.availableMemory() < lowMemThreshold) {
List<SelectionKey> temp = new ArrayList<>(selectionKeys);
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't look like we need this temp variable. We can just assign it to inHandlingOrder directly, right? Also, using an ArrayList seems suboptimal given that we call remove on each element during iteration (each time shifting all the elements). ArrayDeque would work well if we didn't remove via the Iterator. Maybe we should change pollSelectionKeys to clear the collection at the end instead?

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 think the temp was possibly added since Collections.shuffle() needs a list. I have left that as-is. Since we only need to clear the selected key set, I have added clear to the end of poll() and got rid of Iterator.remove. It makes the code clearer as well.

@@ -498,6 +498,7 @@ void pollSelectionKeys(Set<SelectionKey> selectionKeys,

if (!outOfMemory && memoryPool.availableMemory() < lowMemThreshold) {
List<SelectionKey> temp = new ArrayList<>(selectionKeys);
selectionKeys.clear(); // needed for next `select` to count these keys
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd mention in the comment that we normally remove from selectionKeys during iteration, but since we are making a copy here, we need to clear it manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this change.

@rajinisivaram
Copy link
Contributor Author

@ijuma Thanks for the review, I have updated the code.

@@ -409,6 +409,9 @@ public void poll(long timeout) throws IOException {
// Add to completedReceives after closing expired connections to avoid removing
// channels with completed receives until all staged receives are completed.
addToCompletedReceives();

// Clear all selected keys so that they are included in the ready count for the next select
this.nioSelector.selectedKeys().clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to do this right after the last pollSelectionKeys? We can even just do readyKeys.clear() then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pollSelectionKeys is called multiple times with different key sets. Not all of them need clearing. We only really need to clear nioSelector.selectedKeys(). I thought it was clearer this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Misread the comment earlier, updated.

@rajinisivaram rajinisivaram force-pushed the KAFKA-5872-sslselectortest-failure branch from e8faa81 to a938fb7 Compare September 12, 2017 14:03
Copy link
Contributor

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

@rajinisivaram
Copy link
Contributor Author

@ijuma Thank you for the review, merging to trunk.

@asfgit asfgit closed this in 9ed8bf2 Sep 12, 2017
@radai-rosenblatt
Copy link
Contributor

LGTM, batch clearing is probably more efficient to boot

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