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

ddl: implement reorganize for table partition when adding index #6814

Merged
merged 43 commits into from Jul 27, 2018

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Jun 11, 2018

What have you changed? (mandatory)

  • Handle DDL reorganize for table partitions one by one
  • Reorganize meta key changed from handle to startHandle, endHandle, partitionID

Please NOTE that:

This PR changes the DDL reorganize meta key, reviewer should be careful with the rolling update!

What are the type of the changes (mandatory)?

  • New feature (non-breaking change which adds functionality)

How has this PR been tested (mandatory)?

unit test

Add a few positive/negative examples (optional)

@tiancaiamao tiancaiamao changed the title [WIP] ddl: implement reorganize for table partition when adding index ddl: implement reorganize for table partition when adding index Jun 29, 2018
@tiancaiamao
Copy link
Contributor Author

PTAL @zimulala @ciscoxll @winkyao

ddl/reorg.go Outdated
// PartitionID returns the partition ID of the reorgInfo, or table ID if it's not a partition.
func (r *reorgInfo) PartitionID() int64 {
ret := r.Job.ID
if r.Job.ReorgMeta != nil && r.Job.ReorgMeta.PartitionID != 0 {
Copy link
Contributor

@ciscoxll ciscoxll Jul 2, 2018

Choose a reason for hiding this comment

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

s/r.Job.ReorgMeta.PartitionID != 0/ r.Job.ReorgMeta.PartitionID != r.Job.ID @tiancaiamao .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

job.ID has nothing to do with TableID or PartitionID @ciscoxll

Copy link
Contributor

@ciscoxll ciscoxll Jul 3, 2018

Choose a reason for hiding this comment

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

@tiancaiamao You look at the code, if the normal table GetPartitionInfo gets a failure result, what might happen?

@tiancaiamao tiancaiamao added require-LGT3 Indicates that the PR requires three LGTM. priority/non-release-blocker priority/P2 labels Jul 4, 2018
@zimulala zimulala removed the require-LGT3 Indicates that the PR requires three LGTM. label Jul 4, 2018
}

s.tk.MustExec("alter table t add index idx (hired)")
// TODO: Make admin check table work for partition.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix this TODO after this PR is merged https://github.com/pingcap/tidb/pull/6963/files,
because admin check table would benefit from that refactor.

@zz-jason zz-jason added this to In Progress in Table Partitioning via automation Jul 6, 2018
@zz-jason zz-jason added this to the 2.1 milestone Jul 6, 2018
ddl/index.go Outdated
idx := -1
for i, def := range defs {
if partitionID == def.ID {
idx = i
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 use "ID" directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "ID" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The partition's ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the comment of this function:

// findNextPartitionID finds the next partition ID in the PartitionDefinition.
// Returns -1 if this partitionID is the last one.

This function find the next partition ID, using offset is more convenient. @zimulala

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we write it as follows code?

if partitionID == def.ID {
    if i == len(defs)-1{
        return 0
    }else{
        return def[i+1].ID
    }
}

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 26, 2018
@shenli
Copy link
Member

shenli commented Jul 26, 2018

LGTM

@@ -684,9 +683,11 @@ func (w *addIndexWorker) handleBackfillTask(d *ddlCtx, task *reorgIndexTask) *ad
result := &addIndexResult{addedCount: 0, nextHandle: handleRange.startHandle, err: nil}
lastLogCount := 0
startTime := time.Now()
index := tables.NewIndex(task.partitionID, w.table.Meta(), w.indexInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

task.partitionID confuses me, we need to do a refactor after this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shenli is doing that.

ddl/reorg.go Outdated
}

func (r *reorgInfo) UpdateHandle(txn kv.Transaction, handle int64) error {
func (r *reorgInfo) UpdateHandle(txn kv.Transaction, startHandle, endHandle, partitionID 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.

Could we name the UpdateHandle to UpdateReorgMeta, or something else?

@tiancaiamao
Copy link
Contributor Author

PTAL @winkyao

@@ -149,7 +149,7 @@ func (w *worker) runReorgJob(t *meta.Meta, reorgInfo *reorgInfo, lease time.Dura
// Update a job's RowCount.
job.SetRowCount(rowCount)
// Update a reorgInfo's handle.
err := t.UpdateDDLReorgHandle(job, doneHandle)
err := t.UpdateDDLReorgStartHandle(job, doneHandle)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we update the endHandle and the partitionID herer?

Copy link
Contributor

@winkyao winkyao Jul 27, 2018

Choose a reason for hiding this comment

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

If we not, when we are adding partition id 2 indices, and we crashed, then the startHandle set to 1000, then after we restart the job, we will get previous partition id, and the incorrect startHandle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is compatible to the old one.
The reorgInfo will not change to another partition automatically, the only place to do it is in function updateReorgInfo.
I think update both the endHandle and the partitionID here would bring more uncertain things.

Copy link
Contributor

@winkyao winkyao Jul 27, 2018

Choose a reason for hiding this comment

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

So maybe we can call reorgInfo.UpdateReorgMeta in handleReorgTasks when the err is nil?

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

request changes.

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

@zimulala @shenli

@shenli shenli merged commit 6815dec into pingcap:master Jul 27, 2018
Table Partitioning automation moved this from In Progress to Done Jul 27, 2018
@tiancaiamao tiancaiamao deleted the reorg-table-partition branch July 27, 2018 11:03
@ciscoxll ciscoxll added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 3, 2018
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
@zz-jason zz-jason moved this from Issue: Done to PR: Donw in Table Partitioning Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P2 sig/sql-infra SIG: SQL Infra status/LGT3 The PR has already had 3 LGTM.
Projects
No open projects
Table Partitioning
  
PR: Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants