1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver.wal;
21
22 import java.io.DataInput;
23 import java.io.DataOutput;
24 import java.io.EOFException;
25 import java.io.IOException;
26
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.apache.hadoop.io.WritableComparable;
30
31
32
33
34
35
36
37
38
39
40
41 public class HLogKey implements WritableComparable<HLogKey> {
42 private byte [] regionName;
43 private byte [] tablename;
44 private long logSeqNum;
45
46 private long writeTime;
47
48 private byte clusterId;
49
50
51 public HLogKey() {
52 this(null, null, 0L, HConstants.LATEST_TIMESTAMP);
53 }
54
55
56
57
58
59
60
61
62
63
64
65 public HLogKey(final byte [] regionName, final byte [] tablename,
66 long logSeqNum, final long now) {
67 this.regionName = regionName;
68 this.tablename = tablename;
69 this.logSeqNum = logSeqNum;
70 this.writeTime = now;
71 this.clusterId = HConstants.DEFAULT_CLUSTER_ID;
72 }
73
74
75
76
77
78
79 public byte [] getRegionName() {
80 return regionName;
81 }
82
83
84 public byte [] getTablename() {
85 return tablename;
86 }
87
88
89 public long getLogSeqNum() {
90 return logSeqNum;
91 }
92
93 void setLogSeqNum(long logSeqNum) {
94 this.logSeqNum = logSeqNum;
95 }
96
97
98
99
100 public long getWriteTime() {
101 return this.writeTime;
102 }
103
104
105
106
107
108 public byte getClusterId() {
109 return clusterId;
110 }
111
112
113
114
115
116 public void setClusterId(byte clusterId) {
117 this.clusterId = clusterId;
118 }
119
120 @Override
121 public String toString() {
122 return Bytes.toString(tablename) + "/" + Bytes.toString(regionName) + "/" +
123 logSeqNum;
124 }
125
126 @Override
127 public boolean equals(Object obj) {
128 if (this == obj) {
129 return true;
130 }
131 if (obj == null || getClass() != obj.getClass()) {
132 return false;
133 }
134 return compareTo((HLogKey)obj) == 0;
135 }
136
137 @Override
138 public int hashCode() {
139 int result = Bytes.hashCode(this.regionName);
140 result ^= this.logSeqNum;
141 result ^= this.writeTime;
142 result ^= this.clusterId;
143 return result;
144 }
145
146 public int compareTo(HLogKey o) {
147 int result = Bytes.compareTo(this.regionName, o.regionName);
148 if (result == 0) {
149 if (this.logSeqNum < o.logSeqNum) {
150 result = -1;
151 } else if (this.logSeqNum > o.logSeqNum) {
152 result = 1;
153 }
154 if (result == 0) {
155 if (this.writeTime < o.writeTime) {
156 result = -1;
157 } else if (this.writeTime > o.writeTime) {
158 return 1;
159 }
160 }
161 }
162 return result;
163 }
164
165 public void write(DataOutput out) throws IOException {
166 Bytes.writeByteArray(out, this.regionName);
167 Bytes.writeByteArray(out, this.tablename);
168 out.writeLong(this.logSeqNum);
169 out.writeLong(this.writeTime);
170 out.writeByte(this.clusterId);
171 }
172
173 public void readFields(DataInput in) throws IOException {
174 this.regionName = Bytes.readByteArray(in);
175 this.tablename = Bytes.readByteArray(in);
176 this.logSeqNum = in.readLong();
177 this.writeTime = in.readLong();
178 try {
179 this.clusterId = in.readByte();
180 } catch(EOFException e) {
181
182 }
183 }
184
185 }