Skip to content

Commit

Permalink
partition: Add extensive reorganize partition test (#42000)
Browse files Browse the repository at this point in the history
ref #38535
  • Loading branch information
mjonss committed Mar 20, 2023
1 parent 3f8b0cc commit 8982c03
Show file tree
Hide file tree
Showing 5 changed files with 711 additions and 27 deletions.
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.
//
// 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 @@ -1476,6 +1476,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 @@ -1663,9 +1666,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)
} else {
err = tbl.UpdateRecord(gctx, ctx, h, currData, newData, touched)
}
if err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit 8982c03

Please sign in to comment.