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 Nov 4, 2021
1 parent e60abeb commit a83c747
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 12 additions & 4 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/util/topsql"
"github.com/pingcap/tipb/go-binlog"
"go.uber.org/zap"

"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
Expand All @@ -73,6 +69,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"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/telemetry"
"github.com/pingcap/tidb/types"
Expand All @@ -87,9 +84,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 +564,14 @@ func (s *session) doCommit(ctx context.Context) error {

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

// TODO: add an enablement check
if 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

0 comments on commit a83c747

Please sign in to comment.