View Javadoc
1   /*
2    * Copyright 2020 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 org.tikv.kvproto.Kvrpcpb;
21  
22  // ttl > 0: lock is not resolved
23  //
24  // <p>ttl = 0 && commitTS = 0: lock is deleted
25  //
26  // <p>ttl = 0 && commitTS > 0: lock is committed
27  public class TxnStatus {
28    private long ttl;
29    private long commitTS;
30    private Kvrpcpb.Action action;
31  
32    public TxnStatus() {
33      this.ttl = 0L;
34      this.commitTS = 0L;
35      this.action = Kvrpcpb.Action.UNRECOGNIZED;
36    }
37  
38    public TxnStatus(long ttl) {
39      this.ttl = ttl;
40      this.commitTS = 0L;
41      this.action = Kvrpcpb.Action.UNRECOGNIZED;
42    }
43  
44    public TxnStatus(long ttl, long commitTS) {
45      this.ttl = ttl;
46      this.commitTS = commitTS;
47      this.action = Kvrpcpb.Action.UNRECOGNIZED;
48    }
49  
50    public TxnStatus(long ttl, long commitTS, Kvrpcpb.Action action) {
51      this.ttl = ttl;
52      this.commitTS = commitTS;
53      this.action = action;
54    }
55  
56    public long getTtl() {
57      return ttl;
58    }
59  
60    public void setTtl(long ttl) {
61      this.ttl = ttl;
62    }
63  
64    public long getCommitTS() {
65      return commitTS;
66    }
67  
68    public void setCommitTS(long commitTS) {
69      this.commitTS = commitTS;
70    }
71  
72    public boolean isCommitted() {
73      return ttl == 0 && commitTS > 0;
74    }
75  
76    public Kvrpcpb.Action getAction() {
77      return action;
78    }
79  
80    public void setAction(Kvrpcpb.Action action) {
81      this.action = action;
82    }
83  }