Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server:add querystats sync to follower pd #4922

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions server/region_syncer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
stats := resp.GetRegionStats()
regions := resp.GetRegions()
buckets := resp.GetBuckets()
queryStats := resp.GetQueryStats()
regionLeaders := resp.GetRegionLeaders()
hasStats := len(stats) == len(regions)
hasBuckets := len(buckets) == len(regions)
hasQueryStats := len(queryStats) == len(regions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it merge to hasStats?

for i, r := range regions {
var (
region *core.RegionInfo
Expand Down Expand Up @@ -224,6 +226,9 @@ func (s *RegionSyncer) StartSyncWithLeader(addr string) {
region.UpdateBuckets(buckets[i], old)
}
}
if hasQueryStats {
region.QueryStats = queryStats[i]
}
if saveKV {
err = regionStorage.SaveRegion(r)
}
Expand Down
10 changes: 10 additions & 0 deletions server/region_syncer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (s *RegionSyncer) RunServer(ctx context.Context, regionNotifier <-chan *cor
var stats []*pdpb.RegionStat
var leaders []*metapb.Peer
var buckets []*metapb.Buckets
var queryStats []*pdpb.QueryStats
ticker := time.NewTicker(syncerKeepAliveInterval)

defer func() {
Expand All @@ -137,6 +138,7 @@ func (s *RegionSyncer) RunServer(ctx context.Context, regionNotifier <-chan *cor
}
buckets = append(buckets, bucket)
leaders = append(leaders, first.GetLeader())
queryStats = append(queryStats, first.QueryStats)
startIndex := s.history.GetNextIndex()
s.history.Record(first)
pending := len(regionNotifier)
Expand All @@ -151,6 +153,7 @@ func (s *RegionSyncer) RunServer(ctx context.Context, regionNotifier <-chan *cor
}
buckets = append(buckets, bucket)
leaders = append(leaders, region.GetLeader())
queryStats = append(queryStats, region.QueryStats)
s.history.Record(region)
}
regions := &pdpb.SyncRegionResponse{
Expand All @@ -160,6 +163,7 @@ func (s *RegionSyncer) RunServer(ctx context.Context, regionNotifier <-chan *cor
RegionStats: stats,
RegionLeaders: leaders,
Buckets: buckets,
QueryStats: queryStats,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can queryStats be merge into ReginStats?

}
s.broadcast(regions)
case <-ticker.C:
Expand Down Expand Up @@ -240,6 +244,7 @@ func (s *RegionSyncer) syncHistoryRegion(ctx context.Context, request *pdpb.Sync
stats := make([]*pdpb.RegionStat, 0, maxSyncRegionBatchSize)
leaders := make([]*metapb.Peer, 0, maxSyncRegionBatchSize)
buckets := make([]*metapb.Buckets, 0, maxSyncRegionBatchSize)
queryStats := make([]*pdpb.QueryStats, 0, maxSyncRegionBatchSize)
for syncedIndex, r := range regions {
select {
case <-ctx.Done():
Expand All @@ -263,6 +268,7 @@ func (s *RegionSyncer) syncHistoryRegion(ctx context.Context, request *pdpb.Sync
bucket = r.GetBuckets()
}
buckets = append(buckets, bucket)
queryStats = append(queryStats, r.QueryStats)
if len(metas) < maxSyncRegionBatchSize && syncedIndex < len(regions)-1 {
continue
}
Expand All @@ -273,6 +279,7 @@ func (s *RegionSyncer) syncHistoryRegion(ctx context.Context, request *pdpb.Sync
RegionStats: stats,
RegionLeaders: leaders,
Buckets: buckets,
QueryStats: queryStats,
}
s.limit.WaitN(ctx, resp.Size())
lastIndex += len(metas)
Expand Down Expand Up @@ -301,6 +308,7 @@ func (s *RegionSyncer) syncHistoryRegion(ctx context.Context, request *pdpb.Sync
stats := make([]*pdpb.RegionStat, len(records))
leaders := make([]*metapb.Peer, len(records))
buckets := make([]*metapb.Buckets, len(records))
queryStats := make([]*pdpb.QueryStats, len(records))
for i, r := range records {
regions[i] = r.GetMeta()
stats[i] = r.GetStat()
Expand All @@ -314,6 +322,7 @@ func (s *RegionSyncer) syncHistoryRegion(ctx context.Context, request *pdpb.Sync
if r.GetBuckets() != nil {
buckets[i] = r.GetBuckets()
}
queryStats[i] = r.QueryStats
}
resp := &pdpb.SyncRegionResponse{
Header: &pdpb.ResponseHeader{ClusterId: s.server.ClusterID()},
Expand All @@ -322,6 +331,7 @@ func (s *RegionSyncer) syncHistoryRegion(ctx context.Context, request *pdpb.Sync
RegionStats: stats,
RegionLeaders: leaders,
Buckets: buckets,
QueryStats: queryStats,
}
return stream.Send(resp)
}
Expand Down