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