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: avoid commit conflicts when updating/delete from mysql.tidb_ddl_reorg. #38738

Merged
merged 76 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
e2e3b5c
Added test case
mjonss Oct 27, 2022
eb69cab
ddl fix #38669.
mjonss Oct 29, 2022
841b5fa
Fixed typo in comment
mjonss Oct 30, 2022
51174b0
Added test case for #24427
mjonss Nov 9, 2022
cbd0981
Merge remote-tracking branch 'pingcap/master' into trunc-warn-38669
mjonss Dec 25, 2022
17c28f3
Disabled tests for CI testing
mjonss Dec 25, 2022
65c84d9
Revert "Disabled tests for CI testing"
mjonss Dec 25, 2022
f432276
Revert "Revert "Disabled tests for CI testing""
mjonss Dec 25, 2022
31a8165
removed test skips
mjonss Dec 25, 2022
93ec6ce
Clean up the tidb_ddl_reorg entry after DDL is completed
mjonss Dec 26, 2022
f392e91
Use a cleanup job afterwards instead.
mjonss Dec 26, 2022
270a640
Fixed test
mjonss Dec 27, 2022
c56449d
Moved cleanup before asyncNotify
mjonss Dec 27, 2022
f8b2d62
More detailed test failure log
mjonss Dec 27, 2022
4de5504
Merge branch 'master' into trunc-warn-38669
mjonss Dec 27, 2022
2015061
Refined test error message
mjonss Dec 27, 2022
d673abc
Merge branch 'master' into trunc-warn-38669
mjonss Dec 28, 2022
f9ed823
Injecting timoeut to get stack traces from CI
mjonss Dec 28, 2022
9672513
Updated Debug Dump on timeout
mjonss Dec 28, 2022
4f667f9
Delete mulitple entries in tidb_ddl_reorg if needed
mjonss Dec 28, 2022
7908ee8
Linting
mjonss Dec 28, 2022
88a891e
Linting
mjonss Dec 28, 2022
9f9a4ca
Added CI debug logs
mjonss Dec 28, 2022
b7fda44
Linting + CI debugs
mjonss Dec 28, 2022
64f2925
fixed CI debug
mjonss Dec 28, 2022
a713d57
Try to cleanup also if job.State == synced
mjonss Dec 28, 2022
d968d4e
check for non-error of runErr instead of error...
mjonss Dec 29, 2022
6a0e0c3
Use a new session, instead of reusing worker.sess
mjonss Dec 29, 2022
e13c332
Also handle case when job == nil
mjonss Dec 29, 2022
fe65fa9
Merge remote-tracking branch 'pingcap/master' into trunc-warn-38669
mjonss Dec 29, 2022
5614b30
Removed CI debug logs
mjonss Dec 29, 2022
ab0087a
Misssed change session from w.sess to newly created sess
mjonss Dec 29, 2022
6186476
Improved TestConcurrentDDLSwitch and added CI debug logs
mjonss Dec 29, 2022
7257bd0
Always cleaning up all orphan mysql.tidb_ddl_reorg entries
mjonss Dec 29, 2022
6eb65d3
linting
mjonss Dec 29, 2022
143f889
Also cleanup if job is nil
mjonss Dec 29, 2022
3f6dcc5
Merge remote-tracking branch 'pingcap/master' into trunc-warn-38669
mjonss Dec 29, 2022
5473f2f
Updated TestModifyColumnReorgInfo + CI debug logs
mjonss Dec 29, 2022
250717d
more CI debug
mjonss Dec 29, 2022
641f89b
refactored the cleanupDDLReorgHandle code
mjonss Dec 29, 2022
eda7cc9
Added missing cleanup in handleDDLJobQueue
mjonss Dec 29, 2022
0598ed7
Removed debug panic
mjonss Dec 29, 2022
13c3d56
Code cleanup
mjonss Dec 29, 2022
54e0b24
Test updates
mjonss Dec 29, 2022
1d55510
Debug cleanup
mjonss Dec 29, 2022
cf478ea
Merge remote-tracking branch 'pingcap/master' into trunc-warn-38669
mjonss Dec 30, 2022
ee44b65
Cleaned up test after removal of old non-concurrent DDL code merge
mjonss Dec 30, 2022
0ed2f47
Linting
mjonss Dec 30, 2022
8cee684
always wrap changes to tidb_ddl_reorg in an own transaction
mjonss Jan 5, 2023
0164c1a
Merge remote-tracking branch 'pingcap/master' into trunc-warn-38669
mjonss Jan 5, 2023
d8483ab
Minimum fix
mjonss Jan 9, 2023
d05b1af
Always update reorg meta, not only on error
mjonss Jan 9, 2023
10cddb7
Issue is here :)
mjonss Jan 9, 2023
751a54a
Fixed newReorgHandler
mjonss Jan 9, 2023
83894b3
Wrapped more tidb_ddl_reorg changes into separate transactions
mjonss Jan 9, 2023
d0340d8
linting
mjonss Jan 9, 2023
7f18011
Removed updateDDLReorgStartHandle
mjonss Jan 9, 2023
0db4bb3
cleanups
mjonss Jan 9, 2023
5153f09
Made runInTxn a method on *session, instead of normal function
mjonss Jan 9, 2023
86bc31a
Update test
mjonss Jan 9, 2023
445d84c
Final touches
mjonss Jan 10, 2023
79e52b9
Merge branch 'fix-tidb_ddl_reorg' into trunc-warn-38669
mjonss Jan 10, 2023
b0b5084
Removed duplicate test
mjonss Jan 10, 2023
c35d853
CleanupDDLReorgHandles should only be called from HandleJobDone.
mjonss Jan 10, 2023
f1543d5
Variable rename
mjonss Jan 10, 2023
bfb5f52
Renamed 'delete' variabel name
mjonss Jan 10, 2023
0ec2512
Merge branch 'master' into trunc-warn-38669
mjonss Jan 10, 2023
78281b3
Updated test
mjonss Jan 10, 2023
7214e31
small revert
mjonss Jan 10, 2023
f9983e9
Merge remote-tracking branch 'pingcap/master' into trunc-warn-38669
mjonss Jan 11, 2023
51bacd3
Removed timeout debugging code
mjonss Jan 11, 2023
389ad4d
Simplified the cleanup to only start a new txn and not a new session
mjonss Jan 11, 2023
f04df45
Reverted the change of GetDDLInfo
mjonss Jan 11, 2023
076be10
Merge branch 'master' into trunc-warn-38669
ti-chi-bot Jan 11, 2023
022d951
Merge branch 'master' into trunc-warn-38669
ti-chi-bot Jan 11, 2023
43b6946
Merge branch 'master' into trunc-warn-38669
ti-chi-bot Jan 11, 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
9 changes: 5 additions & 4 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,8 @@ func (w *updateColumnWorker) getRowRecord(handle kv.Handle, recordKey []byte, ra
if err != nil {
return w.reformatErrors(err)
}
if w.sessCtx.GetSessionVars().StmtCtx.GetWarnings() != nil && len(w.sessCtx.GetSessionVars().StmtCtx.GetWarnings()) != 0 {
warn := w.sessCtx.GetSessionVars().StmtCtx.GetWarnings()
warn := w.sessCtx.GetSessionVars().StmtCtx.GetWarnings()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since GetWarnings takes a mutex and copies the data, it is better to only do it once instead of up to three times.

if len(warn) != 0 {
//nolint:forcetypeassert
recordWarning = errors.Cause(w.reformatErrors(warn[0].Err)).(*terror.Error)
}
Expand Down Expand Up @@ -1359,8 +1359,9 @@ func (w *updateColumnWorker) BackfillDataInTxn(handleRange reorgBackfillTask) (t
taskCtx.nextKey = nextKey
taskCtx.done = taskDone

warningsMap := make(map[errors.ErrorID]*terror.Error, len(rowRecords))
warningsCountMap := make(map[errors.ErrorID]int64, len(rowRecords))
// Optimize for few warnings!
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 think it is better to avoid reserving too much memory that may not be needed.
On the other hand it will be a single allocation instead of multiple ones when resizing the maps.

warningsMap := make(map[errors.ErrorID]*terror.Error, 2)
warningsCountMap := make(map[errors.ErrorID]int64, 2)
for _, rowRecord := range rowRecords {
taskCtx.scanCount++

Expand Down
19 changes: 19 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4535,6 +4535,25 @@ func TestPartitionTableWithAnsiQuotes(t *testing.T) {
` PARTITION "p4" VALUES LESS THAN ('\\''\t\n','\\''\t\n'),` + "\n" +
` PARTITION "pMax" VALUES LESS THAN (MAXVALUE,MAXVALUE))`))
}

func TestAlterModifyPartitionColTruncateWarning(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
schemaName := "truncWarn"
tk.MustExec("create database " + schemaName)
tk.MustExec("use " + schemaName)
tk.MustExec(`set sql_mode = default`)
tk.MustExec(`create table t (a varchar(255)) partition by range columns (a) (partition p1 values less than ("0"), partition p2 values less than ("zzzz"))`)
tk.MustExec(`insert into t values ("123456"),(" 654321")`)
tk.MustContainErrMsg(`alter table t modify a varchar(5)`, "[types:1265]Data truncated for column 'a', value is '")
tk.MustExec(`set sql_mode = ''`)
tk.MustExec(`alter table t modify a varchar(5)`)
// Fix the duplicate warning, see https://github.com/pingcap/tidb/issues/38699
tk.MustQuery(`show warnings`).Check(testkit.Rows(""+
"Warning 1265 Data truncated for column 'a', value is ' 654321'",
"Warning 1265 Data truncated for column 'a', value is ' 654321'"))
}

func TestAlterModifyColumnOnPartitionedTable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
34 changes: 33 additions & 1 deletion ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ func (w *worker) runReorgJob(rh *reorgHandler, reorgInfo *reorgInfo, tblInfo *mo
}

updateBackfillProgress(w, reorgInfo, tblInfo, 0)
if err1 := rh.RemoveDDLReorgHandle(job, reorgInfo.elements); err1 != nil {
// Do this is a separate transaction, since mysql.tidb_ddl_reorg may have been updated
// by the inner function and could result in commit conflicts.:122

if err1 := reorgInfo.deleteReorgMeta(w.sessPool); err1 != nil {
logutil.BgLogger().Warn("[ddl] run reorg job done, removeDDLReorgHandle failed", zap.Error(err1))
return errors.Trace(err1)
}
Expand Down Expand Up @@ -742,6 +745,35 @@ func getReorgInfoFromPartitions(ctx *JobContext, d *ddlCtx, rh *reorgHandler, jo
return &info, nil
}

func (r *reorgInfo) deleteReorgMeta(pool *sessionPool) error {
if len(r.elements) == 0 {
return nil
}
se, err := pool.get()
if err != nil {
return errors.Trace(err)
}
defer pool.put(se)

sess := newSession(se)
err = sess.begin()
if err != nil {
return errors.Trace(err)
}
txn, err := sess.txn()
if err != nil {
sess.rollback()
return errors.Trace(err)
}
rh := newReorgHandler(meta.NewMeta(txn), sess, variable.EnableConcurrentDDL.Load())
err = rh.RemoveDDLReorgHandle(r.Job, r.elements)
mjonss marked this conversation as resolved.
Show resolved Hide resolved
err1 := sess.commit()
if err == nil {
err = err1
}
return errors.Trace(err)
}

func (r *reorgInfo) UpdateReorgMeta(startKey kv.Key, pool *sessionPool) (err error) {
if startKey == nil && r.EndKey == nil {
return nil
Expand Down
3 changes: 3 additions & 0 deletions parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ func (job *Job) String() string {
rowCount := job.GetRowCount()
ret := fmt.Sprintf("ID:%d, Type:%s, State:%s, SchemaState:%s, SchemaID:%d, TableID:%d, RowCount:%d, ArgLen:%d, start time: %v, Err:%v, ErrCount:%d, SnapshotVersion:%v",
job.ID, job.Type, job.State, job.SchemaState, job.SchemaID, job.TableID, rowCount, len(job.Args), TSConvert2Time(job.StartTS), job.Error, job.ErrorCount, job.SnapshotVer)
if job.ReorgMeta != nil {
ret += fmt.Sprintf(", UniqueWarnings:%d", len(job.ReorgMeta.Warnings))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be able to trace the warnings as well.

}
if job.Type != ActionMultiSchemaChange && job.MultiSchemaInfo != nil {
ret += fmt.Sprintf(", Multi-Schema Change:true, Revertible:%v", job.MultiSchemaInfo.Revertible)
}
Expand Down