diff --git a/store/driver/txn/txn_driver.go b/store/driver/txn/txn_driver.go index 9a5731c14973e..39e2f4b0f9b20 100644 --- a/store/driver/txn/txn_driver.go +++ b/store/driver/txn/txn_driver.go @@ -136,6 +136,8 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) { txn.KVTxn.GetSnapshot().SetIsolationLevel(level) case tikvstore.Pessimistic: txn.SetPessimistic(val.(bool)) + case tikvstore.CommitHook: + txn.SetCommitCallback(val.(func(string, error))) default: txn.KVTxn.SetOption(opt, val) } diff --git a/store/tikv/txn.go b/store/tikv/txn.go index 67477c510cee4..6f57f5cbb9cf4 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -186,8 +186,6 @@ func (txn *KVTxn) SetOption(opt int, val interface{}) { txn.txnInfoSchema = val.(SchemaVer) case kv.SchemaAmender: txn.schemaAmender = val.(SchemaAmender) - case kv.CommitHook: - txn.commitCallback = val.(func(info string, err error)) } } @@ -211,6 +209,12 @@ func (txn *KVTxn) SetPessimistic(b bool) { txn.isPessimistic = b } +// SetCommitCallback sets up a function that will be called when the transaction +// is finished. +func (txn *KVTxn) SetCommitCallback(f func(string, error)) { + txn.commitCallback = f +} + // SetKVFilter sets the filter to ignore key-values in memory buffer. func (txn *KVTxn) SetKVFilter(filter KVFilter) { txn.kvFilter = filter