Skip to content

Commit

Permalink
tables: disable row insertion consistency check in mutation checker; …
Browse files Browse the repository at this point in the history
…and fix the cache problem (#35104)

close #35103
  • Loading branch information
ekexium authored Jun 2, 2022
1 parent 2801ece commit 6d54fea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
8 changes: 7 additions & 1 deletion store/driver/txn/txn_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type tikvTxn struct {
*tikv.KVTxn
idxNameCache map[int64]*model.TableInfo
snapshotInterceptor kv.SnapshotInterceptor
// columnMapsCache is a cache used for the mutation checker
columnMapsCache interface{}
}

// NewTiKVTxn returns a new Transaction.
Expand All @@ -52,7 +54,7 @@ func NewTiKVTxn(txn *tikv.KVTxn) kv.Transaction {
totalLimit := atomic.LoadUint64(&kv.TxnTotalSizeLimit)
txn.GetUnionStore().SetEntrySizeLimit(entryLimit, totalLimit)

return &tikvTxn{txn, make(map[int64]*model.TableInfo), nil}
return &tikvTxn{txn, make(map[int64]*model.TableInfo), nil, nil}
}

func (txn *tikvTxn) GetTableInfo(id int64) *model.TableInfo {
Expand Down Expand Up @@ -247,6 +249,8 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) {
txn.KVTxn.SetRPCInterceptor(val.(interceptor.RPCInterceptor))
case kv.AssertionLevel:
txn.KVTxn.SetAssertionLevel(val.(kvrpcpb.AssertionLevel))
case kv.TableToColumnMaps:
txn.columnMapsCache = val
}
}

Expand All @@ -256,6 +260,8 @@ func (txn *tikvTxn) GetOption(opt int) interface{} {
return !txn.KVTxn.IsCasualConsistency()
case kv.TxnScope:
return txn.KVTxn.GetScope()
case kv.TableToColumnMaps:
return txn.columnMapsCache
default:
return nil
}
Expand Down
17 changes: 10 additions & 7 deletions table/tables/mutation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ func CheckDataConsistency(

columnMaps := getColumnMaps(txn, t)

if rowToInsert != nil {
if err := checkRowInsertionConsistency(
sessVars, rowToInsert, rowInsertion, columnMaps.ColumnIDToInfo, columnMaps.ColumnIDToFieldType, t.Meta().Name.O,
); err != nil {
return errors.Trace(err)
}
}
// Row insertion consistency check contributes the least to defending data-index consistency, but costs most CPU resources.
// So we disable it for now.
//
// if rowToInsert != nil {
// if err := checkRowInsertionConsistency(
// sessVars, rowToInsert, rowInsertion, columnMaps.ColumnIDToInfo, columnMaps.ColumnIDToFieldType, t.Meta().Name.O,
// ); err != nil {
// return errors.Trace(err)
// }
// }

if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math"
"math/rand"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -956,3 +957,17 @@ func TestTxnAssertion(t *testing.T) {
testUntouchedIndexImpl("OFF", false)
testUntouchedIndexImpl("OFF", true)
}

func TestReuseColumnMapsInMutationChecker(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t (a int, b int, c int, primary key(a))")
tk.MustExec("create table t_2 (a int, b int, c int, primary key(a))")
for i := 0; i < 1000; i++ {
tk.MustExec(fmt.Sprintf("insert into t values(%d, %d, %d)", i, rand.Int()%10000, rand.Int()%10000))
}
tk.MustExec("set @@tidb_enable_mutation_checker=1")
tk.MustExec("insert into t_2 select * from t")
}

0 comments on commit 6d54fea

Please sign in to comment.