github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/ctl/master/show_ddl_locks.go (about) 1 // Copyright 2019 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package master 15 16 import ( 17 "context" 18 "errors" 19 "os" 20 21 "github.com/pingcap/tiflow/dm/ctl/common" 22 "github.com/pingcap/tiflow/dm/pb" 23 "github.com/spf13/cobra" 24 ) 25 26 // NewShowDDLLocksCmd creates a ShowDDlLocks command. 27 func NewShowDDLLocksCmd() *cobra.Command { 28 cmd := &cobra.Command{ 29 Use: "show-ddl-locks [-s source ...] [task-name | task-file]", 30 Short: "Shows un-resolved DDL locks", 31 Hidden: true, 32 RunE: showDDLLocksFunc, 33 } 34 return cmd 35 } 36 37 // showDDLLocksFunc does show DDL locks. 38 func showDDLLocksFunc(cmd *cobra.Command, _ []string) error { 39 if len(cmd.Flags().Args()) > 1 { 40 cmd.SetOut(os.Stdout) 41 common.PrintCmdUsage(cmd) 42 return errors.New("please check output to see error") 43 } 44 taskName := common.GetTaskNameFromArgOrFile(cmd.Flags().Arg(0)) // maybe empty 45 46 sources, err := common.GetSourceArgs(cmd) 47 if err != nil { 48 return err 49 } 50 51 ctx, cancel := context.WithCancel(context.Background()) 52 defer cancel() 53 54 resp := &pb.ShowDDLLocksResponse{} 55 err = common.SendRequest( 56 ctx, 57 "ShowDDLLocks", 58 &pb.ShowDDLLocksRequest{ 59 Task: taskName, 60 Sources: sources, 61 }, 62 &resp, 63 ) 64 65 if err != nil { 66 common.PrintLinesf("can not show DDL locks for task %s and sources %v", taskName, sources) 67 return err 68 } 69 70 common.PrettyPrintResponse(resp) 71 return nil 72 }