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