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-21.1: colexec: wrap DrainMeta with panic-catcher and protect columnarizer #63242

Merged
merged 1 commit into from
Apr 7, 2021
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
7 changes: 7 additions & 0 deletions pkg/sql/colexec/columnarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ func (c *Columnarizer) DrainMeta(ctx context.Context) []execinfrapb.ProducerMeta
if c.removedFromFlow {
return nil
}
if c.initStatus == colexecop.OperatorNotInitialized {
// The columnarizer wasn't initialized, so the wrapped processors might
// not have been started leaving them in an unsafe to drain state, so
// we skip the draining. Mostly likely this happened because a panic was
// encountered in Init.
return c.accumulatedMeta
}
c.MoveToDraining(nil /* err */)
for {
meta := c.DrainHelper()
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/materializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (m *Materializer) Start(ctx context.Context) {
m.MoveToDraining(err)
} else {
// Note that we intentionally only start the drain helper if
// initialization was successful - no starting the helper will tell it
// initialization was successful - not starting the helper will tell it
// to not drain the metadata sources (which have not been properly
// initialized).
m.drainHelper.Start(ctx)
Expand Down
8 changes: 3 additions & 5 deletions pkg/sql/colflow/colrpc/outbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Outbox struct {

// draining is an atomic that represents whether the Outbox is draining.
draining uint32
metadataSources []execinfrapb.MetadataSource
metadataSources execinfrapb.MetadataSources
// closers is a slice of Closers that need to be Closed on termination.
closers colexecop.Closers

Expand Down Expand Up @@ -307,10 +307,8 @@ func (o *Outbox) sendMetadata(ctx context.Context, stream flowStreamClient, errT
},
})
}
for _, src := range o.metadataSources {
for _, meta := range src.DrainMeta(ctx) {
msg.Data.Metadata = append(msg.Data.Metadata, execinfrapb.LocalMetaToRemoteProducerMeta(ctx, meta))
}
for _, meta := range o.metadataSources.DrainMeta(ctx) {
msg.Data.Metadata = append(msg.Data.Metadata, execinfrapb.LocalMetaToRemoteProducerMeta(ctx, meta))
}
if len(msg.Data.Metadata) == 0 {
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/execinfrapb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go_library(
"//pkg/sql/catalog/descpb",
"//pkg/sql/catalog/schemaexpr",
"//pkg/sql/catalog/tabledesc",
"//pkg/sql/colexecerror",
"//pkg/sql/parser",
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
Expand Down
14 changes: 11 additions & 3 deletions pkg/sql/execinfrapb/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
"github.com/cockroachdb/cockroach/pkg/sql/colexecerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/encoding"
Expand Down Expand Up @@ -336,11 +337,18 @@ type MetadataSource interface {
type MetadataSources []MetadataSource

// DrainMeta calls DrainMeta on all MetadataSources and returns a single slice
// with all the accumulated metadata.
// with all the accumulated metadata. Note that this method wraps the draining
// with the panic-catcher so that the callers don't have to.
func (s MetadataSources) DrainMeta(ctx context.Context) []ProducerMetadata {
var result []ProducerMetadata
for _, src := range s {
result = append(result, src.DrainMeta(ctx)...)
if err := colexecerror.CatchVectorizedRuntimeError(func() {
for _, src := range s {
result = append(result, src.DrainMeta(ctx)...)
}
}); err != nil {
meta := GetProducerMeta()
meta.Err = err
result = append(result, *meta)
}
return result
}