Skip to content

Free up the resources when materializing the results as Frames#15032

Merged
LakshSingla merged 5 commits intoapache:masterfrom
LakshSingla:clean-resource
Oct 5, 2023
Merged

Free up the resources when materializing the results as Frames#15032
LakshSingla merged 5 commits intoapache:masterfrom
LakshSingla:clean-resource

Conversation

@LakshSingla
Copy link
Contributor

@LakshSingla LakshSingla commented Sep 25, 2023

Description

RowWalker doesn't explicitly clean up the resources over the sequence that it acquires. Therefore, queries acquiring resources like the merge buffers fail to clean up the resources after they are done with it. This PR refactors the code to clean up the result sequences when materializing the results as Frames.

The original PR that added this feature had a failing test that we ignored for the time being since we weren't seeing it in testing, and assumed that it might have been an issue with the TestBuffers class, however after facing this again, and investigating it uncovered the reason why the resources weren't getting cleaned up.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

*/
public interface CloseableCursor extends Cursor, Closeable
{
static CloseableCursor cursorWithCloseable(Cursor cursor, Closeable closeable)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this interface to have a cursor which can be closed.

From this close call, it seems like the cursor is untouched but we want to close the rowWalker ?

RowWalker<Object[]> rowWalker = new RowWalker<>(Sequences.simple(rows), rowAdapter);
return new RowBasedCursor<>(

RowWalker<Object[]> rowWalker = new RowWalker<>(rows, rowAdapter);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you need to close the RowWalker, why don't you change RowBasedCursor and add a closeable to it.

In its close method, call rowWalker.close().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revisiting this comment, it doesn't seem fair that the RowBasedCursor should close the rowWalker that was passed to it by the caller. The caller should close the rowWalker.

Either the method getCursorFromSequence should return a Pair<Cursor, Closeable> or I will rename CloseableCursor to CursorWithCloseable

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets return a pair<Cursor,Closeable> in that case.

@LakshSingla LakshSingla added this to the 28.0 milestone Oct 3, 2023
Copy link
Contributor

@cryptoe cryptoe left a comment

Choose a reason for hiding this comment

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

Changes LGTM. Thanks @LakshSingla

@LakshSingla LakshSingla merged commit b8d03d3 into apache:master Oct 5, 2023
@LakshSingla LakshSingla deleted the clean-resource branch October 5, 2023 04:44
ektravel pushed a commit to ektravel/druid that referenced this pull request Oct 16, 2023
…e#15032)

Refactor the code to clean up the result sequences when materializing the results as Frames
CaseyPan pushed a commit to CaseyPan/druid that referenced this pull request Nov 17, 2023
…e#15032)

Refactor the code to clean up the result sequences when materializing the results as Frames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments