Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: bufferflies <1045931706@qq.com>
  • Loading branch information
bufferflies committed Mar 29, 2022
1 parent e35ec2f commit b20dd37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
17 changes: 5 additions & 12 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const (
// since the once the store is add or remove, we shouldn't return an error even if the store limit is failed to persist.
persistLimitRetryTimes = 5
persistLimitWaitTime = 100 * time.Millisecond
retry = 3
)

// Server is the interface for cluster.
Expand Down Expand Up @@ -615,18 +614,12 @@ func (c *RaftCluster) processBucketHeartbeat(buckets *metapb.Buckets) error {
return errors.Errorf("region %v not found", buckets.GetRegionId())
}

for i := 0; i < retry; i++ {
old := region.GetBuckets()
// region should not update if the version of the buckets is less than the old one.
if old != nil && old.Version >= buckets.Version {
bucketEventCounter.WithLabelValues("version_not_match").Inc()
return nil
}
if ok := region.UpdateBuckets(buckets); ok {
bucketEventCounter.WithLabelValues("update_cache").Inc()
return nil
}
// region should not update if the version of the buckets is less than the old one.
if old := region.GetBuckets(); old != nil && old.Version >= buckets.Version {
bucketEventCounter.WithLabelValues("version_not_match").Inc()
return nil
}
region.UpdateBuckets(buckets)
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions server/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,18 @@ func (r *RegionInfo) GetStat() *pdpb.RegionStat {
}

// UpdateBuckets sets the buckets of the region.
func (r *RegionInfo) UpdateBuckets(buckets *metapb.Buckets) bool {
// bucket is only nil in test cases.
func (r *RegionInfo) UpdateBuckets(buckets *metapb.Buckets) {
// the bucket can't be nil except in the test cases.
if buckets == nil {
return true
return
}
// only need to update bucket keys,versions.
newBuckets := &metapb.Buckets{
RegionId: buckets.GetRegionId(),
Version: buckets.GetVersion(),
Keys: buckets.GetKeys(),
}
return atomic.CompareAndSwapPointer(&r.buckets, r.buckets, unsafe.Pointer(newBuckets))
atomic.StorePointer(&r.buckets, unsafe.Pointer(newBuckets))
}

// GetBuckets returns the buckets of the region.
Expand Down
1 change: 0 additions & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ func (s *GrpcServer) ReportBuckets(stream pdpb.PD_ReportBucketsServer) error {
}
err = rc.HandleBucketHeartbeat(request.Buckets)
if err != nil {
log.Warn("update bucket failed", zap.Error(err))
bucketReportCounter.WithLabelValues("report", "err").Inc()
continue
}
Expand Down

0 comments on commit b20dd37

Please sign in to comment.