@@ -144,8 +144,9 @@ const (
144144func RegionFromHeartbeat (heartbeat * pdpb.RegionHeartbeatRequest , opts ... RegionCreateOption ) * RegionInfo {
145145 // Convert unit to MB.
146146 // If region isn't empty and less than 1MB, use 1MB instead.
147- // The size of empty region will be correct by the previous RegionInfo.
148147 regionSize := heartbeat .GetApproximateSize () / units .MiB
148+ // Due to https://github.com/tikv/tikv/pull/11170, if region size is not initialized,
149+ // approximate size will be zero, and region size is zero not EmptyRegionApproximateSize
149150 if heartbeat .GetApproximateSize () > 0 && regionSize < EmptyRegionApproximateSize {
150151 regionSize = EmptyRegionApproximateSize
151152 }
@@ -188,19 +189,9 @@ func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest, opts ...RegionC
188189 return region
189190}
190191
191- // Inherit inherits the buckets and region size from the parent region if bucket enabled.
192- // correct approximate size and buckets by the previous size if here exists a reported RegionInfo.
193- // See https://github.com/tikv/tikv/issues/11114
194- func (r * RegionInfo ) Inherit (origin * RegionInfo , bucketEnable bool ) {
195- // regionSize should not be zero if region is not empty.
196- if r .GetApproximateSize () == 0 {
197- if origin != nil {
198- r .approximateSize = origin .approximateSize
199- } else {
200- r .approximateSize = EmptyRegionApproximateSize
201- }
202- }
203- if bucketEnable && origin != nil && r .buckets == nil {
192+ // InheritBuckets inherits the buckets from the parent region if bucket enabled.
193+ func (r * RegionInfo ) InheritBuckets (origin * RegionInfo ) {
194+ if origin != nil && r .buckets == nil {
204195 r .buckets = origin .buckets
205196 }
206197}
@@ -478,6 +469,13 @@ func (r *RegionInfo) GetApproximateSize() int64 {
478469 return r .approximateSize
479470}
480471
472+ // IsEmptyRegion returns whether the region is empty.
473+ func (r * RegionInfo ) IsEmptyRegion () bool {
474+ // When cluster resumes, the region size may be not initialized, but region heartbeat is send.
475+ // So use `==` here.
476+ return r .approximateSize == EmptyRegionApproximateSize
477+ }
478+
481479// GetApproximateKeys returns the approximate keys of the region.
482480func (r * RegionInfo ) GetApproximateKeys () int64 {
483481 return r .approximateKeys
0 commit comments