1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.tikv.txn;
19
20 import com.google.protobuf.ByteString;
21 import org.tikv.common.apiversion.RequestKeyCodec;
22 import org.tikv.kvproto.Kvrpcpb;
23
24 public class Lock {
25 private static final long DEFAULT_LOCK_TTL = 3000;
26 private final long txnID;
27 private final long ttl;
28 private final ByteString key;
29 private final ByteString primary;
30 private final long txnSize;
31 private final Kvrpcpb.Op lockType;
32 private final long lockForUpdateTs;
33
34 public Lock(Kvrpcpb.LockInfo l, RequestKeyCodec codec) {
35 txnID = l.getLockVersion();
36 key = codec.decodeKey(l.getKey());
37 primary = codec.decodeKey(l.getPrimaryLock());
38 ttl = l.getLockTtl() == 0 ? DEFAULT_LOCK_TTL : l.getLockTtl();
39 txnSize = l.getTxnSize();
40 lockType = l.getLockType();
41 lockForUpdateTs = l.getLockForUpdateTs();
42 }
43
44 public long getTxnID() {
45 return txnID;
46 }
47
48 public long getTtl() {
49 return ttl;
50 }
51
52 public ByteString getKey() {
53 return key;
54 }
55
56 public ByteString getPrimary() {
57 return primary;
58 }
59
60 public long getTxnSize() {
61 return txnSize;
62 }
63
64 public Kvrpcpb.Op getLockType() {
65 return lockType;
66 }
67
68 public long getLockForUpdateTs() {
69 return lockForUpdateTs;
70 }
71 }