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

*: Reduce data inconsistencies #31547

Merged
merged 28 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32c8c9e
executor: enhance data inconsistency report (#27388)
lysu Sep 13, 2021
2bece44
*: Check mutations for single-row changes (#27920)
ekexium Sep 22, 2021
a0e18f1
tables: check handle consistency (#28465)
ekexium Oct 19, 2021
2f8f4d6
*: add a sysvar to enable mutation checker (#28663)
ekexium Oct 19, 2021
89d537c
util: fix mistakenly shadowed name `idx` (#29470)
ekexium Nov 10, 2021
7849fd9
close #29520 (#29600)
ekexium Nov 11, 2021
c95a06d
enable mutation checker for any store type (#29654)
ekexium Nov 15, 2021
e59565e
Merge branch 'master' into ft-data-inconsistency
ekexium Dec 1, 2021
a065bc6
executor: fix admin test (#30310)
ekexium Dec 7, 2021
2f2df86
Merge remote-tracking branch 'upstream/master' into ft-data-inconsist…
ekexium Dec 7, 2021
583ff25
store: Update unistore for assertion (#29902)
MyonKeminta Dec 9, 2021
7f1b00c
*: Improve errors for mutation checker (#30434)
ekexium Dec 17, 2021
fcc7ffa
*: Support assertion for DMLs (#28313)
MyonKeminta Dec 20, 2021
44479df
Print readable log when TestCheckFailReport; Add stack trace to the l…
MyonKeminta Dec 21, 2021
a2c535e
Merge remote-tracking branch 'upstream/master' into ft-data-inconsist…
ekexium Jan 11, 2022
1557caa
fix build
ekexium Jan 11, 2022
5c07595
fix build
ekexium Jan 11, 2022
ffafb71
executor: fix test on dev branch (#31556)
ekexium Jan 11, 2022
4d4c777
store: add error code for assertion (#30989)
ekexium Jan 18, 2022
6acfe3a
Fix an incomplete comment (#31800)
MyonKeminta Jan 19, 2022
fdf1296
executor: Fix unstable test TestCheckFailReport (#31701)
MyonKeminta Jan 19, 2022
f1c52ca
add grafana panels for assertion (#31145)
ekexium Jan 25, 2022
f95b022
Fix comments; remove unnecessary deep copy (#31945)
MyonKeminta Jan 25, 2022
e7bd1fa
Merge remote-tracking branch 'upstream/master' into ft-data-inconsist…
ekexium Jan 26, 2022
13a57fb
Add a simple test case for assertion with lazy constraint check (#32130)
MyonKeminta Feb 9, 2022
18ae8d2
Merge remote-tracking branch 'upstream/master' into ft-data-inconsist…
ekexium Feb 10, 2022
b706ea3
remove replace client-go (#32230)
ekexium Feb 10, 2022
bf00a57
Merge branch 'master' into ft-data-inconsistency
ti-chi-bot Feb 11, 2022
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
5 changes: 5 additions & 0 deletions br/pkg/lightning/backend/kv/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func (t *transaction) GetTableInfo(id int64) *model.TableInfo {
func (t *transaction) CacheTableInfo(id int64, info *model.TableInfo) {
}

// SetAssertion implements the kv.Transaction interface.
func (t *transaction) SetAssertion(key []byte, assertion ...kv.FlagsOp) error {
return nil
}

// session is a trimmed down Session type which only wraps our own trimmed-down
// transaction type and provides the session variables to the TiDB library
// optimized for Lightning.
Expand Down
2 changes: 1 addition & 1 deletion ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,7 @@ func (s *testIntegrationSuite3) TestAutoIncrementForce(c *C) {
tk.MustGetErrCode("alter table t force auto_increment = 0;", errno.ErrAutoincReadFailed)
tk.MustExec("alter table t force auto_increment = 1;")
c.Assert(getNextGlobalID(), Equals, uint64(1))
// inserting new rows can overwrite the existing data.
// Inserting new rows will cause duplicate entry error.
tk.MustExec("insert into t values (3);")
c.Assert(tk.ExecToErr("insert into t values (3);").Error(), Equals, "[kv:1062]Duplicate entry '2' for key 'PRIMARY'")
tk.MustQuery("select a, _tidb_rowid from t;").Check(testkit.Rows("3 1", "1 2", "2 3"))
Expand Down
2 changes: 1 addition & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ func (w *addIndexWorker) BackfillDataInTxn(handleRange reorgBackfillTask) (taskC
}

// Create the index.
handle, err := w.index.Create(w.sessCtx, txn, idxRecord.vals, idxRecord.handle, idxRecord.rsData)
handle, err := w.index.Create(w.sessCtx, txn, idxRecord.vals, idxRecord.handle, idxRecord.rsData, table.WithIgnoreAssertion)
if err != nil {
if kv.ErrKeyExists.Equal(err) && idxRecord.handle.Equal(handle) {
// Index already exists, skip it.
Expand Down
7 changes: 7 additions & 0 deletions docs/tidb_http_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,13 @@ timezone.*
curl -X POST -d "tidb_enable_1pc=0" http://{TiDBIP}:10080/settings
```

1. Enable/disable the mutation checker

```shell
curl -X POST -d "tidb_enable_mutation_checker=1" http://{TiDBIP}:10080/settings
curl -X POST -d "tidb_enable_mutation_checker=0" http://{TiDBIP}:10080/settings
```

1. Get/Set the size of the Ballast Object

```shell
Expand Down
10 changes: 7 additions & 3 deletions errno/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,15 @@ const (
ErrMultiStatementDisabled = 8130
ErrPartitionStatsMissing = 8131
ErrNotSupportedWithSem = 8132
ErrDataInConsistentExtraIndex = 8133
ErrDataInConsistentMisMatchIndex = 8134
ErrDataInconsistentMismatchCount = 8133
ErrDataInconsistentMismatchIndex = 8134
ErrAsOf = 8135
ErrVariableNoLongerSupported = 8136
ErrAnalyzeMissColumn = 8137
ErrInconsistentRowValue = 8138
ErrInconsistentHandle = 8139
ErrInconsistentIndexedValue = 8140
ErrAssertionFailed = 8141

// Error codes used by TiDB ddl package
ErrUnsupportedDDLOperation = 8200
Expand All @@ -1037,7 +1041,7 @@ const (
ErrWriteOnSnapshot = 8220
ErrInvalidKey = 8221
ErrInvalidIndexKey = 8222
ErrDataInConsistent = 8223
ErrDataInconsistent = 8223
ErrDDLJobNotFound = 8224
ErrCancelFinishedDDLJob = 8225
ErrCannotCancelDDLJob = 8226
Expand Down
10 changes: 7 additions & 3 deletions errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,16 +1000,20 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrWriteOnSnapshot: mysql.Message("write on snapshot", nil),
ErrInvalidKey: mysql.Message("invalid key", nil),
ErrInvalidIndexKey: mysql.Message("invalid index key", nil),
ErrDataInConsistent: mysql.Message("index:%#v != record:%#v", []int{0, 1}),
ErrDataInconsistent: mysql.Message("data inconsistency in table: %s, index: %s, handle: %s, index-values:%#v != record-values:%#v", []int{2, 3, 4}),
ErrDDLReorgElementNotExist: mysql.Message("DDL reorg element does not exist", nil),
ErrDDLJobNotFound: mysql.Message("DDL Job:%v not found", nil),
ErrCancelFinishedDDLJob: mysql.Message("This job:%v is finished, so can't be cancelled", nil),
ErrCannotCancelDDLJob: mysql.Message("This job:%v is almost finished, can't be cancelled now", nil),
ErrUnknownAllocatorType: mysql.Message("Invalid allocator type", nil),
ErrAutoRandReadFailed: mysql.Message("Failed to read auto-random value from storage engine", nil),
ErrInvalidIncrementAndOffset: mysql.Message("Invalid auto_increment settings: auto_increment_increment: %d, auto_increment_offset: %d, both of them must be in range [1..65535]", nil),
ErrDataInConsistentExtraIndex: mysql.Message("handle %#v, index:%#v != record:%#v", []int{0, 1, 2}),
ErrDataInConsistentMisMatchIndex: mysql.Message("col %s, handle %#v, index:%#v != record:%#v, compare err:%#v", []int{1, 2, 3, 4}),
ErrDataInconsistentMismatchCount: mysql.Message("data inconsistency in table: %s, index: %s, index-count:%d != record-count:%d", nil),
ErrDataInconsistentMismatchIndex: mysql.Message("data inconsistency in table: %s, index: %s, col: %s, handle: %#v, index-values:%#v != record-values:%#v, compare err:%#v", []int{3, 4, 5, 6}),
ErrInconsistentRowValue: mysql.Message("writing inconsistent data in table: %s, expected-values:{%s} != record-values:{%s}", []int{1, 2}),
ErrInconsistentHandle: mysql.Message("writing inconsistent data in table: %s, index: %s, index-handle:%#v != record-handle:%#v, index: %#v, record: %#v", []int{2, 3, 4, 5}),
ErrInconsistentIndexedValue: mysql.Message("writing inconsistent data in table: %s, index: %s, col: %s, indexed-value:{%s} != record-value:{%s}", []int{3, 4}),
ErrAssertionFailed: mysql.Message("assertion failed: key: %s, assertion: %s, start_ts: %v, existing start ts: %v, existing commit ts: %v", []int{0}),

ErrWarnOptimizerHintInvalidInteger: mysql.Message("integer value is out of range in '%s'", nil),
ErrWarnOptimizerHintUnsupportedHint: mysql.Message("Optimizer hint %s is not supported by TiDB and is ignored", nil),
Expand Down
26 changes: 23 additions & 3 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ TiDB admin check table failed.

["admin:8223"]
error = '''
index:%#v != record:%#v
data inconsistency in table: %s, index: %s, handle: %s, index-values:%#v != record-values:%#v
'''

["admin:8224"]
Expand Down Expand Up @@ -918,12 +918,12 @@ Export failed: %s

["executor:8133"]
error = '''
handle %#v, index:%#v != record:%#v
data inconsistency in table: %s, index: %s, index-count:%d != record-count:%d
'''

["executor:8134"]
error = '''
col %s, handle %#v, index:%#v != record:%#v, compare err:%#v
data inconsistency in table: %s, index: %s, col: %s, handle: %#v, index-values:%#v != record-values:%#v, compare err:%#v
'''

["executor:8212"]
Expand Down Expand Up @@ -1811,6 +1811,21 @@ error = '''
column %s can't be in none state
'''

["table:8138"]
error = '''
writing inconsistent data in table: %s, expected-values:{%s} != record-values:{%s}
'''

["table:8139"]
error = '''
writing inconsistent data in table: %s, index: %s, index-handle:%#v != record-handle:%#v, index: %#v, record: %#v
'''

["table:8140"]
error = '''
writing inconsistent data in table: %s, index: %s, col: %s, indexed-value:{%s} != record-value:{%s}
'''

["tikv:1105"]
error = '''
Unknown error
Expand All @@ -1831,6 +1846,11 @@ error = '''
Statement aborted because lock(s) could not be acquired immediately and NOWAIT is set.
'''

["tikv:8141"]
error = '''
assertion failed: key: %s, assertion: %s, start_ts: %v, existing start ts: %v, existing commit ts: %v
'''

["tikv:8229"]
error = '''
TTL manager has timed out, pessimistic locks may expire, please commit or rollback this transaction
Expand Down
2 changes: 1 addition & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func (a *ExecStmt) handlePessimisticDML(ctx context.Context, e Executor) error {
keys = filterTemporaryTableKeys(sctx.GetSessionVars(), keys)
seVars := sctx.GetSessionVars()
keys = filterLockTableKeys(seVars.StmtCtx, keys)
lockCtx := newLockCtx(seVars, seVars.LockWaitTimeout)
lockCtx := newLockCtx(seVars, seVars.LockWaitTimeout, len(keys))
var lockKeyStats *util.LockKeysDetails
ctx = context.WithValue(ctx, util.LockKeysDetailCtxKey, &lockKeyStats)
startLocking := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion executor/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (e *RecoverIndexExec) backfillIndexInTxn(ctx context.Context, txn kv.Transa
return result, err
}

_, err = e.index.Create(e.ctx, txn, row.idxVals, row.handle, row.rsData)
_, err = e.index.Create(e.ctx, txn, row.idxVals, row.handle, row.rsData, table.WithIgnoreAssertion)
if err != nil {
return result, err
}
Expand Down
Loading