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

Use AutoCloseable in some places where we previously used SafeCloseable, and standardize some SafeCloseable utilities #5274

Merged
merged 4 commits into from
Mar 21, 2024

Conversation

rcaudy
Copy link
Member

@rcaudy rcaudy commented Mar 21, 2024

In some discussions with @devinrsmith, we realized we could make some of the SafeCloseable code better by allowing AutoCloseable usage in many existing patterns, at no loss of correctness or utility.

@rcaudy rcaudy added core Core development tasks NoDocumentationNeeded NoReleaseNotesNeeded No release notes are needed. labels Mar 21, 2024
@rcaudy rcaudy added this to the 1. March 2024 milestone Mar 21, 2024
@rcaudy rcaudy self-assigned this Mar 21, 2024
Copy link
Member

@devinrsmith devinrsmith left a comment

Choose a reason for hiding this comment

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

Happy with this change as-is, as it moves us in a good direction.

There is a case to be made that, when idempotent, we should prefer implementing Closeable as well.

public class MyIdempotentIterator implements SafeCloseable, Closeable {

We could make a case for:

public interface SafeIdempotentCloseable extends SafeCloseable, Closeable {

to "simplify" the implementations a bit, and a place to add explicit javadoc (of course, maybe we should add more explicit javadoc on SafeCloseable regardless). That said, I don't think it would ever be appropriate to use this interface as an argument type.

// bad
public static void foo(SafeIdempotentCloseable x) { ... }

// good
public static <X extends SafeCloseable, Closeable> void bar(X x) { ... }

* resources that must be released. Such iterators must document this need, and appropriate measures (e.g. a
* try-with-resources block) should be taken to ensure that they are {@link #close() closed}. Methods that return
* streams over CloseableIterator instances should ensure that closing the resulting {@link Stream},
* {@link java.util.stream.IntStream IntStream}, {@link java.util.stream.LongStream LongStream}, or
* {@link java.util.stream.DoubleStream DoubleStream} will also close the iterator.
*/
public interface CloseableIterator<TYPE> extends Iterator<TYPE>, SafeCloseable {
Copy link
Member

Choose a reason for hiding this comment

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

Do we want stricter guarantee of idempotentcy w/ Closeable? Not a blocker. Happy with any answer: yes, no, or yes, but later.


/**
* Iteration support for values supplied by a column.
*
* @apiNote ColumnIterators must be explicitly {@link #close() closed} or used until exhausted in order to avoid
* resource leaks.
*/
public interface ColumnIterator<DATA_TYPE> extends CloseableIterator<DATA_TYPE> {
public interface ColumnIterator<DATA_TYPE> extends CloseableIterator<DATA_TYPE>, SafeCloseable {
Copy link
Member

Choose a reason for hiding this comment

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

Same Q; if we decide that CloseableIterator is not idempotent, we could still make that guarantee here if we wanted to.

Comment on lines +59 to +62
try {
SafeCloseable.closeAll(list.iterator());
} finally {
list.clear();
Copy link
Member

Choose a reason for hiding this comment

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

Should we extend Closeable, given this is a form of idempotency?

@rcaudy rcaudy merged commit dd6ace7 into deephaven:main Mar 21, 2024
20 checks passed
@rcaudy rcaudy deleted the rwc-safe-to-auto branch March 21, 2024 16:13
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core Core development tasks NoDocumentationNeeded NoReleaseNotesNeeded No release notes are needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants