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

partition: Add extensive reorganize partition test #42000

Merged
merged 7 commits into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions table/tables/BUILD.bazel
Expand Up @@ -64,6 +64,7 @@ go_test(
timeout = "short",
srcs = [
"cache_test.go",
"export_test.go",
"index_test.go",
"main_test.go",
"mutation_checker_test.go",
Expand Down Expand Up @@ -102,6 +103,7 @@ go_test(
"//util/codec",
"//util/collate",
"//util/dbterror",
"//util/logutil",
"//util/mock",
"//util/rowcodec",
"//util/stmtsummary",
Expand All @@ -113,5 +115,6 @@ go_test(
"@com_github_tikv_client_go_v2//oracle",
"@org_golang_google_grpc//:grpc",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_zap//:zap",
],
)
35 changes: 35 additions & 0 deletions table/tables/export_test.go
@@ -0,0 +1,35 @@
// Copyright 2023 PingCAP, Inc.
mjonss marked this conversation as resolved.
Show resolved Hide resolved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tables

import "github.com/pingcap/tidb/table"

func SwapReorgPartFields(src, dst table.Table) bool {
s, ok := src.(*partitionedTable)
if !ok {
return false
}
d, ok := dst.(*partitionedTable)
if !ok {
return false
}
d.reorganizePartitions, s.reorganizePartitions = s.reorganizePartitions, d.reorganizePartitions
d.meta, s.meta = s.meta, d.meta
d.partitions, s.partitions = s.partitions, d.partitions
d.doubleWritePartitions, s.doubleWritePartitions = s.doubleWritePartitions, d.doubleWritePartitions
d.reorgPartitionExpr, s.reorgPartitionExpr = s.reorgPartitionExpr, d.reorgPartitionExpr
d.partitionExpr, s.partitionExpr = s.partitionExpr, d.partitionExpr
return true
}
12 changes: 9 additions & 3 deletions table/tables/partition.go
Expand Up @@ -99,7 +99,7 @@ type partitionedTable struct {
// Only used during Reorganize partition
// reorganizePartitions is the currently used partitions that are reorganized
reorganizePartitions map[int64]interface{}
// doubleWriteParittions are the partitions not visible, but we should double write to
// doubleWritePartitions are the partitions not visible, but we should double write to
doubleWritePartitions map[int64]interface{}
reorgPartitionExpr *PartitionExpr
}
Expand Down Expand Up @@ -1453,6 +1453,9 @@ func partitionedTableAddRecord(ctx sessionctx.Context, t *partitionedTable, r []
if err != nil {
return
}
if t.Meta().Partition.DDLState == model.StateDeleteOnly {
return
}
if _, ok := t.reorganizePartitions[pid]; ok {
// Double write to the ongoing reorganized partition
pid, err = t.locateReorgPartition(ctx, r)
Expand Down Expand Up @@ -1640,9 +1643,12 @@ func partitionedTableUpdateRecord(gctx context.Context, ctx sessionctx.Context,
return errors.Trace(err)
}
if newTo == newFrom {
// Update needs to be done in StateDeleteOnly as well
tbl = t.GetPartition(newTo)
err = tbl.UpdateRecord(gctx, ctx, h, currData, newData, touched)
if t.Meta().Partition.DDLState == model.StateDeleteOnly {
err = tbl.RemoveRecord(ctx, h, currData)
Copy link
Member

Choose a reason for hiding this comment

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

It's hard for me to follow this. Will there any issue if we do not change 'UpdateRecord' to 'RemoveRecord'?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the primary key change, UpdateRecord is equal to RemoveRecord + AddRecord
If the primary key is unchanged, UpdateRecord is UpdateRecord, literally @bb7133

} else {
err = tbl.UpdateRecord(gctx, ctx, h, currData, newData, touched)
}
if err != nil {
return errors.Trace(err)
}
Expand Down