1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.tikv.common.meta;
19
20 import java.io.Serializable;
21 import java.util.Objects;
22
23
24 public class TiTimestamp implements Serializable {
25 private static final int PHYSICAL_SHIFT_BITS = 18;
26
27 private final long physical;
28 private final long logical;
29
30 public TiTimestamp(long p, long l) {
31 this.physical = p;
32 this.logical = l;
33 }
34
35 public static long extractPhysical(long ts) {
36 return ts >> PHYSICAL_SHIFT_BITS;
37 }
38
39 public long getVersion() {
40 return (physical << PHYSICAL_SHIFT_BITS) + logical;
41 }
42
43 public long getPhysical() {
44 return this.physical;
45 }
46
47 public long getLogical() {
48 return this.logical;
49 }
50
51 public TiTimestamp getPrevious() {
52 return new TiTimestamp(physical, logical - 1);
53 }
54
55 @Override
56 public boolean equals(Object other) {
57 if (other == this) {
58 return true;
59 }
60 if (!(other instanceof TiTimestamp)) {
61 return false;
62 }
63 return this.getVersion() == ((TiTimestamp) other).getVersion();
64 }
65
66 @Override
67 public int hashCode() {
68 return Objects.hash(getVersion());
69 }
70
71 @Override
72 public String toString() {
73 return "TiTimestamp(" + getVersion() + ")";
74 }
75 }