1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.io.hfile;
19 import org.apache.hadoop.hbase.HConstants;
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.io.HeapSize;
22 import org.apache.hadoop.hbase.io.compress.Compression;
23 import org.apache.hadoop.hbase.io.crypto.Encryption;
24 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25 import org.apache.hadoop.hbase.util.Bytes;
26 import org.apache.hadoop.hbase.util.ChecksumType;
27 import org.apache.hadoop.hbase.util.ClassSize;
28
29
30
31
32
33
34 @InterfaceAudience.Private
35 public class HFileContext implements HeapSize, Cloneable {
36
37 public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
38
39
40 private boolean usesHBaseChecksum = true;
41
42 private boolean includesMvcc = true;
43
44 private boolean includesTags;
45
46 private Compression.Algorithm compressAlgo = Compression.Algorithm.NONE;
47
48 private boolean compressTags;
49
50 private ChecksumType checksumType = ChecksumType.getDefaultChecksumType();
51
52 private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
53
54 private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
55 private DataBlockEncoding encoding = DataBlockEncoding.NONE;
56
57 private Encryption.Context cryptoContext = Encryption.Context.NONE;
58 private long fileCreateTime;
59 private String hfileName;
60
61
62 public HFileContext() {
63 }
64
65
66
67
68
69 public HFileContext(HFileContext context) {
70 this.usesHBaseChecksum = context.usesHBaseChecksum;
71 this.includesMvcc = context.includesMvcc;
72 this.includesTags = context.includesTags;
73 this.compressAlgo = context.compressAlgo;
74 this.compressTags = context.compressTags;
75 this.checksumType = context.checksumType;
76 this.bytesPerChecksum = context.bytesPerChecksum;
77 this.blocksize = context.blocksize;
78 this.encoding = context.encoding;
79 this.cryptoContext = context.cryptoContext;
80 this.fileCreateTime = context.fileCreateTime;
81 this.hfileName = context.hfileName;
82 }
83
84 HFileContext(boolean useHBaseChecksum, boolean includesMvcc, boolean includesTags,
85 Compression.Algorithm compressAlgo, boolean compressTags, ChecksumType checksumType,
86 int bytesPerChecksum, int blockSize, DataBlockEncoding encoding,
87 Encryption.Context cryptoContext, long fileCreateTime, String hfileName) {
88 this.usesHBaseChecksum = useHBaseChecksum;
89 this.includesMvcc = includesMvcc;
90 this.includesTags = includesTags;
91 this.compressAlgo = compressAlgo;
92 this.compressTags = compressTags;
93 this.checksumType = checksumType;
94 this.bytesPerChecksum = bytesPerChecksum;
95 this.blocksize = blockSize;
96 if (encoding != null) {
97 this.encoding = encoding;
98 }
99 this.cryptoContext = cryptoContext;
100 this.fileCreateTime = fileCreateTime;
101 this.hfileName = hfileName;
102 }
103
104
105
106
107
108 public boolean isCompressedOrEncrypted() {
109 Compression.Algorithm compressAlgo = getCompression();
110 boolean compressed =
111 compressAlgo != null
112 && compressAlgo != Compression.Algorithm.NONE;
113
114 Encryption.Context cryptoContext = getEncryptionContext();
115 boolean encrypted = cryptoContext != null
116 && cryptoContext != Encryption.Context.NONE;
117
118 return compressed || encrypted;
119 }
120
121 public Compression.Algorithm getCompression() {
122 return compressAlgo;
123 }
124
125 public boolean isUseHBaseChecksum() {
126 return usesHBaseChecksum;
127 }
128
129 public boolean isIncludesMvcc() {
130 return includesMvcc;
131 }
132
133 public void setIncludesMvcc(boolean includesMvcc) {
134 this.includesMvcc = includesMvcc;
135 }
136
137 public boolean isIncludesTags() {
138 return includesTags;
139 }
140
141 public void setIncludesTags(boolean includesTags) {
142 this.includesTags = includesTags;
143 }
144
145 public void setFileCreateTime(long fileCreateTime) {
146 this.fileCreateTime = fileCreateTime;
147 }
148
149 public boolean isCompressTags() {
150 return compressTags;
151 }
152
153 public void setCompressTags(boolean compressTags) {
154 this.compressTags = compressTags;
155 }
156
157 public ChecksumType getChecksumType() {
158 return checksumType;
159 }
160
161 public int getBytesPerChecksum() {
162 return bytesPerChecksum;
163 }
164
165 public int getBlocksize() {
166 return blocksize;
167 }
168
169 public long getFileCreateTime() {
170 return fileCreateTime;
171 }
172
173 public DataBlockEncoding getDataBlockEncoding() {
174 return encoding;
175 }
176
177 public Encryption.Context getEncryptionContext() {
178 return cryptoContext;
179 }
180
181 public void setEncryptionContext(Encryption.Context cryptoContext) {
182 this.cryptoContext = cryptoContext;
183 }
184
185 public String getHFileName() {
186 return this.hfileName;
187 }
188
189
190
191
192
193
194 @Override
195 public long heapSize() {
196 long size = ClassSize.align(ClassSize.OBJECT +
197
198 5 * ClassSize.REFERENCE +
199 2 * Bytes.SIZEOF_INT +
200
201 4 * Bytes.SIZEOF_BOOLEAN +
202 Bytes.SIZEOF_LONG);
203 if (this.hfileName != null) {
204 size += ClassSize.STRING + this.hfileName.length();
205 }
206 return size;
207 }
208
209 @Override
210 public HFileContext clone() {
211 try {
212 return (HFileContext)(super.clone());
213 } catch (CloneNotSupportedException e) {
214 throw new AssertionError();
215 }
216 }
217
218 @Override
219 public String toString() {
220 StringBuilder sb = new StringBuilder();
221 sb.append("HFileContext [");
222 sb.append(" usesHBaseChecksum="); sb.append(usesHBaseChecksum);
223 sb.append(" checksumType="); sb.append(checksumType);
224 sb.append(" bytesPerChecksum="); sb.append(bytesPerChecksum);
225 sb.append(" blocksize="); sb.append(blocksize);
226 sb.append(" encoding="); sb.append(encoding);
227 sb.append(" includesMvcc="); sb.append(includesMvcc);
228 sb.append(" includesTags="); sb.append(includesTags);
229 sb.append(" compressAlgo="); sb.append(compressAlgo);
230 sb.append(" compressTags="); sb.append(compressTags);
231 sb.append(" cryptoContext=[ "); sb.append(cryptoContext); sb.append(" ]");
232 if (hfileName != null) {
233 sb.append(" name=");
234 sb.append(hfileName);
235 }
236 sb.append(" ]");
237 return sb.toString();
238 }
239
240 }