release-22.1: colexecdisk: make sure to release resources in all cases #81492
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 1/1 commits from #81419.
/cc @cockroachdb/release
Previously, it was possible to not release some resources when external
distinct or external hash aggregator short circuit their execution
(either because of an error or because of the LIMIT on the query) in
some cases (namely, when a sort is planned on top of the external
operation to restore the desired ordering). This was the case because
the hash-based partitioner (which abstracts away the disk-backed
algorithm) wasn't added to
OpWithMetaInfo.ToClose
slice since there isa sort on top of it nor was it closed by that sort.
Here is an example diagram for all the infra that is set up for the
disk-backed distinct when ordering needs to be maintained:
In this diagram,
hash-based partitioner [2]
is the external distinctthat is the input to the
diskSpillerBase [1]
. In the happy path (when[2]
is exhausted), it isClose
d automatically. However, if itsexecution is short-circuited,
[2]
will never be closed because:ToClose
slice (so it will not be closed on the flow cleanup)diskSpillerBase [1]
doesn't close its inputsexternal sorter
nor the in-memory sorter end up closing[2]
eitherbecause there are other utility operators that don't implement
Closer
interface between the sorters and[2]
.As a result of not closing
[2]
, some disk resources might be leaked.This commit fixes the issue by making
diskSpillerBase
close all of itsinputs (which is a single input in the case of the disk-backed distinct
and disk-backed hash aggregator).
Close
is allowed to be calledmultiple time, so it is ok if there happen to be other codepaths
calling it.
Fixes: #81413.
Release note: None
Release justification: low risk bug fix.