1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver.wal;
20
21 import java.io.DataInput;
22 import java.io.DataOutput;
23 import java.io.EOFException;
24 import java.io.IOException;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.UUID;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.hadoop.hbase.classification.InterfaceAudience;
32 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
33 import org.apache.hadoop.hbase.HRegionInfo;
34 import org.apache.hadoop.hbase.TableName;
35 import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl;
36 import org.apache.hadoop.hbase.util.Bytes;
37 import org.apache.hadoop.hbase.wal.WALKey;
38 import org.apache.hadoop.io.Writable;
39 import org.apache.hadoop.io.WritableUtils;
40
41
42
43
44
45
46
47
48
49
50
51
52 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
53 @Deprecated
54 public class HLogKey extends WALKey implements Writable {
55 private static final Log LOG = LogFactory.getLog(HLogKey.class);
56
57 public HLogKey() {
58 super();
59 }
60
61 @InterfaceAudience.Private
62 public HLogKey(final byte[] encodedRegionName, final TableName tablename, long logSeqNum,
63 final long now, UUID clusterId) {
64 super(encodedRegionName, tablename, logSeqNum, now, clusterId);
65 }
66
67 public HLogKey(final byte[] encodedRegionName, final TableName tablename) {
68 super(encodedRegionName, tablename);
69 }
70
71 @InterfaceAudience.Private
72 public HLogKey(final byte[] encodedRegionName, final TableName tablename, final long now) {
73 super(encodedRegionName, tablename, now);
74 }
75
76 public HLogKey(final byte[] encodedRegionName,
77 final TableName tablename,
78 final long now,
79 final MultiVersionConcurrencyControl mvcc) {
80 super(encodedRegionName, tablename, now, mvcc);
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 public HLogKey(
97 final byte[] encodedRegionName,
98 final TableName tablename,
99 long logSeqNum,
100 final long now,
101 List<UUID> clusterIds,
102 long nonceGroup,
103 long nonce,
104 MultiVersionConcurrencyControl mvcc) {
105 super(encodedRegionName, tablename, logSeqNum, now, clusterIds, nonceGroup, nonce, mvcc);
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 public HLogKey(final byte[] encodedRegionName,
122 final TableName tablename,
123 final long now,
124 List<UUID> clusterIds,
125 long nonceGroup,
126 long nonce,
127 final MultiVersionConcurrencyControl mvcc) {
128 super(encodedRegionName, tablename, now, clusterIds, nonceGroup, nonce, mvcc);
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143 public HLogKey(final byte [] encodedRegionName, final TableName tablename, long logSeqNum,
144 long nonceGroup, long nonce, MultiVersionConcurrencyControl mvcc) {
145 super(encodedRegionName, tablename, logSeqNum, nonceGroup, nonce, mvcc);
146 }
147
148
149
150
151 @Override
152 @Deprecated
153 public void write(DataOutput out) throws IOException {
154 LOG.warn("HLogKey is being serialized to writable - only expected in test code");
155 WritableUtils.writeVInt(out, VERSION.code);
156 if (compressionContext == null) {
157 Bytes.writeByteArray(out, this.encodedRegionName);
158 Bytes.writeByteArray(out, this.tablename.getName());
159 } else {
160 Compressor.writeCompressed(this.encodedRegionName, 0,
161 this.encodedRegionName.length, out,
162 compressionContext.regionDict);
163 Compressor.writeCompressed(this.tablename.getName(), 0,
164 this.tablename.getName().length, out,
165 compressionContext.tableDict);
166 }
167 out.writeLong(this.logSeqNum);
168 out.writeLong(this.writeTime);
169
170
171 Iterator<UUID> iterator = clusterIds.iterator();
172 if(iterator.hasNext()){
173 out.writeBoolean(true);
174 UUID clusterId = iterator.next();
175 out.writeLong(clusterId.getMostSignificantBits());
176 out.writeLong(clusterId.getLeastSignificantBits());
177 } else {
178 out.writeBoolean(false);
179 }
180 }
181
182 @Override
183 public void readFields(DataInput in) throws IOException {
184 Version version = Version.UNVERSIONED;
185
186
187
188
189
190
191
192
193 setScopes(null);
194 int len = WritableUtils.readVInt(in);
195 byte[] tablenameBytes = null;
196 if (len < 0) {
197
198 version = Version.fromCode(len);
199
200
201 if (compressionContext == null || !version.atLeast(Version.COMPRESSED)) {
202 len = WritableUtils.readVInt(in);
203 }
204 }
205 if (compressionContext == null || !version.atLeast(Version.COMPRESSED)) {
206 this.encodedRegionName = new byte[len];
207 in.readFully(this.encodedRegionName);
208 tablenameBytes = Bytes.readByteArray(in);
209 } else {
210 this.encodedRegionName = Compressor.readCompressed(in, compressionContext.regionDict);
211 tablenameBytes = Compressor.readCompressed(in, compressionContext.tableDict);
212 }
213
214 this.logSeqNum = in.readLong();
215 this.writeTime = in.readLong();
216
217 this.clusterIds.clear();
218 if (version.atLeast(Version.INITIAL)) {
219 if (in.readBoolean()) {
220
221
222 clusterIds.add(new UUID(in.readLong(), in.readLong()));
223 }
224 } else {
225 try {
226
227 in.readByte();
228 } catch(EOFException e) {
229
230 if (LOG.isTraceEnabled()) LOG.trace(e);
231 }
232 }
233 try {
234 this.tablename = TableName.valueOf(tablenameBytes);
235 } catch (IllegalArgumentException iae) {
236 if (Bytes.toString(tablenameBytes).equals(TableName.OLD_META_STR)) {
237
238 LOG.info("Got an old .META. edit, continuing with new format ");
239 this.tablename = TableName.META_TABLE_NAME;
240 this.encodedRegionName = HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes();
241 } else if (Bytes.toString(tablenameBytes).equals(TableName.OLD_ROOT_STR)) {
242 this.tablename = TableName.OLD_ROOT_TABLE_NAME;
243 throw iae;
244 } else throw iae;
245 }
246
247 }
248
249 }