Skip to content

Commit

Permalink
ddl: enable goleak for ingest package (#43765)
Browse files Browse the repository at this point in the history
close #43764
  • Loading branch information
tangenta committed May 15, 2023
1 parent 853d2b6 commit aa52c4b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ddl/ingest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ go_test(
"checkpoint_test.go",
"env_test.go",
"integration_test.go",
"main_test.go",
"mem_root_test.go",
],
embed = [":ingest"],
flaky = True,
race = "on",
shard_count = 11,
deps = [
":ingest",
"//config",
"//ddl",
"//ddl/internal/session",
Expand All @@ -77,5 +78,6 @@ go_test(
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
)
3 changes: 3 additions & 0 deletions ddl/ingest/backend_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func (m *litBackendCtxMgr) Unregister(jobID int64) {
}
bc.unregisterAll(jobID)
bc.backend.Close()
if bc.checkpointMgr != nil {
bc.checkpointMgr.Close()
}
m.memRoot.Release(StructSizeBackendCtx)
m.Delete(jobID)
m.memRoot.ReleaseWithTag(EncodeBackendTag(jobID))
Expand Down
4 changes: 4 additions & 0 deletions ddl/ingest/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func NewCheckpointManager(ctx context.Context, flushCtrl FlushController,
cm.updateCheckpointLoop()
cm.updaterWg.Done()
}()
logutil.BgLogger().Info("[ddl-ingest] create checkpoint manager",
zap.Int64("jobID", jobID), zap.Int64("indexID", indexID))
return cm, nil
}

Expand Down Expand Up @@ -195,6 +197,8 @@ func (s *CheckpointManager) UpdateCurrent(taskID int, added int) error {
func (s *CheckpointManager) Close() {
s.updaterExitCh <- struct{}{}
s.updaterWg.Wait()
logutil.BgLogger().Info("[ddl-ingest] close checkpoint manager",
zap.Int64("jobID", s.jobID), zap.Int64("indexID", s.indexID))
}

// Sync syncs the checkpoint.
Expand Down
1 change: 0 additions & 1 deletion ddl/ingest/engine_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (bc *litBackendCtx) Unregister(jobID, indexID int64) {

ei.Clean()
bc.Delete(indexID)
bc.checkpointMgr.Close()
bc.MemRoot.ReleaseWithTag(encodeEngineTag(jobID, indexID))
bc.MemRoot.Release(StructSizeWriterCtx * int64(ei.writerCount))
bc.MemRoot.Release(StructSizeEngineInfo)
Expand Down
34 changes: 34 additions & 0 deletions ddl/ingest/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ingest

import (
"testing"

"go.uber.org/goleak"
)

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("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("github.com/tikv/client-go/v2/txnkv/transaction.keepAlive"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"),
goleak.IgnoreTopFunction("net/http.(*persistConn).writeLoop"),
}
goleak.VerifyTestMain(m, opts...)
}
3 changes: 3 additions & 0 deletions ddl/ingest/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (m *MockBackendCtxMgr) Unregister(jobID int64) {
err := mCtx.sessCtx.CommitTxn(context.Background())
logutil.BgLogger().Info("mock backend mgr unregister", zap.Int64("jobID", jobID), zap.Error(err))
delete(m.runningJobs, jobID)
if mCtx.checkpointMgr != nil {
mCtx.checkpointMgr.Close()
}
}
}

Expand Down

0 comments on commit aa52c4b

Please sign in to comment.