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

*: support mpp partition for tiflash #31043

Merged
merged 32 commits into from
Mar 15, 2022
Merged

Conversation

wshwsh12
Copy link
Contributor

@wshwsh12 wshwsh12 commented Dec 27, 2021

What problem does this PR solve?

Issue Number: close #32347

Problem Summary:

What is changed and how it works?

TiPB: https://github.com/pingcap/tipb/tree/mpp_partition_table
Kvproto: https://github.com/pingcap/kvproto/tree/mpp_partition_table

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Support mpp partition table

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 27, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • windtalker

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 27, 2021
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 8, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 15, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Feb 16, 2022

@wshwsh12 wshwsh12 changed the title [WIP] *: support mpp partition *: support mpp partition for tiflash Feb 16, 2022
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 16, 2022
@wshwsh12
Copy link
Contributor Author

/cc @windtalker

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 22, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2022
@wshwsh12 wshwsh12 requested a review from XuHuaiyu March 14, 2022 16:01
tasks := make([]*kv.MPPTask, 0, len(metas))
for _, meta := range metas {
tasks = append(tasks, &kv.MPPTask{Meta: meta, ID: e.ctx.GetSessionVars().AllocMPPTaskID(e.startTS), StartTs: e.startTS, TableID: tableID})
task := &kv.MPPTask{Meta: meta, ID: e.ctx.GetSessionVars().AllocMPPTaskID(e.startTS), StartTs: e.startTS, TableID: ts.Table.ID, PartitionTableIDs: allPartitionsIDs}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For non-partition table, PartitionTableIDs will be a empty slice instead of nil, is it as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In L338, var allPartitionsIDs []int64 , it will assign allPartitionsIDs to nil. So PartitionTableIDs will be nil when the table is non-partition table..

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 15, 2022
@@ -325,6 +337,41 @@ func (e *TableReaderExecutor) buildKVReqSeparately(ctx context.Context, ranges [
return kvReqs, nil
}

func (e *TableReaderExecutor) buildKVForPartitionTableScan(ctx context.Context, ranges []*ranger.Range) (*kv.Request, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildKVReqForPartitionTableScan ?

Meta *metapb.Region
Ranges *KeyRanges
AllStores []uint64
PartitionIndex int64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment for this attribute

@@ -289,6 +290,9 @@ func (p *PhysicalTableScan) OperatorInfo(normalized bool) string {
if p.stats.StatsVersion == statistics.PseudoVersion && !normalized {
buffer.WriteString(", stats:pseudo")
}
if p.StoreType == kv.TiFlash && p.Table.GetPartitionInfo() != nil && p.IsMPPOrBatchCop && p.ctx.GetSessionVars().UseDynamicPartitionPrune() {
buffer.WriteString(", PartitionTableScan")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for this.

KeyRanges: kvRange,
})
}
if err := updateExecutorTableID(ctx, e.dagPB.RootExecutor, e.table.Meta().ID, true, pids); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.table.Meta().ID is meaningless here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

ret = append(ret, tasks...)
}
return ret, nil
return e.constructMPPTasks(ctx, ts, splitedRanges, partitions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return e.constructMPPTasks(ctx, ts, splitedRanges, partitions)
func (e *mppTaskGenerator) constructMPPTasksImpl(ctx context.Context, ts *PhysicalTableScan) ([]*kv.MPPTask, error) {
...
if ts.Table.GetPartitionInfo() != nil {
req, allPartitionIDs = e.constructMPPBuildTaskReqForPartitionedTable()
} else {
req = e.constructMPPBuildTaskForNonPartitionTable()
}
ttl =
metas =
tasks =
return tasks
...
}

Comment on lines 631 to 653
for _, copTask := range batchTasks {
tableRegions := make([]*coprocessor.TableRegions, len(partitionIDs))
// init coprocessor.TableRegions
for j, pid := range partitionIDs {
tableRegions[j] = &coprocessor.TableRegions{
PhysicalTableId: pid,
}
}
// fill region infos
for _, ri := range copTask.regionInfos {
tableRegions[ri.PartitionIndex].Regions = append(tableRegions[ri.PartitionIndex].Regions,
ri.toCoprocessorRegionInfo())
}
count := 0
// clear empty table region
for j := 0; j < len(tableRegions); j++ {
if len(tableRegions[j].Regions) != 0 {
tableRegions[count] = tableRegions[j]
count++
}
}
copTask.PartitionTableRegions = tableRegions[:count]
copTask.regionInfos = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this code block as an individual function like convertRegionInfosToPartitionTableRegions

// When `partitionIDs != nil`, it means that buildBatchCopTasks is constructing a batch cop tasks for PartitionTableScan.
// At this time, `len(rangesForEachPhysicalTable) == len(partitionIDs)` and `rangesForEachPhysicalTable[i]` is for partition `partitionIDs[i]`.
// Otherwise, `rangesForEachPhysicalTable[0]` indicates the range for the single physical table.
func buildBatchCopTasks(bo *backoff.Backoffer, store *kvStore, rangesForEachPhysicalTable []*KeyRanges, storeType kv.StoreType, mppStoreLastFailTime map[string]time.Time, ttl time.Duration, balanceWithContinuity bool, balanceContinuousRegionCount int64, partitionIDs []int64) ([]*batchCopTask, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a new function as buildBatchCopTasksForPartitionedTable() and rename this old function to buildBatchCopTasksForNonPartitionedTable.

Then we can extract the common code block as buildBatchCopTasksCore()

@@ -628,56 +636,62 @@ func buildBatchCopTasks(bo *backoff.Backoffer, store *kvStore, rangesForEachPhys

// generate tableRegions for batchCopTasks
if partitionIDs != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block can be moved into buildBatchCopTasksForPartitionedTable

keyRanges := []*KeyRanges{ranges}
var partitionIDs []int64
var tasks []*batchCopTask
var err error
if req.PartitionIDAndRanges != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block can be moved into buildBatchCopTasksForPartitionedTable

}
tasks, err = buildBatchCopTasksForPartitionedTable(bo, c.store.kvStore, keyRanges, req.StoreType, nil, 0, false, 0, partitionIDs)
} else {
ranges := NewKeyRanges(req.KeyRanges)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this line into buildBatchCopTasksForNonPartitionedTable

@@ -49,7 +48,8 @@ type batchCopTask struct {
cmdType tikvrpc.CmdType
ctx *tikv.RPCContext

regionInfos []RegionInfo
regionInfos []RegionInfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment for the difference between regionInfos and PartitionTableRegions

}
return distsql.NewSerialSelectResults(results), nil
// Use PartitionTable Scan
kvReq, err := e.buildKVRangeForPartitionTableScan(ctx, ranges)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildKVReq
not buildKVRange

@@ -22,7 +22,7 @@ import (
"github.com/pingcap/tipb/go-tipb"
)

func updateExecutorTableID(ctx context.Context, exec *tipb.Executor, partitionID int64, recursive bool) error {
func updateExecutorTableID(ctx context.Context, exec *tipb.Executor, partitionID int64, recursive bool, partitionIDs []int64) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not only use partitionIDs here, and remove partitionID?

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 15, 2022
@XuHuaiyu
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 53f9366

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 15, 2022
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 15, 2022
@wshwsh12
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: ae08a1f

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 15, 2022
@ti-chi-bot
Copy link
Member

@wshwsh12: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot merged commit 3393cf9 into pingcap:master Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New implementation of partition table support in MPP/BatchCoprocessor
5 participants