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 7d81749
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 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
6 changes: 3 additions & 3 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 {
func (r *RegionInfo) UpdateBuckets(buckets *metapb.Buckets) {
// bucket is only nil in 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

0 comments on commit 7d81749

Please sign in to comment.