-
Notifications
You must be signed in to change notification settings - Fork 288
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
Optimist: return ConflictNone if a conflict DDL has no conflict with at lease one normal table #5414
Optimist: return ConflictNone if a conflict DDL has no conflict with at lease one normal table #5414
Changes from 5 commits
c0b7fb9
4bbf3a5
5c2d65d
6dd59dd
91b30ab
b395963
929985d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -889,8 +889,8 @@ func (l *Lock) trySyncForOneDDL(source, schema, table string, prevTable, postTab | |||
|
||||
log.L().Info("found conflict for DDL", zap.String("source", source), zap.String("schema", schema), zap.String("table", table), zap.Stringer("prevTable", prevTable), zap.Stringer("postTable", postTable), log.ShortError(tableErr)) | ||||
|
||||
if idempotent { | ||||
log.L().Info("return conflict DDL for idempotent DDL", zap.String("source", source), zap.String("schema", schema), zap.String("table", table), zap.Stringer("prevTable", prevTable), zap.Stringer("postTable", postTable)) | ||||
if idempotent || l.noConflictWithOneNormalTable(source, schema, table, prevTable, postTable) { | ||||
log.L().Info("directly return conflict DDL", zap.Bool("idempotent", idempotent), zap.String("source", source), zap.String("schema", schema), zap.String("table", table), zap.Stringer("prevTable", prevTable), zap.Stringer("postTable", postTable)) | ||||
l.tables[source][schema][table] = postTable | ||||
l.finalTables[source][schema][table] = postTable | ||||
return true, ConflictNone | ||||
|
@@ -902,15 +902,6 @@ func (l *Lock) trySyncForOneDDL(source, schema, table string, prevTable, postTab | |||
l.addConflictTable(source, schema, table, postTable) | ||||
l.finalTables[source][schema][table] = postTable | ||||
|
||||
// if more than one conflict tables and this conflict DDL has no conflict with normal tables | ||||
// e.g. tb1,tb2 put ddl1(rename a to b); tb1 put ddl2(rename c to d); tb2 crash and reput ddl1(rename a to b) | ||||
// now tb2's ddl1 is a conflict DDL but has no conflict with normal tables | ||||
if l.multipleConflictTables() && l.noConflictWithNormalTables(source, schema, table, postTable) { | ||||
l.removeConflictTable(source, schema, table) | ||||
l.tables[source][schema][table] = postTable | ||||
return true, ConflictNone | ||||
} | ||||
|
||||
// if any conflict happened between conflict DDLs, return error | ||||
// e.g. tb1: "ALTER TABLE RENAME a TO b", tb2: "ALTER TABLE RENAME c TO d" | ||||
if !l.noConflictForConflictTables() { | ||||
|
@@ -1085,33 +1076,39 @@ func (l *Lock) allFinalTableLarger() bool { | |||
return l.allTableLarger(finalTables) | ||||
} | ||||
|
||||
// judge whether a conflict DDL has no conflict with all normal tables. | ||||
func (l *Lock) noConflictWithNormalTables(source, schema, table string, postTable schemacmp.Table) bool { | ||||
// revert conflict tables and final tables | ||||
currentConflictTables := l.conflictTables | ||||
currentFinalTables := l.finalTables | ||||
defer func() { | ||||
l.conflictTables = currentConflictTables | ||||
l.finalTables = currentFinalTables | ||||
}() | ||||
|
||||
// reset conflict tables and final tables | ||||
l.conflictTables = make(map[string]map[string]map[string]schemacmp.Table) | ||||
l.finalTables = make(map[string]map[string]map[string]schemacmp.Table) | ||||
// jude a conflict ddl is no conflict with at least one normal table. | ||||
func (l *Lock) noConflictWithOneNormalTable(callerSource, callerSchema, callerTable string, prevTable, postTable schemacmp.Table) bool { | ||||
for source, schemaTables := range l.tables { | ||||
l.finalTables[source] = make(map[string]map[string]schemacmp.Table) | ||||
for schema, tables := range schemaTables { | ||||
l.finalTables[source][schema] = make(map[string]schemacmp.Table) | ||||
for table, ti := range tables { | ||||
l.finalTables[source][schema][table] = ti | ||||
if source == callerSource && schema == callerSchema && table == callerTable { | ||||
continue | ||||
} | ||||
|
||||
// judge joined no error | ||||
joined, err := postTable.Join(ti) | ||||
if err != nil { | ||||
continue | ||||
} | ||||
|
||||
// judge this normal table is smaller(same as allTableSmaller) | ||||
if _, err = joined.Compare(prevTable); err == nil { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy from tiflow/dm/pkg/shardddl/optimism/lock.go Line 1003 in 08928bf
|
||||
continue | ||||
} | ||||
|
||||
// judge this normal table is larger(same as allTableLarger) | ||||
if joined, err = prevTable.Join(ti); err != nil { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy from tiflow/dm/pkg/shardddl/optimism/lock.go Line 1043 in 08928bf
|
||||
joined = ti | ||||
} | ||||
if cmp, err := joined.Compare(postTable); err != nil || cmp < 0 { | ||||
continue | ||||
} | ||||
|
||||
return true | ||||
} | ||||
} | ||||
} | ||||
// update for current conflict DDL | ||||
l.addConflictTable(source, schema, table, postTable) | ||||
l.finalTables[source][schema][table] = postTable | ||||
|
||||
return l.noConflictForFinalTables() | ||||
return false | ||||
} | ||||
|
||||
// judge whether all conflict tables has no conflict. | ||||
|
@@ -1202,19 +1199,3 @@ func (l *Lock) redirectForConflictTables(callerSource, callerSchema, callerTable | |||
} | ||||
return nil | ||||
} | ||||
|
||||
// multipleConflictTables check whether a lock has multiple conflict tables. | ||||
func (l *Lock) multipleConflictTables() bool { | ||||
cnt := 0 | ||||
for _, schemaTables := range l.conflictTables { | ||||
for _, tables := range schemaTables { | ||||
for range tables { | ||||
cnt++ | ||||
if cnt > 1 { | ||||
return true | ||||
} | ||||
} | ||||
} | ||||
} | ||||
return false | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idempotent means the DDL has already been executed in this table before.
noConflictWithOneNormalTable means the DDL has already been executed in at least one other table before.