* *: add TxnManager to manage txn in session * modify * add tests * move failpoint content to a single file
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
// Copyright 2021 PingCAP, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package session
|
|
|
|
import (
|
|
"github.com/pingcap/tidb/infoschema"
|
|
"github.com/pingcap/tidb/sessionctx"
|
|
"github.com/pingcap/tidb/sessiontxn"
|
|
)
|
|
|
|
func init() {
|
|
sessiontxn.GetTxnManager = getTxnManager
|
|
}
|
|
|
|
func getTxnManager(sctx sessionctx.Context) sessiontxn.TxnManager {
|
|
if manager, ok := sctx.GetSessionVars().TxnManager.(sessiontxn.TxnManager); ok {
|
|
return manager
|
|
}
|
|
|
|
manager := newTxnManager(sctx)
|
|
sctx.GetSessionVars().TxnManager = manager
|
|
return manager
|
|
}
|
|
|
|
// txnManager implements sessiontxn.TxnManager
|
|
type txnManager struct {
|
|
sctx sessionctx.Context
|
|
|
|
ctxProvider sessiontxn.TxnContextProvider
|
|
}
|
|
|
|
func newTxnManager(sctx sessionctx.Context) *txnManager {
|
|
return &txnManager{sctx: sctx}
|
|
}
|
|
|
|
func (m *txnManager) GetTxnInfoSchema() infoschema.InfoSchema {
|
|
if m.ctxProvider == nil {
|
|
return nil
|
|
}
|
|
return m.ctxProvider.GetTxnInfoSchema()
|
|
}
|
|
|
|
func (m *txnManager) GetContextProvider() sessiontxn.TxnContextProvider {
|
|
return m.ctxProvider
|
|
}
|
|
|
|
func (m *txnManager) SetContextProvider(provider sessiontxn.TxnContextProvider) error {
|
|
m.ctxProvider = provider
|
|
return nil
|
|
}
|