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

master: use etcd as operate queue #363

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
47b099a
add command proto and master write some request to etcd, and watch re…
WangXiangUSTC Nov 18, 2019
b26d68e
update some request
WangXiangUSTC Nov 18, 2019
6c5c75a
update name
WangXiangUSTC Nov 18, 2019
0143e5f
minor update
WangXiangUSTC Nov 18, 2019
889e7a9
Merge branch 'master' into xiang/etcd_operate_queue
WangXiangUSTC Nov 19, 2019
6709763
use etcd in tidb-tools
WangXiangUSTC Nov 19, 2019
f85e98c
fix test
WangXiangUSTC Nov 19, 2019
a946031
fix unit test
WangXiangUSTC Nov 20, 2019
62afe6e
add some error
WangXiangUSTC Nov 20, 2019
d7298f5
minor update
WangXiangUSTC Nov 20, 2019
0b0d372
fix
WangXiangUSTC Nov 20, 2019
6b869ef
add Unknown operate type
WangXiangUSTC Nov 21, 2019
9891c9a
address comment
WangXiangUSTC Nov 21, 2019
83bc4cb
update function saveRequestAndWaitResponse
WangXiangUSTC Nov 21, 2019
b640925
update function name
WangXiangUSTC Nov 21, 2019
92e8265
address comment
WangXiangUSTC Nov 21, 2019
c04fcee
delete useless import
WangXiangUSTC Nov 21, 2019
9899502
address comment
WangXiangUSTC Nov 22, 2019
4c09e2e
Merge branch 'master' into xiang/etcd_operate_queue
csuzhangxc Nov 22, 2019
c6cc5ca
address comment
WangXiangUSTC Nov 25, 2019
eab5c48
address comment
WangXiangUSTC Nov 25, 2019
88a551e
merge master and resolve conflicts
WangXiangUSTC Nov 27, 2019
a27edd8
only leader handle request
WangXiangUSTC Nov 27, 2019
314f5e3
fix unit test
WangXiangUSTC Nov 27, 2019
0ddd1dd
add log
WangXiangUSTC Nov 28, 2019
ccd1a79
Merge branch 'master' into xiang/etcd_operate_queue
WangXiangUSTC Nov 28, 2019
1a82e68
add ShowMasterLeader rpc server, and update check master online
WangXiangUSTC Dec 2, 2019
26abd88
add operate stage
WangXiangUSTC Dec 2, 2019
a7759dc
merge master
WangXiangUSTC Dec 2, 2019
2e67069
add some log
WangXiangUSTC Dec 2, 2019
3fd9af5
minor fix
WangXiangUSTC Dec 2, 2019
5f75338
add show master leader test
WangXiangUSTC Dec 3, 2019
39a1fbc
fix ci
WangXiangUSTC Dec 3, 2019
b8518cd
Merge branch 'master' into xiang/etcd_operate_queue
IANTHEREAL Dec 3, 2019
f0931fb
update log
WangXiangUSTC Dec 4, 2019
0201e85
add comment for unit test
WangXiangUSTC Dec 4, 2019
20524e7
update proto and other update
WangXiangUSTC Dec 4, 2019
7d89605
Merge branch 'xiang/etcd_operate_queue' of https://github.com/pingcap…
WangXiangUSTC Dec 4, 2019
b091a46
add log for watch request
WangXiangUSTC Dec 4, 2019
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
10 changes: 10 additions & 0 deletions _utils/terror_gen/errors_release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ ErrMasterGenEmbedEtcdConfigFail,[code=38037:class=dm-master:scope=internal:level
ErrMasterStartEmbedEtcdFail,[code=38038:class=dm-master:scope=internal:level=high],"fail to start embed etcd"
ErrMasterParseURLFail,[code=38039:class=dm-master:scope=internal:level=high],"fail to parse URL %s"
ErrMasterJoinEmbedEtcdFail,[code=38040:class=dm-master:scope=internal:level=high],"fail to join embed etcd: %s"
ErrMasterMarshalOperate,[code=38041:class=dm-master:scope=internal:level=high],"fail to marshal operate: %v"
ErrMasterUnmarshalOperate,[code=38042:class=dm-master:scope=internal:level=high],"fail to unmarshal operate, operate's key: %s"
ErrMasterUnmarshalOperateRequest,[code=38043:class=dm-master:scope=internal:level=high],"fail to unmarshal operate request: %v"
ErrMasterMarshalResponse,[code=38044:class=dm-master:scope=internal:level=high],"fail to marshal response"
ErrMasterWatchEtcd,[code=38045:class=dm-master:scope=internal:level=medium],"fail to watch etcd's key: %s"
ErrMasterWriteEtcd,[code=38046:class=dm-master:scope=internal:level=high],"fail to write data to etcd"
ErrMasterCreateEtcdClient,[code=38047:class=dm-master:scope=internal:level=high],"fail to create etcd client"
ErrMasterMarshalRequest,[code=38048:class=dm-master:scope=internal:level=high],"fail to marshal request: %v"
ErrMasterUnmarshalResponse,[code=38049:class=dm-master:scope=internal:level=high],"fail to unmarshal response"
ErrMasterOperateNotHandle,[code=38050:class=dm-master:scope=internal:level=medium],"operate %v is not handled, maybe no DM-master leader"
ErrWorkerParseFlagSet,[code=40001:class=dm-worker:scope=internal:level=medium],"parse dm-worker config flag set"
ErrWorkerInvalidFlag,[code=40002:class=dm-worker:scope=internal:level=medium],"'%s' is an invalid flag"
ErrWorkerDecodeConfigFromFile,[code=40003:class=dm-worker:scope=internal:level=medium],"toml decode file"
Expand Down
1 change: 1 addition & 0 deletions dm/ctl/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewRootCmd() *cobra.Command {
master.NewUpdateRelayCmd(),
master.NewPurgeRelayCmd(),
master.NewMigrateRelayCmd(),
master.NewShowLeaderCmd(),
)
return cmd
}
Expand Down
50 changes: 50 additions & 0 deletions dm/ctl/master/show_leader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2019 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"

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

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewShowLeaderCmd creates a ShowMasterLeader command
func NewShowLeaderCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show-master-leader",
Short: "show the DM-master's leader information",
Run: showLeaderFunc,
}
return cmd
}

