Skip to content

Commit 29d3246

Browse files
committed
pkg/ddl,planner: add TiKV space precheck for DXF add-index
1 parent ee9df2a commit 29d3246

10 files changed

Lines changed: 1937 additions & 180 deletions

File tree

docs/plans/2026-05-14-add-index-tikv-space-precheck.md

Lines changed: 243 additions & 0 deletions
Large diffs are not rendered by default.

pkg/ddl/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ go_library(
138138
"//pkg/parser/opcode",
139139
"//pkg/parser/terror",
140140
"//pkg/parser/types",
141+
"//pkg/planner/util/rowsize",
141142
"//pkg/privilege",
142143
"//pkg/resourcegroup",
143144
"//pkg/resourcemanager/pool/workerpool",

pkg/ddl/backfilling_dist_executor.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,20 @@ type BackfillTaskMeta struct {
4848
// For now, only index type is supported.
4949
EleTypeKey []byte `json:"ele_type_key"`
5050

51-
CloudStorageURI string `json:"cloud_storage_uri"`
52-
EstimateRowSize int `json:"estimate_row_size"`
53-
MergeTempIndex bool `json:"merge_temp_index"`
54-
InitialTiKVStoreUsage *TiKVStoreUsageSnapshot `json:"initial_tikv_store_usage,omitempty"`
51+
CloudStorageURI string `json:"cloud_storage_uri"`
52+
EstimateRowSize int `json:"estimate_row_size"`
53+
MergeTempIndex bool `json:"merge_temp_index"`
54+
InitialTiKVStoreUsage *TiKVStoreUsageSnapshot `json:"initial_tikv_store_usage,omitempty"`
55+
InitialTiKVCapacity *TiKVClusterCapacity `json:"initial_tikv_capacity,omitempty"`
56+
BasicPredictedTiKVIndexBytes uint64 `json:"basic_predicted_tikv_index_bytes,omitempty"`
57+
RepresentPredictedTiKVIndexBytes uint64 `json:"represent_predicted_tikv_index_bytes,omitempty"`
58+
SamplePredictedTiKVIndexBytes uint64 `json:"sample_predicted_tikv_index_bytes,omitempty"`
59+
SamplePredictionRegionCount int `json:"sample_prediction_region_count,omitempty"`
60+
SamplePredictionRowCount int `json:"sample_prediction_row_count,omitempty"`
61+
SamplePredictionReadErrorCount int `json:"sample_prediction_read_error_count,omitempty"`
62+
// PredictedTiKVIndexBytes is kept for compatibility with task metadata written by
63+
// earlier builds. New task submissions store the sample-model prediction here.
64+
PredictedTiKVIndexBytes uint64 `json:"predicted_tikv_index_bytes,omitempty"`
5565

5666
Version int `json:"version,omitempty"`
5767
}
@@ -62,6 +72,24 @@ type TiKVStoreUsageSnapshot struct {
6272
StoreCount int `json:"store_count"`
6373
}
6474

75+
// TiKVStoreCapacity contains per-store capacity details needed by DXF add-index
76+
// capacity precheck and post-task observation.
77+
type TiKVStoreCapacity struct {
78+
StoreID int64 `json:"store_id"`
79+
TotalBytes uint64 `json:"total_bytes"`
80+
AvailableBytes uint64 `json:"available_bytes"`
81+
UsedBytes uint64 `json:"used_bytes"`
82+
}
83+
84+
// TiKVClusterCapacity is the aggregated TiKV capacity snapshot collected from PD.
85+
type TiKVClusterCapacity struct {
86+
TotalBytes uint64 `json:"total_bytes"`
87+
AvailableBytes uint64 `json:"available_bytes"`
88+
UsedBytes uint64 `json:"used_bytes"`
89+
StoreCount int `json:"store_count"`
90+
Stores []TiKVStoreCapacity `json:"stores,omitempty"`
91+
}
92+
6593
// BackfillSubTaskMeta is the sub-task meta for backfilling index.
6694
type BackfillSubTaskMeta struct {
6795
external.BaseExternalMeta

0 commit comments

Comments
 (0)