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

*: support sourceID on operate-source stop #855

Merged
merged 6 commits into from
Aug 5, 2020
Merged
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
18 changes: 12 additions & 6 deletions dm/ctl/master/operate_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,30 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) (err error) {
return
}

contents := make([]string, len(cmd.Flags().Args())-1)
contents := make([]string, 0, len(cmd.Flags().Args())-1)
sourceID := make([]string, 0, len(cmd.Flags().Args())-1)
for i := 1; i < len(cmd.Flags().Args()); i++ {
configFile := cmd.Flags().Arg(i)
arg := cmd.Flags().Arg(i)
var content []byte
content, err = common.GetFileContent(configFile)
content, err = common.GetFileContent(arg)
if err != nil {
if op == pb.SourceOp_StopSource {
sourceID = append(sourceID, arg)
continue
}
return
}
contents[i-1] = string(content)
contents = append(contents, string(content))
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cli := common.MasterClient()
resp, err := cli.OperateSource(ctx, &pb.OperateSourceRequest{
Config: contents,
Op: op,
Config: contents,
Op: op,
SourceID: sourceID,
})
if err != nil {
return
Expand Down
12 changes: 10 additions & 2 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,17 @@ func (s *Server) OperateSource(ctx context.Context, req *pb.OperateSourceRequest
resp.Msg = "Update worker config is not supported by dm-ha now"
return resp, nil
case pb.SourceOp_StopSource:
toRemove := make([]string, 0, len(cfgs)+len(req.SourceID))
for _, sid := range req.SourceID {
toRemove = append(toRemove, sid)
}
for _, cfg := range cfgs {
boundM[cfg.SourceID] = s.scheduler.GetWorkerBySource(cfg.SourceID)
err := s.scheduler.RemoveSourceCfg(cfg.SourceID)
toRemove = append(toRemove, cfg.SourceID)
}

for _, sid := range toRemove {
boundM[sid] = s.scheduler.GetWorkerBySource(sid)
err := s.scheduler.RemoveSourceCfg(sid)
// TODO(lance6716):
// user could not copy-paste same command if encounter error halfway:
// `operate-source stop correct-id-1 wrong-id-2`
Expand Down
Loading