Skip to content

Commit

Permalink
discover faster
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Aug 23, 2024
1 parent b5a873e commit f2c0c14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ func (c *RaftCluster) checkTSOService() {
// leader tso service exit, tso independent service provide tso
c.tsoAllocator.ResetAllocatorGroup(tso.GlobalDCLocation, true)
}
if !c.IsServiceIndependent(constant.TSOServiceName) {
log.Info("TSO server starts to provide timestamp")
}
c.SetServiceIndependent(constant.TSOServiceName)
} else {
if !allocator.IsInitialize() {
Expand All @@ -419,6 +422,9 @@ func (c *RaftCluster) checkTSOService() {
return
}
}
if c.IsServiceIndependent(constant.TSOServiceName) {
log.Info("PD server starts to provide timestamp")
}
c.UnsetServiceIndependent(constant.TSOServiceName)
}
} else {
Expand Down
7 changes: 7 additions & 0 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/mcs/discovery"
"github.com/tikv/pd/pkg/mcs/utils/constant"
"github.com/tikv/pd/pkg/storage/endpoint"
"github.com/tikv/pd/pkg/storage/kv"
Expand Down Expand Up @@ -274,6 +275,11 @@ func (s *GrpcServer) GetClusterInfo(context.Context, *pdpb.GetClusterInfoRequest

var tsoServiceAddrs []string
svcModes := make([]pdpb.ServiceMode, 0)

servers, err := discovery.Discover(s.client, strconv.FormatUint(s.ClusterID(), 10), constant.TSOServiceName)
if err == nil && len(servers) != 0 {
s.GetRaftCluster().SetServiceIndependent(constant.TSOServiceName)
}
if s.IsAPIServiceMode() && s.GetRaftCluster().IsServiceIndependent(constant.TSOServiceName) {
svcModes = append(svcModes, pdpb.ServiceMode_API_SVC_MODE)
tsoServiceAddrs = s.keyspaceGroupManager.GetTSOServiceAddrs()
Expand Down Expand Up @@ -524,6 +530,7 @@ func (s *GrpcServer) Tso(stream pdpb.PD_TsoServer) error {
return err
}
}

if s.IsAPIServiceMode() && s.GetRaftCluster().IsServiceIndependent(constant.TSOServiceName) {
return s.forwardTSO(stream)
}
Expand Down

0 comments on commit f2c0c14

Please sign in to comment.