Enhancement Task
Background
#10656 switched PD's internal approximateSize from MiB to KiB to improve empty-region detection. During that work we discovered that size values throughout PD are plain int64 with no unit annotation. Fields like LeaderSize, RegionSize, approximateSizeKib carry their unit only in naming conventions, not in the type system.
This caused real bugs: step.go wrote KiB values into StoreInfluence.LeaderSize / RegionSize fields that the store-scoring functions treat as MiB. No compiler error — just silently wrong scheduling decisions.
Proposal
- Introduce a named type
type SizeKiB int64 in pkg/core/ (or pkg/units/).
- Use
SizeKiB for all internal region/store size fields: RegionInfo.approximateSizeKib, StoreInfluence.RegionSize, StoreInfluence.LeaderSize, StoreInfo.regionSize, StoreInfo.leaderSize, thresholds like EmptyRegionApproximateSize, SmallRegionThreshold, etc.
- Drop the separate MiB-denominated fields (
approximateSize, GetApproximateSize() returning MiB). KiB is the single source of truth internally.
- Convert to MiB only at the API/JSON boundary for backward compatibility (
approximate_size in API responses, Prometheus metrics). Plain int64 division at the edge, no SizeMiB type needed.
This makes any MiB/KiB confusion a compile-time error rather than a silent scheduling bug.
Related
Enhancement Task
Background
#10656 switched PD's internal
approximateSizefrom MiB to KiB to improve empty-region detection. During that work we discovered that size values throughout PD are plainint64with no unit annotation. Fields likeLeaderSize,RegionSize,approximateSizeKibcarry their unit only in naming conventions, not in the type system.This caused real bugs:
step.gowrote KiB values intoStoreInfluence.LeaderSize/RegionSizefields that the store-scoring functions treat as MiB. No compiler error — just silently wrong scheduling decisions.Proposal
type SizeKiB int64inpkg/core/(orpkg/units/).SizeKiBfor all internal region/store size fields:RegionInfo.approximateSizeKib,StoreInfluence.RegionSize,StoreInfluence.LeaderSize,StoreInfo.regionSize,StoreInfo.leaderSize, thresholds likeEmptyRegionApproximateSize,SmallRegionThreshold, etc.approximateSize,GetApproximateSize()returning MiB). KiB is the single source of truth internally.approximate_sizein API responses, Prometheus metrics). Plainint64division at the edge, noSizeMiBtype needed.This makes any MiB/KiB confusion a compile-time error rather than a silent scheduling bug.
Related