mirror of https://github.com/tikv/client-go.git
tikv: remove BeginWithOption method (#370)
* tikv: remove BeginWithOption method Signed-off-by: Xu Qiaolun <jamesxql@gmail.com> * reset the tidb version in integration test to latest tidb master Signed-off-by: Xu Qiaolun <jamesxql@gmail.com>
This commit is contained in:
parent
6ac6a8daf2
commit
8a4ce38c2a
|
|
@ -629,12 +629,12 @@ func (s *testCommitterSuite) TestRejectCommitTS() {
|
|||
// Use max.Uint64 to read the data and success.
|
||||
// That means the final commitTS > startTS+2, it's not the one we provide.
|
||||
// So we cover the rety commitTS logic.
|
||||
txn1, err := s.store.BeginWithOption(tikv.DefaultStartTSOption().SetStartTS(committer.GetStartTS() + 2))
|
||||
txn1, err := s.store.KVStore.Begin(tikv.WithStartTS(committer.GetStartTS() + 2))
|
||||
s.Nil(err)
|
||||
_, err = txn1.Get(bo.GetCtx(), []byte("x"))
|
||||
s.True(tikverr.IsErrNotFound(err))
|
||||
|
||||
txn2, err := s.store.BeginWithOption(tikv.DefaultStartTSOption().SetStartTS(math.MaxUint64))
|
||||
txn2, err := s.store.KVStore.Begin(tikv.WithStartTS(math.MaxUint64))
|
||||
s.Nil(err)
|
||||
val, err := txn2.Get(bo.GetCtx(), []byte("x"))
|
||||
s.Nil(err)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ require (
|
|||
github.com/ninedraft/israce v0.0.3
|
||||
github.com/pingcap/failpoint v0.0.0-20210316064728-7acb0f0a3dfd
|
||||
github.com/pingcap/kvproto v0.0.0-20211011060348-d957056f1551
|
||||
github.com/pingcap/tidb v1.1.0-beta.0.20211031114450-f271148d792f
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211031114450-f271148d792f // indirect
|
||||
github.com/pingcap/tidb v1.1.0-beta.0.20211111035905-25d698c79730
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211111035905-25d698c79730 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/tikv/client-go/v2 v2.0.0
|
||||
github.com/tikv/client-go/v2 v2.0.0-alpha.0.20211103022933-5ae005dac331
|
||||
github.com/tikv/pd v1.1.0-beta.0.20211029083450-e65f0c55b6ae
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723
|
||||
)
|
||||
|
|
|
|||
|
|
@ -552,8 +552,9 @@ github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTw
|
|||
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||
github.com/pingcap/errors v0.11.5-0.20200917111840-a15ef68f753d/go.mod h1:g4vx//d6VakjJ0mk7iLBlKA8LFavV/sAVINT/1PFxeQ=
|
||||
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3/go.mod h1:G7x87le1poQzLB/TqvTJI2ILrSgobnq4Ut7luOwvfvI=
|
||||
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 h1:+FZIDR/D97YOPik4N4lPDaUcLDF/EQPogxtlHB2ZZRM=
|
||||
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
|
||||
github.com/pingcap/errors v0.11.5-0.20211009033009-93128226aaa3 h1:8l9lu9RjWkI/VeqrP+Fn3tvZNPu5GYP0rYLLN5Q46go=
|
||||
github.com/pingcap/errors v0.11.5-0.20211009033009-93128226aaa3/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
|
||||
github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d/go.mod h1:DNS3Qg7bEDhU6EXNHF+XSv/PGznQaMJ5FWvctpm6pQI=
|
||||
github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce/go.mod h1:w4PEZ5y16LeofeeGwdgZB4ddv9bLyDuIX+ljstgKZyk=
|
||||
github.com/pingcap/failpoint v0.0.0-20210316064728-7acb0f0a3dfd h1:I8IeI8MNiZVKnwuXhcIIzz6pREcOSbq18Q31KYIzFVM=
|
||||
|
|
@ -576,16 +577,16 @@ github.com/pingcap/log v0.0.0-20210906054005-afc726e70354/go.mod h1:DWQW5jICDR7U
|
|||
github.com/pingcap/sysutil v0.0.0-20210315073920-cc0985d983a3/go.mod h1:tckvA041UWP+NqYzrJ3fMgC/Hw9wnmQ/tUkp/JaHly8=
|
||||
github.com/pingcap/sysutil v0.0.0-20210730114356-fcd8a63f68c5 h1:7rvAtZe/ZUzOKzgriNPQoBNvleJXBk4z7L3Z47+tS98=
|
||||
github.com/pingcap/sysutil v0.0.0-20210730114356-fcd8a63f68c5/go.mod h1:XsOaV712rUk63aOEKYP9PhXTIE3FMNHmC2r1wX5wElY=
|
||||
github.com/pingcap/tidb v1.1.0-beta.0.20211031114450-f271148d792f h1:ojoulRH3eZz3tEn2re2J6Wpdr6SSGcb/fo26VhmEIbc=
|
||||
github.com/pingcap/tidb v1.1.0-beta.0.20211031114450-f271148d792f/go.mod h1:Pv+WlFkX7KP+lpsJG8kNYDTC18DGJsGS0Tf7IoNc11U=
|
||||
github.com/pingcap/tidb v1.1.0-beta.0.20211111035905-25d698c79730 h1:dFbUXxGYk0rx3R2dxhK6HZ93cj+tCAq66JjZ1GX5TgU=
|
||||
github.com/pingcap/tidb v1.1.0-beta.0.20211111035905-25d698c79730/go.mod h1:Z5NlUEsyr1yVAtTaKNdOO7WgySTZuwnCP6kuCaUiRyc=
|
||||
github.com/pingcap/tidb-dashboard v0.0.0-20211008050453-a25c25809529/go.mod h1:OCXbZTBTIMRcIt0jFsuCakZP+goYRv6IjawKbwLS2TQ=
|
||||
github.com/pingcap/tidb-tools v5.2.2-0.20211019062242-37a8bef2fa17+incompatible h1:c7+izmker91NkjkZ6FgTlmD4k1A5FLOAq+li6Ki2/GY=
|
||||
github.com/pingcap/tidb-tools v5.2.2-0.20211019062242-37a8bef2fa17+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211011031125-9b13dc409c5e/go.mod h1:e1MGCA9Sg3T8jid8PKAEq5eYVuMMCq4n8gJ+Kqp4Plg=
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211031114450-f271148d792f h1:qX2NOcsgw+/7Wj+00jOdrJocg3sEKYbubgyVdBRSNtQ=
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211031114450-f271148d792f/go.mod h1:MAa22tagoj7nv5b1NBcxPkc5CiUNhqj1wuSQnw4f9WE=
|
||||
github.com/pingcap/tipb v0.0.0-20211026080602-ec68283c1735 h1:kS8pJNUnF3ENkjtBcJeMe/W8+9RtrChcortoyljCwwc=
|
||||
github.com/pingcap/tipb v0.0.0-20211026080602-ec68283c1735/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs=
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211111035905-25d698c79730 h1:wNgibpxmYT9nhnB6mwOpY+Jn29Pze49f5GXHz+Wv7ks=
|
||||
github.com/pingcap/tidb/parser v0.0.0-20211111035905-25d698c79730/go.mod h1:MAa22tagoj7nv5b1NBcxPkc5CiUNhqj1wuSQnw4f9WE=
|
||||
github.com/pingcap/tipb v0.0.0-20211105090418-71142a4d40e3 h1:xnp/Qkk5gELlB8TaY6oro0JNXMBXTafNVxU/vbrNU8I=
|
||||
github.com/pingcap/tipb v0.0.0-20211105090418-71142a4d40e3/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
|
|
|||
46
tikv/kv.go
46
tikv/kv.go
|
|
@ -302,27 +302,6 @@ func (s *KVStore) Begin(opts ...TxnOption) (*transaction.KVTxn, error) {
|
|||
return transaction.NewTiKVTxn(s, snapshot, startTS, options.TxnScope)
|
||||
}
|
||||
|
||||
// BeginWithOption begins a transaction with the given StartTSOption
|
||||
// TODO: remove this method once tidb and br are ready
|
||||
func (s *KVStore) BeginWithOption(options StartTSOption) (*transaction.KVTxn, error) {
|
||||
if options.TxnScope == "" {
|
||||
options.TxnScope = oracle.GlobalTxnScope
|
||||
}
|
||||
|
||||
if options.StartTS != nil {
|
||||
snapshot := txnsnapshot.NewTiKVSnapshot(s, *options.StartTS, s.nextReplicaReadSeed())
|
||||
return transaction.NewTiKVTxn(s, snapshot, *options.StartTS, options.TxnScope)
|
||||
}
|
||||
|
||||
bo := retry.NewBackofferWithVars(context.Background(), transaction.TsoMaxBackoff, nil)
|
||||
startTS, err := s.getTimestampWithRetry(bo, options.TxnScope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
snapshot := txnsnapshot.NewTiKVSnapshot(s, startTS, s.nextReplicaReadSeed())
|
||||
return transaction.NewTiKVTxn(s, snapshot, startTS, options.TxnScope)
|
||||
}
|
||||
|
||||
// DeleteRange delete all versions of all keys in the range[startKey,endKey) immediately.
|
||||
// Be careful while using this API. This API doesn't keep recent MVCC versions, but will delete all versions of all keys
|
||||
// in the range immediately. Also notice that frequent invocation to this API may cause performance problems to TiKV.
|
||||
|
|
@ -663,31 +642,6 @@ func WithStartTS(startTS uint64) TxnOption {
|
|||
|
||||
// TODO: remove once tidb and br are ready
|
||||
|
||||
// StartTSOption indicates the option when beginning a transaction
|
||||
// `TxnScope` must be set for each object
|
||||
// Every other fields are optional, but currently at most one of them can be set
|
||||
type StartTSOption struct {
|
||||
TxnScope string
|
||||
StartTS *uint64
|
||||
}
|
||||
|
||||
// DefaultStartTSOption creates a default StartTSOption, ie. Work in GlobalTxnScope and get start ts when got used
|
||||
func DefaultStartTSOption() StartTSOption {
|
||||
return StartTSOption{TxnScope: oracle.GlobalTxnScope}
|
||||
}
|
||||
|
||||
// SetStartTS returns a new StartTSOption with StartTS set to the given startTS
|
||||
func (to StartTSOption) SetStartTS(startTS uint64) StartTSOption {
|
||||
to.StartTS = &startTS
|
||||
return to
|
||||
}
|
||||
|
||||
// SetTxnScope returns a new StartTSOption with TxnScope set to txnScope
|
||||
func (to StartTSOption) SetTxnScope(txnScope string) StartTSOption {
|
||||
to.TxnScope = txnScope
|
||||
return to
|
||||
}
|
||||
|
||||
// KVTxn contains methods to interact with a TiKV transaction.
|
||||
type KVTxn = transaction.KVTxn
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue