Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external: range job keys and region split keys are 2 concepts (part 1) #55659

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/ddl/backfilling_dist_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type BackfillSubTaskMeta struct {
RowEnd []byte `json:"row_end"`

// Used by global sort write & ingest step.
RangeJobKeys [][]byte `json:"range_job_keys,omitempty"`
RangeSplitKeys [][]byte `json:"range_split_keys,omitempty"`
DataFiles []string `json:"data-files,omitempty"`
StatFiles []string `json:"stat-files,omitempty"`
Expand Down
18 changes: 11 additions & 7 deletions pkg/ddl/backfilling_dist_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func splitSubtaskMetaForOneKVMetaGroup(
startKey := kvMeta.StartKey
var endKey kv.Key
for {
endKeyOfGroup, dataFiles, statFiles, rangeSplitKeys, err := splitter.SplitOneRangesGroup()
endKeyOfGroup, dataFiles, statFiles, rangeJobKeys, regionSplitKeys, err := splitter.SplitOneRangesGroup()
if err != nil {
return nil, err
}
Expand All @@ -472,7 +472,8 @@ func splitSubtaskMetaForOneKVMetaGroup(
}},
DataFiles: dataFiles,
StatFiles: statFiles,
RangeSplitKeys: rangeSplitKeys,
RangeJobKeys: rangeJobKeys,
RangeSplitKeys: regionSplitKeys,
TS: ts,
}
if eleID > 0 {
Expand Down Expand Up @@ -596,16 +597,16 @@ func getRangeSplitter(
rangeGroupSize := totalSize / instanceCnt
rangeGroupKeys := int64(math.MaxInt64)

var maxSizePerRange = int64(config.SplitRegionSize)
var maxKeysPerRange = int64(config.SplitRegionKeys)
var regionSplitSize = int64(config.SplitRegionSize)
var regionSplitKeys = int64(config.SplitRegionKeys)
if store != nil {
pdCli := store.GetPDClient()
tls, err := ingest.NewDDLTLS()
if err == nil {
size, keys, err := local.GetRegionSplitSizeKeys(ctx, pdCli, tls)
if err == nil {
maxSizePerRange = max(maxSizePerRange, size)
maxKeysPerRange = max(maxKeysPerRange, keys)
regionSplitSize = max(regionSplitSize, size)
regionSplitKeys = max(regionSplitKeys, keys)
} else {
logger.Warn("fail to get region split keys and size", zap.Error(err))
}
Expand All @@ -614,8 +615,11 @@ func getRangeSplitter(
}
}

// no matter region split size and keys, we always split range jobs by 96MB
return external.NewRangeSplitter(ctx, multiFileStat, extStore,
rangeGroupSize, rangeGroupKeys, maxSizePerRange, maxKeysPerRange)
rangeGroupSize, rangeGroupKeys,
int64(config.SplitRegionSize), int64(config.SplitRegionKeys),
regionSplitSize, regionSplitKeys)
}

func forEachBackfillSubtaskMeta(
Expand Down
6 changes: 6 additions & 0 deletions pkg/ddl/backfilling_import_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,19 @@ func (m *cloudImportExecutor) RunSubtask(ctx context.Context, subtask *proto.Sub
all.Merge(g)
}

// compatible with old version TiDB
jobKeys := sm.RangeJobKeys
if jobKeys == nil {
jobKeys = sm.RangeSplitKeys
}
err = local.CloseEngine(ctx, &backend.EngineConfig{
External: &backend.ExternalEngineConfig{
StorageURI: m.cloudStoreURI,
DataFiles: sm.DataFiles,
StatFiles: sm.StatFiles,
StartKey: all.StartKey,
EndKey: all.EndKey,
JobKeys: jobKeys,
SplitKeys: sm.RangeSplitKeys,
TotalFileSize: int64(all.TotalKVSize),
TotalKVCount: 0,
Expand Down
9 changes: 6 additions & 3 deletions pkg/disttask/importinto/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func generateWriteIngestSpecs(planCtx planner.PlanCtx, p *LogicalPlan) ([]planne
startKey := tidbkv.Key(kvMeta.StartKey)
var endKey tidbkv.Key
for {
endKeyOfGroup, dataFiles, statFiles, rangeSplitKeys, err2 := splitter.SplitOneRangesGroup()
endKeyOfGroup, dataFiles, statFiles, rangeJobKeys, regionSplitKeys, err2 := splitter.SplitOneRangesGroup()
if err2 != nil {
return err2
}
Expand Down Expand Up @@ -415,8 +415,8 @@ func generateWriteIngestSpecs(planCtx planner.PlanCtx, p *LogicalPlan) ([]planne
},
DataFiles: dataFiles,
StatFiles: statFiles,
RangeSplitKeys: rangeSplitKeys,
RangeSplitSize: splitter.GetRangeSplitSize(),
RangeJobKeys: rangeJobKeys,
RangeSplitKeys: regionSplitKeys,
TS: ts,
}
specs = append(specs, &WriteIngestSpec{m})
Expand Down Expand Up @@ -516,12 +516,15 @@ func getRangeSplitter(ctx context.Context, store storage.ExternalStorage, kvMeta
zap.Int64("region-split-size", regionSplitSize),
zap.Int64("region-split-keys", regionSplitKeys))

// no matter region split size and keys, we always split range jobs by 96MB
return external.NewRangeSplitter(
ctx,
kvMeta.MultipleFilesStats,
store,
int64(config.DefaultBatchSize),
int64(math.MaxInt64),
int64(config.SplitRegionSize),
int64(config.SplitRegionKeys),
regionSplitSize,
regionSplitKeys,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/disttask/importinto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ type WriteIngestStepMeta struct {
external.SortedKVMeta `json:"sorted-kv-meta"`
DataFiles []string `json:"data-files"`
StatFiles []string `json:"stat-files"`
RangeJobKeys [][]byte `json:"range-job-keys"`
RangeSplitKeys [][]byte `json:"range-split-keys"`
RangeSplitSize int64 `json:"range-split-size"`
TS uint64 `json:"ts"`

Result Result
Expand Down
25 changes: 15 additions & 10 deletions pkg/disttask/importinto/task_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,23 @@ func (e *writeAndIngestStepExecutor) RunSubtask(ctx context.Context, subtask *pr
_, engineUUID := backend.MakeUUID("", subtask.ID)
localBackend := e.tableImporter.Backend()
localBackend.WorkerConcurrency = subtask.Concurrency * 2
// compatible with old version TiDB
lance6716 marked this conversation as resolved.
Show resolved Hide resolved
jobKeys := sm.RangeJobKeys
if jobKeys == nil {
jobKeys = sm.RangeSplitKeys
}
err = localBackend.CloseEngine(ctx, &backend.EngineConfig{
External: &backend.ExternalEngineConfig{
StorageURI: e.taskMeta.Plan.CloudStorageURI,
DataFiles: sm.DataFiles,
StatFiles: sm.StatFiles,
StartKey: sm.StartKey,
EndKey: sm.EndKey,
SplitKeys: sm.RangeSplitKeys,
RegionSplitSize: sm.RangeSplitSize,
TotalFileSize: int64(sm.TotalKVSize),
TotalKVCount: 0,
CheckHotspot: false,
StorageURI: e.taskMeta.Plan.CloudStorageURI,
DataFiles: sm.DataFiles,
StatFiles: sm.StatFiles,
StartKey: sm.StartKey,
EndKey: sm.EndKey,
JobKeys: jobKeys,
SplitKeys: sm.RangeSplitKeys,
TotalFileSize: int64(sm.TotalKVSize),
TotalKVCount: 0,
CheckHotspot: false,
},
TS: sm.TS,
}, engineUUID)
Expand Down
14 changes: 7 additions & 7 deletions pkg/lightning/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ type LocalEngineConfig struct {

// ExternalEngineConfig is the configuration used for local backend external engine.
type ExternalEngineConfig struct {
StorageURI string
DataFiles []string
StatFiles []string
StartKey []byte
EndKey []byte
SplitKeys [][]byte
RegionSplitSize int64
StorageURI string
DataFiles []string
StatFiles []string
StartKey []byte
EndKey []byte
JobKeys [][]byte
SplitKeys [][]byte
// TotalFileSize can be an estimated value.
TotalFileSize int64
// TotalKVCount can be an estimated value.
Expand Down
14 changes: 6 additions & 8 deletions pkg/lightning/backend/external/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func NewExternalEngine(
startKey []byte,
endKey []byte,
splitKeys [][]byte,
regionSplitSize int64,
keyAdapter common.KeyAdapter,
duplicateDetection bool,
duplicateDB *pebble.DB,
Expand All @@ -153,13 +152,12 @@ func NewExternalEngine(
) common.Engine {
memLimiter := membuf.NewLimiter(memLimit)
return &Engine{
storage: storage,
dataFiles: dataFiles,
statsFiles: statsFiles,
startKey: startKey,
endKey: endKey,
splitKeys: splitKeys,
regionSplitSize: regionSplitSize,
storage: storage,
dataFiles: dataFiles,
statsFiles: statsFiles,
startKey: startKey,
endKey: endKey,
splitKeys: splitKeys,
smallBlockBufPool: membuf.NewPool(
membuf.WithBlockNum(0),
membuf.WithPoolMemoryLimiter(memLimiter),
Expand Down
4 changes: 3 additions & 1 deletion pkg/lightning/backend/external/merge_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func MergeOverlappingFilesV2(
math.MaxInt64,
int64(4*size.GB),
math.MaxInt64,
math.MaxInt64,
math.MaxInt64,
)
if err != nil {
return err
Expand Down Expand Up @@ -114,7 +116,7 @@ func MergeOverlappingFilesV2(
var curEnd kv.Key

for {
endKeyOfGroup, dataFilesOfGroup, statFilesOfGroup, _, err1 := splitter.SplitOneRangesGroup()
endKeyOfGroup, dataFilesOfGroup, statFilesOfGroup, _, _, err1 := splitter.SplitOneRangesGroup()
if err1 != nil {
logutil.Logger(ctx).Warn("split one ranges group failed", zap.Error(err1))
return
Expand Down
Loading