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

[WIP] Add optimistic sharding mode #491

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions dm/ctl/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewRootCmd() *cobra.Command {
master.NewShowDDLLocksCmd(),
master.NewUnlockDDLLockCmd(),
master.NewBreakDDLLockCmd(),
master.NewSetDDLLockModeCmd(),
master.NewSwitchRelayMasterCmd(),
master.NewPauseRelayCmd(),
master.NewResumeRelayCmd(),
Expand Down
70 changes: 70 additions & 0 deletions dm/ctl/master/set_ddl_lock_mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2020 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,
// See the License for the specific language governing permissions and
// limitations under the License.

package master

import (
"context"
"fmt"
"os"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/shardddl/pessimism"

"github.com/pingcap/errors"
"github.com/spf13/cobra"
)

// NewSetDDLLockModeCmd creates a SetDDLLockMode command
func NewSetDDLLockModeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set-ddl-lock-mode <mode>",
Short: "switch between optimistic and pessimistic modes for new DDL locks",
Run: setDDLLockModeFunc,
}
return cmd
}

// breakDDLLockFunc does break DDL lock
func setDDLLockModeFunc(cmd *cobra.Command, _ []string) {
if len(cmd.Flags().Args()) != 1 {
cmd.SetOut(os.Stdout)
cmd.Usage()
return
}

var lockMode pessimism.LockMode
switch lockModeStr := cmd.Flags().Arg(0); lockModeStr {
case "optimistic":
lockMode = pessimism.LockModeOptimistic
case "pessimistic":
lockMode = pessimism.LockModePessimistic
default:
fmt.Println("unknown lock mode", lockModeStr)
return
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli := common.MasterClient()
resp, err := cli.SetDDLLockMode(ctx, &pb.SetDDLLockModeRequest{
LockMode: uint32(lockMode),
})
if err != nil {
common.PrintLines("cannot change lock mode:\n%s", errors.ErrorStack(err))
return
}

common.PrettyPrintResponse(resp)
}
150 changes: 0 additions & 150 deletions dm/master/ddl_lock.go

This file was deleted.

70 changes: 0 additions & 70 deletions dm/master/ddl_lock_test.go

This file was deleted.

Loading