Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch committed Jul 27, 2023
1 parent d9a0960 commit c6b73c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/tempurl"
Expand Down Expand Up @@ -91,6 +92,10 @@ func AddEtcdMember(client *clientv3.Client, urls []string) (*clientv3.MemberAddR
// ListEtcdMembers returns a list of internal etcd members.
func ListEtcdMembers(client *clientv3.Client) (*clientv3.MemberListResponse, error) {
ctx, cancel := context.WithTimeout(client.Ctx(), DefaultRequestTimeout)
failpoint.Inject("SlowMemberList", func(val failpoint.Value) {
d := val.(int)
time.Sleep(time.Duration(d) * time.Second)
})
listResp, err := client.MemberList(ctx)
cancel()
if err != nil {
Expand All @@ -116,6 +121,10 @@ func EtcdKVGet(c *clientv3.Client, key string, opts ...clientv3.OpOption) (*clie
defer cancel()

start := time.Now()
failpoint.Inject("SlowEtcdKVGet", func(val failpoint.Value) {
d := val.(int)
time.Sleep(time.Duration(d) * time.Second)
})
resp, err := clientv3.NewKV(c).Get(ctx, key, opts...)
if cost := time.Since(start); cost > DefaultSlowRequestTime {
log.Warn("kv gets too slow", zap.String("request-key", key), zap.Duration("cost", cost), errs.ZapError(err))
Expand Down
9 changes: 9 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,15 @@ func (s *Server) campaignLeader() {
log.Info("etcd leader changed, resigns pd leadership", zap.String("old-pd-leader-name", s.Name()))
return
}
// add failpoint to test exit leader, failpoint judge the member is the give value, then break
failpoint.Inject("exitCampaignLeader", func(val failpoint.Value) {
memberString := val.(string)
memberID, _ := strconv.ParseUint(memberString, 10, 64)
if s.member.ID() == memberID {
log.Info("exit PD leader")
failpoint.Return()
}
})
case <-ctx.Done():
// Server is closed and it should return nil.
log.Info("server is closed")
Expand Down

0 comments on commit c6b73c9

Please sign in to comment.