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

*: simple code for readProjection #39600

Merged
merged 6 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion ddl/concurrentddltest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "concurrentddltest_test",
timeout = "short",
timeout = "moderate",
srcs = [
"main_test.go",
"switch_test.go",
Expand Down
40 changes: 14 additions & 26 deletions executor/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (e *ProjectionExec) Open(ctx context.Context) error {
return e.open(ctx)
}

func (e *ProjectionExec) open(ctx context.Context) error {
func (e *ProjectionExec) open(_ context.Context) error {
e.prepared = false
e.parentReqRows = int64(e.maxChunkSize)

Expand Down Expand Up @@ -364,14 +364,14 @@ func (f *projectionInputFetcher) run(ctx context.Context) {
}()

for {
input := readProjectionInput(f.inputCh, f.globalFinishCh)
if input == nil {
input, isNil := readProjection[*projectionInput](f.inputCh, f.globalFinishCh)
if isNil {
return
}
targetWorker := input.targetWorker

output = readProjectionOutput(f.outputCh, f.globalFinishCh)
if output == nil {
output, isNil = readProjection[*projectionOutput](f.outputCh, f.globalFinishCh)
if isNil {
f.proj.memTracker.Consume(-input.chk.MemoryUsage())
return
}
Expand Down Expand Up @@ -431,13 +431,13 @@ func (w *projectionWorker) run(ctx context.Context) {
w.proj.wg.Done()
}()
for {
input := readProjectionInput(w.inputCh, w.globalFinishCh)
if input == nil {
input, isNil := readProjection[*projectionInput](w.inputCh, w.globalFinishCh)
if isNil {
return
}

output = readProjectionOutput(w.outputCh, w.globalFinishCh)
if output == nil {
output, isNil = readProjection[*projectionOutput](w.outputCh, w.globalFinishCh)
if isNil {
return
}

Expand All @@ -462,26 +462,14 @@ func recoveryProjection(output *projectionOutput, r interface{}) {
logutil.BgLogger().Error("projection executor panicked", zap.String("error", fmt.Sprintf("%v", r)), zap.Stack("stack"))
}

func readProjectionInput(inputCh <-chan *projectionInput, finishCh <-chan struct{}) *projectionInput {
func readProjection[T any](ch <-chan T, finishCh <-chan struct{}) (t T, isNil bool) {
select {
case <-finishCh:
return nil
case input, ok := <-inputCh:
if !ok {
return nil
}
return input
}
}

func readProjectionOutput(outputCh <-chan *projectionOutput, finishCh <-chan struct{}) *projectionOutput {
select {
case <-finishCh:
return nil
case output, ok := <-outputCh:
return t, true
case t, ok := <-ch:
if !ok {
return nil
return t, true
}
return output
return t, false
}
}
2 changes: 1 addition & 1 deletion executor/seqtest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/golang/glog.(*loggingT).flushDaemon"),
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"),
goleak.IgnoreTopFunction("github.com/pingcap/tidb/executor.readProjectionInput"),
goleak.IgnoreTopFunction("github.com/pingcap/tidb/executor.readProjection[...]"),
goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
}
Expand Down