@@ -144,9 +144,8 @@ 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.
147148 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
150149 if heartbeat .GetApproximateSize () > 0 && regionSize < EmptyRegionApproximateSize {
151150 regionSize = EmptyRegionApproximateSize
152151 }
@@ -189,9 +188,19 @@ func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest, opts ...RegionC
189188 return region
190189}
191190
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 {
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 {
195204 r .buckets = origin .buckets
196205 }
197206}
@@ -469,13 +478,6 @@ func (r *RegionInfo) GetApproximateSize() int64 {
469478 return r .approximateSize
470479}
471480
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-
479481// GetApproximateKeys returns the approximate keys of the region.
480482func (r * RegionInfo ) GetApproximateKeys () int64 {
481483 return r .approximateKeys
0 commit comments