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

release-22.1: colexecdisk: make sure to release resources in all cases #81492

Merged
merged 1 commit into from
May 19, 2022
Merged
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
11 changes: 10 additions & 1 deletion pkg/sql/colexec/disk_spiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,17 @@ func (d *diskSpillerBase) Close(ctx context.Context) error {
return nil
}
var retErr error
for _, input := range d.inputs {
if c, ok := input.(colexecop.Closer); ok {
if err := c.Close(ctx); err != nil {
retErr = err
}
}
}
if c, ok := d.inMemoryOp.(colexecop.Closer); ok {
retErr = c.Close(ctx)
if err := c.Close(ctx); err != nil {
retErr = err
}
}
if c, ok := d.diskBackedOp.(colexecop.Closer); ok {
if err := c.Close(ctx); err != nil {
Expand Down
10 changes: 2 additions & 8 deletions pkg/sql/colexec/external_distinct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,8 @@ func TestExternalDistinct(t *testing.T) {
require.Equal(t, numExpectedClosers, len(closers))
return distinct, err
})
if tc.errorOnDup == "" || tc.noError {
// We don't check that all FDs were released if an error is
// expected to be returned because our utility closeIfCloser()
// doesn't handle multiple closers (which is always the case for
// the external distinct).
for i, sem := range semsToCheck {
require.Equal(t, 0, sem.GetCount(), "sem still reports open FDs at index %d", i)
}
for i, sem := range semsToCheck {
require.Equal(t, 0, sem.GetCount(), "sem still reports open FDs at index %d", i)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/colexec/parallel_unordered_synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,10 @@ func (s *ParallelUnorderedSynchronizer) Close(ctx context.Context) error {
// Note that at this point we know that the input goroutines won't be
// spawned up (our consumer won't call Next/DrainMeta after calling Close),
// so it is safe to close all closers from this goroutine.
for _, span := range s.tracingSpans {
for i, span := range s.tracingSpans {
if span != nil {
span.Finish()
s.tracingSpans[i] = nil
}
}
var lastErr error
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/colexec/serial_unordered_synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (s *SerialUnorderedSynchronizer) Close(context.Context) error {
}
if s.span != nil {
s.span.Finish()
s.span = nil
}
return lastErr
}
4 changes: 3 additions & 1 deletion pkg/sql/colexecop/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ type BufferingInMemoryOperator interface {
type Closer interface {
// Close releases the resources associated with this Closer. If this Closer
// is an Operator, the implementation of Close must be safe to execute even
// if Operator.Init wasn't called.
// if Operator.Init wasn't called. Multiple calls to Close() are allowed,
// and most of the implementations should make all calls except for the
// first one no-ops.
//
// Unless the Closer derives its own context with a separate tracing span,
// the argument context rather than the one from Init() must be used
Expand Down