// showLeaderFunc does show master leader request
func showLeaderFunc(cmd *cobra.Command, _ []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// show master leader
cli := common.MasterClient()
resp, err := cli.ShowMasterLeader(ctx, &pb.ShowMasterLeaderRequest{})
if err != nil {
common.PrintLines("fail to show master leader:\n%v", errors.ErrorStack(err))
return
}

common.PrettyPrintResponse(resp)
}
6 changes: 6 additions & 0 deletions dm/master/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ func (s *Server) electionNotify(ctx context.Context) {
}
}
}

// getLeaderMasterInfo gets the DM-master leader's ID, this ID can set by Config.Name, or use hostname by default.
func (s *Server) getLeaderMasterInfo(ctx context.Context) (string, error) {
_, leaderID, err := s.election.LeaderInfo(ctx)
return leaderID, err
}
21 changes: 21 additions & 0 deletions dm/master/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"strings"
"time"

"github.com/pingcap/tidb-tools/pkg/etcd"
"github.com/pingcap/tidb-tools/pkg/utils"
"go.etcd.io/etcd/embed"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand All @@ -36,6 +38,10 @@ const (
etcdStartTimeout = time.Minute
// privateDirMode grants owner to make/remove files inside the directory.
privateDirMode os.FileMode = 0700

defaultOperatePath = "/dm-operate"

defaultEtcdTimeout = time.Duration(10 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also defined this in pkg/etcdutil/etcdutil.go. and and a CreateClient in it in #367 . we can merge then later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, if your pr merged first I will use your function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WangXiangUSTC It's time to update this defaultEtcdTimeout with the one in pkg/etcdutil/etcdutil.go now?

)

// startEtcd starts an embedded etcd server.
Expand Down Expand Up @@ -198,3 +204,18 @@ func isDataExist(d string) bool {
}
return len(names) != 0
}

// getEtcdClientForOperate returns an etcd client
func getEtcdClientForOperate(addr string) (*etcd.Client, error) {
ectdEndpoints, err := utils.ParseHostPortAddr(addr)
if err != nil {
return nil, terror.ErrMasterCreateEtcdClient.Delegate(err)
}

etcdClient, err := etcd.NewClientFromCfg(ectdEndpoints, defaultEtcdTimeout, "", nil)
if err != nil {
return nil, terror.ErrMasterCreateEtcdClient.Delegate(err)
}

return etcdClient, nil
}
Loading