diff --git a/store/driver/txn/txn_driver.go b/store/driver/txn/txn_driver.go index 0a78c8ed935d3..968d0f8701233 100644 --- a/store/driver/txn/txn_driver.go +++ b/store/driver/txn/txn_driver.go @@ -144,6 +144,8 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) { txn.SetPessimistic(val.(bool)) case tikvstore.SnapshotTS: txn.KVTxn.GetSnapshot().SetSnapshotTS(val.(uint64)) + 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 4a73bb30b4d77..de0d607f5f55a 100644 --- a/store/tikv/txn.go +++ b/store/tikv/txn.go @@ -187,8 +187,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)) } } @@ -223,6 +221,12 @@ func (txn *KVTxn) SetPriority(pri Priority) { txn.GetSnapshot().SetPriority(pri) } +// 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