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

vdiff: fix data race in test #5490

Merged
merged 1 commit into from
Dec 1, 2019
Merged
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
19 changes: 12 additions & 7 deletions go/vt/wrangler/vdiff_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package wrangler
import (
"flag"
"fmt"
"sync"

"golang.org/x/net/context"
"vitess.io/vitess/go/sqltypes"
Expand Down Expand Up @@ -51,18 +52,22 @@ const (
type testVDiffEnv struct {
wr *Wrangler
workflow string
tablets map[int]*testVDiffTablet
topoServ *topo.Server
cell string
tabletType topodatapb.TabletType
tmc *testVDiffTMClient

mu sync.Mutex
tablets map[int]*testVDiffTablet
}

// vdiffEnv has to be a global for RegisterDialer to work.
var vdiffEnv *testVDiffEnv

func init() {
tabletconn.RegisterDialer("VDiffTest", func(tablet *topodatapb.Tablet, failFast grpcclient.FailFast) (queryservice.QueryService, error) {
vdiffEnv.mu.Lock()
defer vdiffEnv.mu.Unlock()
return vdiffEnv.tablets[int(tablet.Alias.Uid)], nil
})
}
Expand Down Expand Up @@ -163,12 +168,17 @@ func newTestVDiffEnv(sourceShards, targetShards []string, query string, position
}

func (env *testVDiffEnv) close() {
env.mu.Lock()
defer env.mu.Unlock()
for _, t := range env.tablets {
env.deleteTablet(t.tablet)
env.topoServ.DeleteTablet(context.Background(), t.tablet.Alias)
}
env.tablets = nil
}

func (env *testVDiffEnv) addTablet(id int, keyspace, shard string, tabletType topodatapb.TabletType) *testVDiffTablet {
env.mu.Lock()
defer env.mu.Unlock()
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: env.cell,
Expand Down Expand Up @@ -198,11 +208,6 @@ func (env *testVDiffEnv) addTablet(id int, keyspace, shard string, tabletType to
return env.tablets[id]
}

func (env *testVDiffEnv) deleteTablet(tablet *topodatapb.Tablet) {
env.topoServ.DeleteTablet(context.Background(), tablet.Alias)
delete(env.tablets, int(tablet.Alias.Uid))
}

//----------------------------------------------
// testVDiffTablet

Expand Down