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: Added tests for Reorganize Partition with TiFlash #42082

Merged
merged 214 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
214 commits
Select commit Hold shift + click to select a range
cddba93
WIP: Support REORGANIZE PARTITION
mjonss Aug 20, 2022
4013303
ddl: support modify column on partitioned table
mjonss Oct 5, 2022
a8a0d2c
Fixed tests
mjonss Oct 5, 2022
8ada652
Merge remote-tracking branch 'pingcap/master' into allow-mod-col-on-part
mjonss Oct 5, 2022
2458678
WIP reorganize partition
mjonss Oct 6, 2022
d7437c5
Merge branch 'allow-mod-col-on-part' into reorganize-partition
mjonss Oct 6, 2022
6bc2909
WIP starting to work \o/
mjonss Oct 7, 2022
9adfd25
Updated test
mjonss Oct 7, 2022
5356f77
Test update
mjonss Oct 7, 2022
913e503
Fixed some issues
mjonss Oct 7, 2022
f42852f
Lint fix
mjonss Oct 10, 2022
20a98ea
Fixed linting
mjonss Oct 10, 2022
2bfe6dd
Only do DroppingDefinitions during REORG PARTITION
mjonss Oct 10, 2022
dad8b4f
Fixed linting
mjonss Oct 10, 2022
cccbe8b
cleanups
mjonss Oct 10, 2022
978afda
Fix for modify column
mjonss Oct 10, 2022
75c94ed
Test passes
mjonss Oct 11, 2022
9e3bdf8
Updated test
mjonss Oct 11, 2022
de8cce8
Fixed restriction on new end-range
mjonss Oct 11, 2022
be7643f
lint fix
mjonss Oct 11, 2022
aa859a2
Tested LIST partitioning
mjonss Oct 11, 2022
ea6354f
lint fixes
mjonss Oct 11, 2022
38c6d09
added schema to backgroundExec test function
mjonss Oct 11, 2022
b39dacc
First part of REORGANIZE PARTITION, implementing data/index copying
mjonss Oct 13, 2022
0d316ef
Merge master into feature branch (#38463)
mjonss Oct 13, 2022
a49abe0
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Oct 13, 2022
3d72072
Code cleanups
mjonss Oct 16, 2022
6bd0fe1
Cleaned up an issue with 38302
mjonss Oct 16, 2022
711f5d5
Changed the interface for partition and partitioned table
mjonss Oct 16, 2022
9c22c96
Added GetPartitionedTable to Table interface
mjonss Oct 16, 2022
8d1986b
lint, sorting imports
mjonss Oct 16, 2022
8a62b26
Make use of the new GetPartitionedTable interface method
mjonss Oct 16, 2022
173a3b9
non-code changes (cleanup and better comments)
mjonss Oct 17, 2022
631672c
Removed non needed type assert
mjonss Oct 17, 2022
6ec104f
fixed compilation issue
mjonss Oct 17, 2022
262ba3e
Table partition double write during Reorganize partition (part 2)
mjonss Oct 17, 2022
1919a58
formatting
mjonss Oct 17, 2022
19a1e54
Merge branch 'reorg-partition-double-write' into reorg-part-rollback
mjonss Oct 17, 2022
b31beda
Enabled test
mjonss Oct 17, 2022
743fe47
Concurrent test + assertion workaround
mjonss Oct 18, 2022
130a148
Moved TiFlash check
mjonss Oct 19, 2022
6b64a9d
Fixed typo in function name
mjonss Oct 19, 2022
0be7320
Fixes for TiFlash (still needs work + support from TiFlash)
mjonss Oct 19, 2022
de23b9d
fixed linting
mjonss Oct 19, 2022
ece2444
updated updateSchemaVersion for Reorganize partition
mjonss Oct 23, 2022
d79a24b
Added test case
mjonss Oct 23, 2022
30739fb
Fixed rollback and tested no abandoned keys.
mjonss Oct 23, 2022
1d1fb20
linting
mjonss Oct 23, 2022
12db9a6
linting
mjonss Oct 23, 2022
53c4a0f
Minor updates according to review comments (no logic change)
mjonss Nov 14, 2022
184b6d0
temporary disabled wip test
mjonss Nov 14, 2022
2b8c979
*: merge master to feature/reorganize-partition (#38613)
mjonss Nov 15, 2022
3f16048
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Nov 15, 2022
d02aa9a
Added typeReorgPartitionWorker back to adjustWorkerSize
mjonss Nov 15, 2022
dc0fc1e
Added Partition to TableInfo.Clone()
mjonss Nov 15, 2022
880c148
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Nov 15, 2022
d3fcc49
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Nov 15, 2022
cefae62
Merge branch 'reorg-partition-double-write' into reorg-part-rollback
mjonss Nov 15, 2022
3c460dd
Added checks on the ddl worker side
mjonss Nov 15, 2022
3fc4988
update after make bazel_prepare
mjonss Nov 15, 2022
dce19dd
wip, updated statistics handle for reorg partition
mjonss Nov 16, 2022
4b254e7
Clarified error message for range single range
mjonss Nov 20, 2022
6f3d0be
Updated error message from single range to adjacent partitions
mjonss Nov 24, 2022
f290f44
testing docs partitioning management and found + fixed a bug
mjonss Nov 24, 2022
0e76348
wip added test (not yet testing what I want...)
mjonss Nov 24, 2022
eb2ae23
Fixed tests to show deleteReorg is needed
mjonss Nov 28, 2022
e2d8aa0
Also double writing during StateDeleteReorganization
mjonss Nov 28, 2022
82dcbb1
linting issues
mjonss Nov 28, 2022
fd331c9
Linting
mjonss Nov 28, 2022
e60de33
Lint found a potential bug
mjonss Nov 28, 2022
f6ac390
Removed useless use of failpoint
mjonss Nov 28, 2022
a50069b
Cleaned up sql_mode and verified with test
mjonss Nov 28, 2022
aec9e7c
*: Merge master to feature/reorganize-partition (#39164)
mjonss Nov 28, 2022
64ec7ef
minor fixes and linting
mjonss Nov 29, 2022
1a3bc69
Removed empty lines
mjonss Nov 29, 2022
62ac719
removed an empty line
mjonss Nov 29, 2022
e526cca
Clarified code for double write and delete only
mjonss Nov 29, 2022
624ed8c
wip updated test to show the need for StateDeleteOnly
mjonss Nov 30, 2022
d8041d5
Fixed DeleteOnly state
mjonss Nov 30, 2022
b494e76
fixed unreachable code
mjonss Dec 1, 2022
2f4a50d
Updated according to review comments, minor changes
mjonss Dec 1, 2022
0a5410f
added missed return + removed empty line
mjonss Dec 1, 2022
b33cddf
Added a comment
mjonss Dec 1, 2022
0c9faa4
Removed comment about long running alter. It will just add a log
mjonss Dec 5, 2022
a6dbd11
*: merge master into feature/reorganize-partition (#39556)
mjonss Dec 5, 2022
c1d9db3
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 5, 2022
e292370
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 5, 2022
b395d22
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 5, 2022
5bb311a
Merge branch 'reorg-partition-double-write' into reorg-part-rollback
mjonss Dec 5, 2022
3ed74cc
Improved data assertion and added panic for finding test issues
mjonss Dec 6, 2022
e3d9fb3
linting
mjonss Dec 6, 2022
3e9c95b
Updated comments
mjonss Dec 6, 2022
f99fe0b
Removed comment, since assertions are already handled.
mjonss Dec 7, 2022
8bb7049
Updated comment
mjonss Dec 8, 2022
a974efc
Removed TODO after checking that DROP PARTITION also cleans up PD
mjonss Dec 8, 2022
768493f
Fixed deletion of PD rule for TiFlash after Reorg Partition
mjonss Dec 8, 2022
c047d1e
*: merge master into feature branch reorganize-partition (#39906)
mjonss Dec 13, 2022
0426cda
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 13, 2022
d8d260e
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 14, 2022
47c0c0c
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 14, 2022
1dd12ec
Merge branch 'reorg-partition-double-write' into reorg-part-rollback
mjonss Dec 14, 2022
caed970
ci debugging
mjonss Dec 14, 2022
5a60f7e
Linting
mjonss Dec 20, 2022
85257f3
Updated after make bazel_prepare
mjonss Dec 21, 2022
273e7e8
Removed CI debug log
mjonss Dec 21, 2022
b086421
Cleaned PR to only have the core of the data copying parts
mjonss Dec 21, 2022
74fa4c4
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 21, 2022
b0c16cd
More cleanup of PR to only focus on reorg data copy
mjonss Dec 21, 2022
73dcf5a
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 21, 2022
0accdd8
Added check to avoid null-pointer dereferencing
mjonss Dec 21, 2022
8c914b0
Fixed nil session context
mjonss Dec 21, 2022
0678894
Cleanup
mjonss Dec 21, 2022
3a1adcd
Added Info logs for debugging in CI
mjonss Dec 21, 2022
f23a27a
more CI debug info logs + cleared a TODO
mjonss Dec 22, 2022
ecb7f50
Added one more CI debug line
mjonss Dec 22, 2022
985b5ec
Update ddl/partition.go
mjonss Dec 22, 2022
bfd5e66
More cleanup of PR to only focus on reorg data copy
mjonss Dec 22, 2022
0b0c7ec
Removed checkReorgParition, it will be back in part 3.
mjonss Dec 22, 2022
b7e590c
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 22, 2022
1e0d902
Moved code to only run once instead of for every fetchRowColVal
mjonss Dec 22, 2022
60a956b
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 22, 2022
eb6fec9
Return directly on error instead of retrying workerCnt times
mjonss Dec 22, 2022
3438e00
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 22, 2022
251a69a
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 22, 2022
0a275d6
Merge branch 'reorg-part-merge-dec22' into reorg-part-data-reorg-merg…
mjonss Dec 22, 2022
2e5b311
Added reverted code needed for reorganize partition
mjonss Dec 22, 2022
fa2a2ba
*: merge master into feature/reorganize-partition dec22 (#40117)
mjonss Dec 22, 2022
0eab90d
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 23, 2022
060f189
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Dec 23, 2022
5632e4a
post merge fix, removed test
mjonss Dec 23, 2022
7c093a2
Merge branch 'reorg-part-data-reorg' into reorg-part-rollback
mjonss Dec 23, 2022
c27499e
Merge branch 'reorg-partition-double-write' into reorg-part-rollback
mjonss Dec 23, 2022
4702033
Merge fix
mjonss Dec 23, 2022
3112178
Merge branch 'reorg-partition-double-write' into reorg-part-rollback
mjonss Dec 23, 2022
dfd9dae
Removed applyTableUpdate from applyReorgPart + CI debug
mjonss Dec 23, 2022
a9c528c
Linting
mjonss Dec 23, 2022
6ad990a
updateTable CI testing
mjonss Dec 24, 2022
658f9a6
More CI debugging
mjonss Dec 24, 2022
9d55834
Even more CI debugs...
mjonss Dec 25, 2022
40edc9e
More CI testing skipping oom tests
mjonss Dec 25, 2022
34c03ad
more CI debugging
mjonss Dec 25, 2022
bcf8ef1
Linting
mjonss Dec 25, 2022
ff8bd3c
more CI debug
mjonss Dec 25, 2022
3e2ca84
Removed cleaning of tidb_ddl_reorg when ddl is completed (CI testing)
mjonss Dec 26, 2022
cf56bf9
More CI debug...
mjonss Dec 27, 2022
22261a0
More CI debug
mjonss Dec 27, 2022
25df00e
*: support REORGANIZE PARTITION, part 1 - data reorg / data+index cop…
mjonss Dec 30, 2022
b259112
*: Table partition double write during Reorganize partition (part 2) …
mjonss Dec 30, 2022
94b65bd
Merge remote-tracking branch 'pingcap/master' into feature-reorganize…
mjonss Dec 30, 2022
7ef86c3
Post merge fixes
mjonss Dec 30, 2022
7e2fa6c
Merge branch 'feature-reorganize-partition-merge-dec30' into reorg-pa…
mjonss Dec 30, 2022
ca03f9c
Changes from tidb#38738 to fix tidb_ddl_reorg conflicts
mjonss Dec 31, 2022
9ac5dff
Removed debug logs
mjonss Dec 31, 2022
114b690
*: merge master into feature/reorganize-partition (#40263)
mjonss Jan 3, 2023
1e99fa4
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Jan 3, 2023
ef7c8bd
Main Reorganize Partition DDL logic (moved from part 3)
mjonss Jan 10, 2023
eb033f8
Skipping two tests, to be fixed in separate PR
mjonss Jan 10, 2023
8a14d11
Update after `make bazel_prepare`
mjonss Jan 10, 2023
cf8f683
Merge pingcap/master and pingcap/feature/reorganize-partition
mjonss Jan 10, 2023
4ae9e6d
Updated CODEOWNERS for the feature branch
mjonss Jan 10, 2023
34d9352
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Jan 10, 2023
eb3df8b
Main Reorganize Partition DDL logic (moved from part 3)
mjonss Jan 10, 2023
ac6f869
Skipping two tests, to be fixed in separate PR
mjonss Jan 10, 2023
d3444e6
Update after `make bazel_prepare`
mjonss Jan 10, 2023
805553a
Merge remote-tracking branch 'origin/reorg-part-ddl-states' into reor…
mjonss Jan 10, 2023
6e220cf
Renamed the receiver of *partitionedTable to be consistently 't'
mjonss Jan 11, 2023
2b32037
Merge remote-tracking branch 'pingcap/master' into reorg-part-merge-j…
mjonss Jan 11, 2023
4b6f0ca
Post merge fix
mjonss Jan 11, 2023
d041912
Merge branch 'reorg-part-merge-jan10' into reorg-part-ddl-states
mjonss Jan 11, 2023
88f5ff8
Merge branch 'reorg-part-merge-jan10' into reorg-part-rollback-merge-…
mjonss Jan 11, 2023
bd7c905
Post merge fix
mjonss Jan 11, 2023
8bc3503
Post merge fix
mjonss Jan 11, 2023
5c71c3d
Renamed receiver of partitionedTable from p to t
mjonss Jan 11, 2023
8a97633
Removed TestTiflashReorgPartition test (since support will come later)
mjonss Jan 11, 2023
a3b77df
Removed non needed cast
mjonss Jan 11, 2023
e2b4ca5
bazel_prepare update
mjonss Jan 11, 2023
a0229ea
Merge branch 'reorg-part-ddl-states' into reorg-part-rollback-merge-j…
mjonss Jan 12, 2023
5ad0c09
*: Merge master into feature/reorganize-partition branch (#40480)
mjonss Jan 12, 2023
2578e7b
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Jan 12, 2023
9cd2d19
Merge branch 'reorg-part-ddl-states' into reorg-part-rollback-merge-j…
mjonss Jan 12, 2023
6ae6ecd
Removed skipped tests (to be added back in next PR)
mjonss Jan 12, 2023
038a4e5
Explicitly add label on panic tests
mjonss Jan 12, 2023
d87a516
Added back code that does not need to be touched
mjonss Jan 12, 2023
5e94a2d
Removed non used test function
mjonss Jan 12, 2023
9f0a0c3
make bazel_prepare
mjonss Jan 12, 2023
1b09e1a
Cleanup
mjonss Jan 12, 2023
599f5dc
Implemented delete range cleanup for Reorganize Partition
mjonss Jan 12, 2023
11b62c7
update after make bazel_prepare
mjonss Jan 12, 2023
aa3bf0b
Merge branch 'reorg-part-rollback' into reorg-part-tiflash-and-update…
mjonss Jan 16, 2023
b8b5194
Fixed an index issue in StateDeleteReorg after adding test.
mjonss Jan 16, 2023
2887591
*: Reorganize Partition DDL states logic (#40473)
mjonss Jan 18, 2023
1353270
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Jan 18, 2023
5a31388
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Jan 18, 2023
8db6a00
telemetry: Adding telemetry for alter table reorganize partition (#40…
mjonss Jan 18, 2023
1af113a
Fixed test for TiFlash and reorg partition
mjonss Jan 18, 2023
1cceb71
Removed changes that belongs to splitted PR
mjonss Jan 18, 2023
459f7b2
Splitted, so the PR only contains TiFlash related changes and tests
mjonss Jan 18, 2023
2e7cb93
Bazel update
mjonss Jan 18, 2023
ccbacc8
Merge branch 'feature/reorganize-partition' into reorg-part-update-table
mjonss Jan 18, 2023
db40209
Merge branch 'feature/reorganize-partition' into reorg-part-tiflash
mjonss Jan 18, 2023
778e009
Merge branch 'reorg-part-delete-range' into reorg-part-tiflash-test
mjonss Jan 18, 2023
4e6a054
Merge branch 'reorg-part-update-table' into reorg-part-tiflash-test
mjonss Jan 18, 2023
3eef6a0
*: Reorg part delete range (#40543)
mjonss Jan 19, 2023
f6c2994
Merge branch 'feature/reorganize-partition' into reorg-part-tiflash
mjonss Jan 19, 2023
a642b7c
Merge remote-tracking branch 'pingcap/feature/reorganize-partition' i…
mjonss Jan 19, 2023
7ea2f7a
Test update and fix for unistore safe destroy range
mjonss Jan 19, 2023
03180b1
Cleanup of parts included in other PRs
mjonss Jan 19, 2023
b5a74c3
Code cleanup
mjonss Jan 19, 2023
8409849
Merge branch 'reorg-part-tiflash' into reorg-part-tiflash-test
mjonss Jan 19, 2023
c30739d
Merge branch 'reorg-part-update-table' into reorg-part-tiflash-test
mjonss Jan 19, 2023
687f396
Addeed tests for Reorganize Partition with TiFlash
mjonss Mar 9, 2023
8c04202
Merge remote-tracking branch 'pingcap/master' into reorg-part-tiflash…
mjonss May 10, 2023
233a467
Merge branch 'reorg-part-tiflash-test' into reorg-part-tiflash-tests
mjonss May 10, 2023
92da0e2
make bazel_prepare
mjonss May 10, 2023
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
87 changes: 87 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"math/rand"
"sort"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -3844,6 +3845,92 @@ func TestAddPartitionReplicaBiggerThanTiFlashStores(t *testing.T) {
require.Equal(t, "[ddl:-1]DDL job rollback, error msg: [ddl] add partition wait for tiflash replica to complete", err.Error())
}

func TestReorgPartitionTiFlash(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
schemaName := "ReorgPartTiFlash"
tk.MustExec("create database " + schemaName)
tk.MustExec("use " + schemaName)
tk.MustExec(`create table t (a int unsigned PRIMARY KEY, b varchar(255), c int, key (b), key (c,b))` +
` partition by list columns (a) ` +
`(partition p0 values in (10,11,45),` +
` partition p1 values in (20,1,23,56),` +
` partition p2 values in (12,34,9))`)
tk.MustExec(`insert into t values (1,"1",1), (12,"12",21),(23,"23",32),(34,"34",43),(45,"45",54),(56,"56",65)`)

require.Nil(t, failpoint.Enable("github.com/pingcap/tidb/infoschema/mockTiFlashStoreCount", `return(true)`))
defer func() {
err := failpoint.Disable("github.com/pingcap/tidb/infoschema/mockTiFlashStoreCount")
require.NoError(t, err)
}()

tk.MustExec(`alter table t set tiflash replica 1`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` int(10) unsigned NOT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" `c` int(11) DEFAULT NULL,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n" +
" KEY `b` (`b`),\n" +
" KEY `c` (`c`,`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" +
"PARTITION BY LIST COLUMNS(`a`)\n" +
"(PARTITION `p0` VALUES IN (10,11,45),\n" +
" PARTITION `p1` VALUES IN (20,1,23,56),\n" +
" PARTITION `p2` VALUES IN (12,34,9))"))

tbl := external.GetTableByName(t, tk, schemaName, "t")
p := tbl.GetPartitionedTable()
for _, pid := range p.GetAllPartitionIDs() {
require.NoError(t, domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), pid, true))
}
// Reload
tbl = external.GetTableByName(t, tk, schemaName, "t")
p = tbl.GetPartitionedTable()
require.NotNil(t, tbl.Meta().TiFlashReplica)
require.True(t, tbl.Meta().TiFlashReplica.Available)
pids := p.GetAllPartitionIDs()
sort.Slice(pids, func(i, j int) bool { return pids[i] < pids[j] })
availablePids := tbl.Meta().TiFlashReplica.AvailablePartitionIDs
sort.Slice(availablePids, func(i, j int) bool { return availablePids[i] < availablePids[j] })
require.Equal(t, pids, availablePids)
require.Nil(t, failpoint.Enable("github.com/pingcap/tidb/ddl/mockWaitTiFlashReplicaOK", `return(true)`))
defer func() {
err := failpoint.Disable("github.com/pingcap/tidb/ddl/mockWaitTiFlashReplicaOK")
require.NoError(t, err)
}()
tk.MustExec(`alter table t reorganize partition p1, p2 into (partition p1 values in (34,2,23), partition p2 values in (12,56,9),partition p3 values in (1,8,19))`)
tk.MustExec(`admin check table t`)
tk.MustQuery(`show create table t`).Check(testkit.Rows("" +
"t CREATE TABLE `t` (\n" +
" `a` int(10) unsigned NOT NULL,\n" +
" `b` varchar(255) DEFAULT NULL,\n" +
" `c` int(11) DEFAULT NULL,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n" +
" KEY `b` (`b`),\n" +
" KEY `c` (`c`,`b`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" +
"PARTITION BY LIST COLUMNS(`a`)\n" +
"(PARTITION `p0` VALUES IN (10,11,45),\n" +
" PARTITION `p1` VALUES IN (34,2,23),\n" +
" PARTITION `p2` VALUES IN (12,56,9),\n" +
" PARTITION `p3` VALUES IN (1,8,19))"))

// TODO: Check how to properly test TiFlash, since this will just change the actual configuration
tbl = external.GetTableByName(t, tk, schemaName, "t")
p = tbl.GetPartitionedTable()
for _, pid := range p.GetAllPartitionIDs() {
require.NoError(t, domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), pid, true))
}
tbl = external.GetTableByName(t, tk, schemaName, "t")
p = tbl.GetPartitionedTable()
require.NotNil(t, tbl.Meta().TiFlashReplica)
require.True(t, tbl.Meta().TiFlashReplica.Available)
for _, pid := range p.GetAllPartitionIDs() {
require.True(t, tbl.Meta().TiFlashReplica.IsPartitionAvailable(pid))
}
}

func TestDuplicatePartitionNames(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
21 changes: 21 additions & 0 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ func checkPartitionReplica(replicaCount uint64, addingDefinitions []model.Partit
failpoint.Return(true, nil)
}
})
failpoint.Inject("mockWaitTiFlashReplicaOK", func(val failpoint.Value) {
if val.(bool) {
failpoint.Return(false, nil)
}
})

ctx := context.Background()
pdCli := d.store.(tikv.Storage).GetRegionCache().PDClient()
Expand Down Expand Up @@ -1849,6 +1854,22 @@ func (w *worker) onDropTablePartition(d *ddlCtx, t *meta.Meta, job *model.Job) (
return ver, errors.Trace(err)
}
}
if tblInfo.TiFlashReplica != nil {
// Remove the partitions
ids := tblInfo.TiFlashReplica.AvailablePartitionIDs
// Rarely called, so OK to take some time, to make it easy
for _, id := range physicalTableIDs {
for i, avail := range ids {
if id == avail {
tmp := ids[:i]
tmp = append(tmp, ids[i+1:]...)
ids = tmp
break
}
}
}
tblInfo.TiFlashReplica.AvailablePartitionIDs = ids
}
mjonss marked this conversation as resolved.
Show resolved Hide resolved
tblInfo.Partition.DroppingDefinitions = nil
// used by ApplyDiff in updateSchemaVersion
job.CtxVars = []interface{}{physicalTableIDs}
Expand Down
3 changes: 3 additions & 0 deletions ddl/tiflashtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ go_test(
"//store/mockstore",
"//store/mockstore/unistore",
"//table",
"//tablecodec",
"//testkit",
"//testkit/external",
"//testkit/testsetup",
"//util",
"//util/logutil",
Expand All @@ -32,6 +34,7 @@ go_test(
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_client_go_v2//testutils",
"@com_github_tikv_client_go_v2//tikv",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_zap//:zap",
],
Expand Down
109 changes: 109 additions & 0 deletions ddl/tiflashtest/ddl_tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/external"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/logutil"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/oracle"
"github.com/tikv/client-go/v2/testutils"
"github.com/tikv/client-go/v2/tikv"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -1351,3 +1354,109 @@ func TestTiFlashAvailableAfterDownOneStore(t *testing.T) {
time.Sleep(ddl.PollTiFlashInterval * RoundToBeAvailable * 3)
CheckTableAvailable(s.dom, t, 1, []string{})
}

// TestDLLCallback copied from ddl.TestDDLCallback, but smaller
type TestDDLCallback struct {
*ddl.BaseCallback
// We recommended to pass the domain parameter to the test ddl callback, it will ensure
// domain to reload schema before your ddl stepping into the next state change.
Do ddl.DomainReloader

// Only need this for now
OnJobRunBeforeExported func(*model.Job)
}

// OnJobRunBefore is used to run the user customized logic of `onJobRunBefore` first.
func (tc *TestDDLCallback) OnJobRunBefore(job *model.Job) {
logutil.BgLogger().Info("on job run before", zap.String("job", job.String()))
if tc.OnJobRunBeforeExported != nil {
tc.OnJobRunBeforeExported(job)
return
}

tc.BaseCallback.OnJobRunBefore(job)
}

func TestTiFlashReorgPartition(t *testing.T) {
s, teardown := createTiFlashContext(t)
defer teardown()
fCancel := TempDisableEmulatorGC()
defer fCancel()
tk := testkit.NewTestKit(t, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists ddltiflash")

tk.MustExec(`create table ddltiflash (id int, vc varchar(255), i int, key (vc), key(i,vc))` +
` partition by range (id)` +
` (partition p0 values less than (1000000), partition p1 values less than (2000000))`)
tk.MustExec(`alter table ddltiflash set tiflash replica 1`)
time.Sleep(ddl.PollTiFlashInterval * RoundToBeAvailable * 3)
CheckTableAvailable(s.dom, t, 1, []string{})
tb := external.GetTableByName(t, tk, "test", "ddltiflash")
firstPartitionID := tb.Meta().Partition.Definitions[0].ID
ruleName := fmt.Sprintf("table-%v-r", firstPartitionID)
_, ok := s.tiflash.GetPlacementRule(ruleName)
require.True(t, ok)

// Note that the mock TiFlash does not have any data or regions, so the wait for regions being available will fail
dom := domain.GetDomain(tk.Session())
originHook := dom.DDL().GetHook()
defer dom.DDL().SetHook(originHook)
hook := &TestDDLCallback{Do: dom}
dom.DDL().SetHook(hook)
done := false

hook.OnJobRunBeforeExported = func(job *model.Job) {
if !done && job.Type == model.ActionReorganizePartition && job.SchemaState == model.StateDeleteOnly {
// Let it fail once (to check that code path) then increase the count to skip retry
if job.ErrorCount > 0 {
job.ErrorCount = 1000
done = true
}
}
}
tk.MustContainErrMsg(`alter table ddltiflash reorganize partition p0 into (partition p0 values less than (500000), partition p500k values less than (1000000))`, "[ddl] add partition wait for tiflash replica to complete")

done = false
hook.OnJobRunBeforeExported = func(job *model.Job) {
if !done && job.Type == model.ActionReorganizePartition && job.SchemaState == model.StateDeleteOnly {
// Let it fail once (to check that code path) then mock the regions into the partitions
if job.ErrorCount > 0 {
// Add the tiflash stores as peers for the new regions, to fullfil the check
// in checkPartitionReplica
pdCli := s.store.(tikv.Storage).GetRegionCache().PDClient()
var dummy []model.CIStr
partInfo := &model.PartitionInfo{}
_ = job.DecodeArgs(&dummy, &partInfo)
ctx := context.Background()
stores, _ := pdCli.GetAllStores(ctx)
for _, pd := range partInfo.Definitions {
startKey, endKey := tablecodec.GetTableHandleKeyRange(pd.ID)
regions, _ := pdCli.ScanRegions(ctx, startKey, endKey, -1)
for i := range regions {
// similar as storeHasEngineTiFlashLabel
for _, store := range stores {
for _, label := range store.Labels {
if label.Key == placement.EngineLabelKey && label.Value == placement.EngineLabelTiFlash {
s.cluster.MockRegionManager.AddPeer(regions[i].Meta.Id, store.Id, 1)
break
}
}
}
}
}
done = true
}
}
}
tk.MustExec(`alter table ddltiflash reorganize partition p0 into (partition p0 values less than (500000), partition p500k values less than (1000000))`)
tk.MustExec(`admin check table ddltiflash`)
_, ok = s.tiflash.GetPlacementRule(ruleName)
require.True(t, ok)
gcWorker, err := gcworker.NewMockGCWorker(s.store)
require.NoError(t, err)
require.Nil(t, gcWorker.DeleteRanges(context.TODO(), math.MaxInt64))
_, ok = s.tiflash.GetPlacementRule(ruleName)
require.False(t, ok)
tk.MustExec(`drop table ddltiflash`)
}
6 changes: 6 additions & 0 deletions store/mockstore/unistore/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ func (c *RPCClient) SendRequest(ctx context.Context, addr string, req *tikvrpc.R
case tikvrpc.CmdStoreSafeTS:
resp.Resp, err = c.usSvr.GetStoreSafeTS(ctx, req.StoreSafeTS())
return resp, err
case tikvrpc.CmdUnsafeDestroyRange:
// Pretend it was done. Unistore does not have "destroy", and the
// keys has already been removed one-by-one before through:
// (dr *delRange) startEmulator()
resp.Resp = &kvrpcpb.UnsafeDestroyRangeResponse{}
return resp, nil
default:
err = errors.Errorf("not support this request type %v", req.Type)
}
Expand Down