Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
*: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Feb 26, 2020
1 parent c53fb89 commit 257e59a
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ func (s *Server) getSourceRespsAfterOperation(ctx context.Context, taskName stri
return sortCommonWorkerResults(sourceRespCh)
}

// SetDDLLockMode implements MasterClient.
func (s *Server) SetDDLLockMode(ctx context.Context, req *pb.SetDDLLockModeRequest) (*pb.CommonWorkerResponse, error) {
s.pessimist.SetLockMode(pessimism.LockMode(req.LockMode))
return &pb.CommonWorkerResponse{Result: true}, nil
Expand Down
1 change: 1 addition & 0 deletions dm/master/shardddl/pessimist.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func NewPessimist(pLogger *log.Logger, taskSources func(task string) []string) *
}
}

// SetLockMode dynamically changes the lock mode of all new DDL locks.
func (p *Pessimist) SetLockMode(mode pessimism.LockMode) {
p.mu.Lock()
p.lk.SetLockMode(mode)
Expand Down
10 changes: 5 additions & 5 deletions dm/master/shardddl/pessimist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func (t *testPessimist) TestPessimist(c *C) {
DDLs = []string{"ALTER TABLE bar ADD COLUMN c1 INT"}
ID1 = "task-1-`foo`.`bar`"
ID2 = "task-2-`foo`.`bar`"
i11 = pessimism.NewInfo(task1, source1, schema, table, DDLs)
i12 = pessimism.NewInfo(task1, source2, schema, table, DDLs)
i21 = pessimism.NewInfo(task2, source1, schema, table, DDLs)
i22 = pessimism.NewInfo(task2, source2, schema, table, DDLs)
i23 = pessimism.NewInfo(task2, source3, schema, table, DDLs)
i11 = pessimism.NewInfo(task1, source1, schema, table, DDLs, nil, nil)
i12 = pessimism.NewInfo(task1, source2, schema, table, DDLs, nil, nil)
i21 = pessimism.NewInfo(task2, source1, schema, table, DDLs, nil, nil)
i22 = pessimism.NewInfo(task2, source2, schema, table, DDLs, nil, nil)
i23 = pessimism.NewInfo(task2, source3, schema, table, DDLs, nil, nil)

sources = func(task string) []string {
switch task {
Expand Down
4 changes: 2 additions & 2 deletions pkg/schema/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/util"
)

const (
Expand Down Expand Up @@ -115,8 +116,7 @@ func (tr *Tracker) Reset() error {
ddl := tr.dom.DDL()
for _, db := range allDBs {
dbName := model.NewCIStr(db)
switch dbName.L {
case "mysql", "performance_schema", "information_schema":
if util.IsMemOrSysDB(dbName.L) {
continue
}
if err := ddl.DropSchema(tr.se, dbName); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/shardddl/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pingcap/parser/model"
)

// Lock is a generic DDL lock.
type Lock struct {
mu sync.RWMutex

Expand All @@ -31,6 +32,7 @@ type Lock struct {
impl LockImpl
}

// LockImpl is an interface describing the resolution algorithm of the lock.
type LockImpl interface {
AddSources(sources []string)

Expand All @@ -43,6 +45,7 @@ type LockImpl interface {
Ready() map[string]bool
}

// NewLock creates a new generic DDL lock.
func NewLock(ID, task, owner string, sources []string, impl LockImpl) *Lock {
lock := &Lock{
ID: ID,
Expand All @@ -58,6 +61,9 @@ func NewLock(ID, task, owner string, sources []string, impl LockImpl) *Lock {
return lock
}

// TrySync tries to sync the lock, does decrease on remain, re-entrant.
// new upstream sources may join when the DDL lock is in syncing,
// so we need to merge these new sources.
func (l *Lock) TrySync(caller string, ddls []string, newTableInfo *model.TableInfo, sources []string) (bool, int, error) {
l.mu.Lock()
defer l.mu.Unlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/shardddl/optimism/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type optimisticLockImpl struct {
synced bool // whether last call to TrySync() returns true
}

// NewLock creates a new optimistic DDL lock.
func NewLock(ID, task, owner string, table *model.TableInfo, sources []string) *shardddl.Lock {
return shardddl.NewLock(ID, task, owner, sources, &optimisticLockImpl{
tables: make(map[string]schemacmp.Table),
Expand Down
8 changes: 8 additions & 0 deletions pkg/shardddl/pessimism/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ import (
"github.com/pingcap/dm/pkg/shardddl/optimism"
)

// LockMode represents the mode of a DDL lock.
type LockMode uint32

const (
// LockModePessimistic sets the lock mode to be pessimistic. The lock is
// held until all sources have executed the same DDL upstream.
LockModePessimistic LockMode = iota
// LockModeOptimistic sets the lock mode to be optimistic. The lock is
// released as soon as the downstream table schema is compatible with all
// upstream schemas.
LockModeOptimistic
)

Expand All @@ -45,12 +51,14 @@ func NewLockKeeper() *LockKeeper {
}
}

// SetLockMode dynamically modify the mode for all new DDL locks.
func (lk *LockKeeper) SetLockMode(mode LockMode) {
lk.mu.Lock()
lk.mode = mode
lk.mu.Unlock()
}

// LockMode returns the current mode for new DDL locks.
func (lk *LockKeeper) LockMode() LockMode {
lk.mu.RLock()
mode := lk.mode
Expand Down
1 change: 1 addition & 0 deletions pkg/shardddl/pessimism/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pingcap/dm/pkg/shardddl"
)

// Lock is an alias of `shardddl.Lock` for compatibility with existing code.
type Lock = shardddl.Lock

type pessimisticLockImpl struct {
Expand Down
2 changes: 1 addition & 1 deletion syncer/shardddl/pessimist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (t *testPessimist) TestPessimist(c *C) {

logger = log.L()
p = NewPessimist(&logger, etcdTestCli, task, source)
info = p.ConstructInfo(schema, table, DDLs)
info = p.ConstructInfo(schema, table, DDLs, nil, nil)
)

ctx, cancel := context.WithCancel(context.Background())
Expand Down
1 change: 1 addition & 0 deletions tests/others_integration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ha_master
full_mode
start_task
dm_syncer
sequence_sharding_optimistic

0 comments on commit 257e59a

Please sign in to comment.