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

store/tikv: remove use of SchemaLease transaction option in store/tikv #24331

Merged
merged 8 commits into from
Apr 28, 2021
2 changes: 2 additions & 0 deletions store/driver/txn/txn_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) {
txn: txn.KVTxn,
binInfo: val.(*binloginfo.BinlogInfo), // val cannot be other type.
})
case tikvstore.SchemaChecker:
txn.SetSchemaLeaseChecker(val.(tikv.SchemaLeaseChecker))
default:
txn.KVTxn.SetOption(opt, val)
}
Expand Down
7 changes: 4 additions & 3 deletions store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,8 @@ type SchemaVer interface {
SchemaMetaVersion() int64
}

type schemaLeaseChecker interface {
// SchemaLeaseChecker is used to validate schema version is not changed during transaction execution.
type SchemaLeaseChecker interface {
// CheckBySchemaVer checks if the schema has changed for the transaction related tables between the startSchemaVer
// and the schema version at txnTS, all the related schema changes will be returned.
CheckBySchemaVer(txnTS uint64, startSchemaVer SchemaVer) (*RelatedSchemaChange, error)
Expand Down Expand Up @@ -1398,8 +1399,8 @@ func (c *twoPhaseCommitter) checkSchemaValid(ctx context.Context, checkTS uint64
err := errors.Errorf("mock check schema valid failure")
failpoint.Return(nil, false, err)
})
checker, ok := c.txn.us.GetOption(kv.SchemaChecker).(schemaLeaseChecker)
if !ok {
checker := c.txn.schemaLeaseChecker
if checker == nil {
disksing marked this conversation as resolved.
Show resolved Hide resolved
if c.sessionID > 0 {
logutil.Logger(ctx).Warn("schemaLeaseChecker is not set for this transaction",
zap.Uint64("sessionID", c.sessionID),
Expand Down
8 changes: 7 additions & 1 deletion store/tikv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ type KVTxn struct {
// commitCallback is called after current transaction gets committed
commitCallback func(info string, err error)

binlog BinlogExecutor
binlog BinlogExecutor
schemaLeaseChecker SchemaLeaseChecker
}

func newTiKVTxn(store *KVStore, txnScope string) (*KVTxn, error) {
Expand Down Expand Up @@ -198,6 +199,11 @@ func (txn *KVTxn) DelOption(opt int) {
txn.us.DelOption(opt)
}

// SetSchemaLeaseChecker sets a hook to check schema version.
func (txn *KVTxn) SetSchemaLeaseChecker(checker SchemaLeaseChecker) {
txn.schemaLeaseChecker = checker
}

// IsPessimistic returns true if it is pessimistic.
func (txn *KVTxn) IsPessimistic() bool {
return txn.us.GetOption(kv.Pessimistic) != nil
Expand Down