-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[HUDI-9219] Add callbacks for CloseableIterators and eager close data readers #13178
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
base: master
Are you sure you want to change the base?
[HUDI-9219] Add callbacks for CloseableIterators and eager close data readers #13178
Conversation
…ook for HoodieData
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.
LGTM. just 1 minor suggestion.
good job chasing down all the resource closing gaps.
private final Iterator<T> inner; | ||
private boolean isClosed = false; | ||
|
||
public WrappedIterator(Iterator<T> inner) { |
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.
hwo about CloseValidationIterator
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.
updated
@@ -628,6 +628,8 @@ public boolean hasNext() { | |||
try { | |||
// NOTE: This is required for idempotency | |||
if (eof) { | |||
// eagerly close | |||
close(); |
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.
we have these eagerly close, do we still need to invoke the Iterator.close
outside? Looks the logic is redundant.
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.
This helps proactively free up resources if all elements are read, especially in places that try with resources was missed or if the close is in a later callback. If the iterator is closed without going through all of the elements, it will hit the close
method to ensure that the input stream is still closed
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.
yeah, understand, but eager close is not often used in code, I suggest we remove it and unify the code to AutoClosable
and try-resource
for resource releasing.
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 don't see any issue in doing both of these things. What is the main concern for this added level of safety?
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.
The iterator is designed to be no side effect actually, we breaks it already for introducing ClosableIterator
, and not we breaks the rule silently during the iteration which I think is not a very good convention to follow.
Change Logs
Impact
Risk level (write none, low medium or high below)
Low
Documentation Update
Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".
ticket number here and follow the instruction to make
changes to the website.
Contributor's checklist