Skip to content

Commit

Permalink
only check when InTxn is true
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <ekexium@gmail.com>
  • Loading branch information
ekexium committed Dec 6, 2021
1 parent 571a488 commit b985104
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 11 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/statistics/handle"
"github.com/pingcap/tidb/table/tables"
storeerr "github.com/pingcap/tidb/store/driver/error"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/telemetry"
Expand All @@ -88,9 +89,12 @@ import (
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/tableutil"
"github.com/pingcap/tidb/util/timeutil"
"github.com/pingcap/tidb/util/topsql"
"github.com/pingcap/tipb/go-binlog"
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikv"
tikvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -564,6 +568,13 @@ func (s *session) doCommit(ctx context.Context) error {

func (s *session) commitTxnWithTemporaryData(ctx context.Context, txn kv.Transaction) error {
sessVars := s.sessionVars

if sessVars.EnableMutationChecker && sessVars.InTxn() {
if err := tables.CheckTxnConsistency(txn); err != nil {
return errors.Trace(err)
}
}

txnTempTables := sessVars.TxnCtx.TemporaryTables
if len(txnTempTables) == 0 {
return txn.Commit(ctx)
Expand Down
6 changes: 0 additions & 6 deletions session/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/pingcap/tidb/session/txninfo"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/binloginfo"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/sli"
Expand Down Expand Up @@ -335,11 +334,6 @@ func (txn *LazyTxn) Commit(ctx context.Context) error {
return errors.Trace(kv.ErrInvalidTxn)
}

// add an enablement check
if err := tables.CheckTxnConsistency(txn); err != nil {
return errors.Trace(err)
}

txn.mu.Lock()
txn.mu.TxnInfo.State = txninfo.TxnCommitting
txn.mu.Unlock()
Expand Down
3 changes: 1 addition & 2 deletions table/tables/mutation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,11 @@ func CheckTxnConsistency(txn kv.Transaction) error {
return errors.Trace(err)
}
for tableID, count := range indexInsertionCount {
// FIXME: always? what if like backfilling?
// TODO: always? what if like backfilling?
if rowInsertionCount[tableID] > 0 && count%rowInsertionCount[tableID] != 0 {
return errors.Errorf("inconsistent index insertion count %d and row insertion count %d",
count, rowInsertionCount[tableID])
}

}
return nil
}

0 comments on commit b985104

Please sign in to comment.