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

DRILL-8479: Merge Join Leak When Depleting Incoming Batches Throw Exception #2878

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

shfshihuafeng
Copy link
Contributor

@shfshihuafeng shfshihuafeng commented Jan 24, 2024

DRILL-8479: Merge Join Leak When Depleting Incoming Batches Throw Exception

Description

when fragment failed, it call close() from MergeJoinBatch. but if leftIterator.close() throw exception, we could not call rightIterator.close() to release memory。

Relates to: (#2876)

Documentation

(Please describe user-visible changes similar to what should appear in the Drill documentation.)

Testing

The test method is the same with link, only one parameter needs to be modified,
set planner.enable_hashjoin =false to ensure use mergejoin operator
link
DRILL-8478: HashPartition memory leak when it allocate memory exception with OutOfMemoryException (#2874)

@cgivre cgivre added bug backport-to-stable This bug fix is applicable to the latest stable release and should be considered for inclusion there labels Jan 24, 2024
@cgivre cgivre requested a review from paul-rogers January 24, 2024 17:18
@cgivre cgivre changed the title DRILL-8479: mergejoin leak when Depleting incoming batches throw exception… DRILL-8479: Merge Join Leak When Depleting Incoming Batches Throw Exception Jan 24, 2024
leftIterator.close();
try {
leftIterator.close();
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know what kind(s) of exceptions to expect here? Also, can we throw a better error message? Specifically, can we tell the user more information about the cause of the crash and how to fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add exception info ?

try {
      leftIterator.close();
    } catch (QueryCancelledException qce) {
      throw UserException.executionError(qce)
          .message("Failed when depleting incoming batches, probably because query was cancelled " +
              "by executor had some error")
          .build(logger);
    } catch (Exception e) {
      throw UserException.internalError(e)
          .message("Failed when depleting incoming batches")
          .build(logger);
    } finally {
      // todo catch exception info or By default,the exception is thrown directly ?
      rightIterator.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.

stack

Caused by: org.apache.drill.exec.ops.QueryCancelledException: null
        at org.apache.drill.exec.work.fragment.FragmentExecutor$ExecutorStateImpl.checkContinue(FragmentExecutor.java:533)
        at org.apache.drill.exec.record.AbstractRecordBatch.checkContinue(AbstractRecordBatch.java:278)
        at org.apache.drill.exec.record.AbstractRecordBatch.next(AbstractRecordBatch.java:105)
        at org.apache.drill.exec.record.AbstractUnaryRecordBatch.innerNext(AbstractUnaryRecordBatch.java:59)
        at org.apache.drill.exec.record.AbstractRecordBatch.next(AbstractRecordBatch.java:165)
        at org.apache.drill.exec.record.RecordIterator.clearInflightBatches(RecordIterator.java:359)
        at org.apache.drill.exec.record.RecordIterator.close(RecordIterator.java:365)
        at org.apache.drill.exec.physical.impl.join.MergeJoinBatch.close(MergeJoinBatch.java:301)

leftIterator.close();
} catch (Exception e) {
rightIterator.close();
throw UserException.executionError(e)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the right iterator doesn't close properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it throw exception from method clearInflightBatches() , but it has cleared the memory by clear(); so it does not affect memory leaks ,see following code

public void close() { clear(); clearInflightBatches(); }

Copy link
Contributor

@cgivre cgivre left a comment

Choose a reason for hiding this comment

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

LGTM +1

@cgivre cgivre merged commit 26f4d30 into apache:master Mar 6, 2024
8 checks passed
jnturton pushed a commit to jnturton/drill that referenced this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-stable This bug fix is applicable to the latest stable release and should be considered for inclusion there bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants