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

[SPARK-50235][SQL] Clean up ColumnVector resource after processing all rows in ColumnarToRowExec #48767

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public abstract class ColumnVector implements AutoCloseable {
@Override
public abstract void close();

/**
* Cleans up memory for this column vector if it's not writable. The column vector is not usable
* after this.
*
* If this is a writable column vector, it is a no-op.
*/
public void closeIfNotWritable() {
// By default, we just call close() for all column vectors. If a column vector is writable, it
// should override this method and do nothing.
close();
}

/**
* Returns true if this column vector contains any null values.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public void close() {
}
}

/**
* Called to close all the columns if they are not writable. This is used to clean up memory
* allocated during columnar processing.
*/
public void closeIfNotWritable() {
for (ColumnVector c: columns) {
c.closeIfNotWritable();
}
}

/**
* Returns an iterator over the rows in this batch.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public void close() {
releaseMemory();
}

@Override
public void closeIfNotWritable() {
// no-op
}

public void reserveAdditional(int additionalCapacity) {
reserve(elementsAppended + additionalCapacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@ case class ColumnarToRowExec(child: SparkPlan) extends ColumnarToRowTransition w
| $shouldStop
| }
| $idx = $numRows;
| $batch.closeIfNotWritable();
Copy link
Member Author

Choose a reason for hiding this comment

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

For writable column vectors, they are reused across batches, so we cannot close them until finishing all batches (see below).

| $batch = null;
| $nextBatchFuncName();
|}
|// clean up resources
|if ($batch != null) {
| $batch.close();
|}
Comment on lines +202 to +204
Copy link
Member Author

Choose a reason for hiding this comment

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

This looks like memory leak for off-heap case.

""".stripMargin
}

Expand Down