Skip to content

Commit

Permalink
change log
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed May 10, 2024
1 parent 8d36be5 commit 2433f0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions pkg/mcs/scheduling/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package server
import (
"context"
"fmt"
"github.com/tikv/pd/pkg/utils/etcdutil"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -56,6 +55,7 @@ import (
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/pkg/storage/kv"
"github.com/tikv/pd/pkg/utils/apiutil"
"github.com/tikv/pd/pkg/utils/etcdutil"
"github.com/tikv/pd/pkg/utils/grpcutil"
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/memberutil"
Expand Down Expand Up @@ -334,10 +334,10 @@ func (s *Server) campaignLeader() {
func (s *Server) primaryWatch(ctx context.Context, exitPrimary chan struct{}) {
resp, err := etcdutil.EtcdKVGet(s.participant.GetLeadership().GetClient(), s.participant.GetLeaderPath())
if err != nil || resp == nil || len(resp.Kvs) == 0 {
log.Error("[primary] getting the leader meets error", errs.ZapError(err))
log.Error("scheduling primary getting the primary meets error", errs.ZapError(err))
return
}
log.Info("[primary] start to watch the primary", zap.Stringer("scheduling-primary", s.participant.GetLeader()))
log.Info("scheduling primary start to watch the primary", zap.Stringer("scheduling-primary", s.participant.GetLeader()))
// Watch will keep looping and never return unless the primary has changed.
s.participant.GetLeadership().SetLeaderWatch(true)
s.participant.GetLeadership().Watch(s.serverLoopCtx, resp.Kvs[0].ModRevision+1)
Expand All @@ -346,15 +346,15 @@ func (s *Server) primaryWatch(ctx context.Context, exitPrimary chan struct{}) {
// only API update primary will set the expected leader
curPrimary, err := etcdutil.GetValue(s.participant.Client(), s.participant.GetLeaderPath())
if err != nil {
log.Error("[primary] getting the leader meets error", errs.ZapError(err))
log.Error("scheduling primary getting the leader meets error", errs.ZapError(err))
return
}
// only trigger by updating primary
if curPrimary != nil && resp.Kvs[0].Value != nil && string(curPrimary) != string(resp.Kvs[0].Value) {
utils.SetExpectedPrimary(s.participant.Client(), s.participant.GetLeaderPath())

s.participant.UnsetLeader()
defer log.Info("[primary] exit the primary watch loop")
defer log.Info("scheduling primary exit the primary watch loop")
for {
select {
case <-ctx.Done():
Expand Down
6 changes: 3 additions & 3 deletions pkg/mcs/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func GetExpectedPrimary(client *clientv3.Client, leaderPath string) string {
}

// RemoveExpectedPrimary removes the expected primary key.
// - removed when campaign success
// - removed when server is closed
// - removed when campaign new primary success
// - removed when old primary server is closed
func RemoveExpectedPrimary(client *clientv3.Client, leaderPath string) {
log.Info("remove expected primary key", zap.String("leaderPath", leaderPath))
// remove expected leader key
Expand All @@ -105,7 +105,7 @@ func SetExpectedPrimary(client *clientv3.Client, leaderPath string) {
log.Info("set expected primary key", zap.String("leaderPath", leaderPath))
leaderRaw, err := etcdutil.GetValue(client, leaderPath)
if err != nil {
log.Error("[primary] get primary key error", zap.Error(err))
log.Error("get primary key error", zap.Error(err))
return

Check warning on line 109 in pkg/mcs/utils/util.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/utils/util.go#L108-L109

Added lines #L108 - L109 were not covered by tests
}
// write a flag to indicate the current primary has exited
Expand Down
8 changes: 4 additions & 4 deletions pkg/tso/global_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ func (gta *GlobalTSOAllocator) campaignLeader() {
func (gta *GlobalTSOAllocator) primaryWatch(ctx context.Context, exitPrimary chan struct{}) {
resp, err := etcdutil.EtcdKVGet(gta.member.GetLeadership().GetClient(), gta.member.GetLeaderPath())
if err != nil || resp == nil || len(resp.Kvs) == 0 {
log.Error("[primary] getting the leader meets error", errs.ZapError(err))
log.Error("tso primary getting the primary meets error", errs.ZapError(err))
return
}
log.Info("[primary] start to watch the primary",
log.Info("tso primary start to watch the primary",
logutil.CondUint32("keyspace-group-id", gta.getGroupID(), gta.getGroupID() > 0),
zap.String("campaign-tso-primary-name", gta.member.Name()))
// Watch will keep looping and never return unless the primary has changed.
Expand All @@ -691,18 +691,18 @@ func (gta *GlobalTSOAllocator) primaryWatch(ctx context.Context, exitPrimary cha
// only API update primary will set the expected leader
curPrimary, err := etcdutil.GetValue(gta.member.Client(), gta.member.GetLeaderPath())
if err != nil {
log.Error("[primary] getting the leader meets error", errs.ZapError(err))
log.Error("tso primary getting the leader meets error", errs.ZapError(err))
return

Check warning on line 695 in pkg/tso/global_allocator.go

View check run for this annotation

Codecov / codecov/patch

pkg/tso/global_allocator.go#L694-L695

Added lines #L694 - L695 were not covered by tests
}

if curPrimary != nil && resp.Kvs[0].Value != nil && string(curPrimary) != string(resp.Kvs[0].Value) {
mcsutils.SetExpectedPrimary(gta.member.Client(), gta.member.GetLeaderPath())

gta.member.UnsetLeader()
defer log.Info("tso primary exit the primary watch loop")
for {
select {
case <-ctx.Done():
log.Info("[primary] exit the primary watch loop")
return
case exitPrimary <- struct{}{}:
return
Expand Down

0 comments on commit 2433f0c

Please sign in to comment.