View Javadoc
1   /*
2    * Copyright 2017 TiKV Project Authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }