-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotxn.go
51 lines (45 loc) · 1.03 KB
/
rotxn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// package sdk defined spanner sdk for tikv transaction
package sdk
type roTxn struct {
transaction
}
func beginROTxn() (*roTxn, error) {
return nil, nil
}
func (txn *roTxn) Get(key []byte) ([]byte, error) {
lg.Debug("call get in ro transection")
// get TS if not exist, and start heartbeat with transaction nodes
if err := txn.setTxnIDNX(); err != nil {
return nil, err
}
// locate key from PD
_, rleader, err := pdClient.GetRegion(txn.ctx, key)
if err != nil {
return nil, err
}
linfo, err := pdClient.GetStore(txn.ctx, rleader.GetId())
if err != nil {
return nil, err
}
// call tikv get RO/RW with TS
kvcli, err := NewTiKV(linfo.GetAddress())
if err != nil {
return nil, err
}
return kvcli.Get(txn.ctx, txn.txnid, key, txn.txnid, true)
}
func (txn *roTxn) Set(key, value []byte) error {
return ErrInvalid
}
func (txn *roTxn) Delete(key []byte) error {
return ErrInvalid
}
func (txn *roTxn) Rollback() error {
return nil
}
func (txn *roTxn) Commit() error {
return nil
}
func (txn *roTxn) Close() error {
return nil
}