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.classification.InterfaceAudience;
20 import org.apache.hadoop.hbase.HConstants;
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
60
61 public HFileContext() {
62 }
63
64
65
66
67
68 public HFileContext(HFileContext context) {
69 this.usesHBaseChecksum = context.usesHBaseChecksum;
70 this.includesMvcc = context.includesMvcc;
71 this.includesTags = context.includesTags;
72 this.compressAlgo = context.compressAlgo;
73 this.compressTags = context.compressTags;
74 this.checksumType = context.checksumType;
75 this.bytesPerChecksum = context.bytesPerChecksum;
76 this.blocksize = context.blocksize;
77 this.encoding = context.encoding;
78 this.cryptoContext = context.cryptoContext;
79 this.fileCreateTime = context.fileCreateTime;
80 }
81
82 public HFileContext(boolean useHBaseChecksum, boolean includesMvcc, boolean includesTags,
83 Compression.Algorithm compressAlgo, boolean compressTags, ChecksumType checksumType,
84 int bytesPerChecksum, int blockSize, DataBlockEncoding encoding,
85 Encryption.Context cryptoContext, long fileCreateTime) {
86 this.usesHBaseChecksum = useHBaseChecksum;
87 this.includesMvcc = includesMvcc;
88 this.includesTags = includesTags;
89 this.compressAlgo = compressAlgo;
90 this.compressTags = compressTags;
91 this.checksumType = checksumType;
92 this.bytesPerChecksum = bytesPerChecksum;
93 this.blocksize = blockSize;
94 if (encoding != null) {
95 this.encoding = encoding;
96 }
97 this.cryptoContext = cryptoContext;
98 this.fileCreateTime = fileCreateTime;
99 }
100
101
102
103
104
105 public boolean isCompressedOrEncrypted() {
106 Compression.Algorithm compressAlgo = getCompression();
107 boolean compressed =
108 compressAlgo != null
109 && compressAlgo != Compression.Algorithm.NONE;
110
111 Encryption.Context cryptoContext = getEncryptionContext();
112 boolean encrypted = cryptoContext != null
113 && cryptoContext != Encryption.Context.NONE;
114
115 return compressed || encrypted;
116 }
117
118 public Compression.Algorithm getCompression() {
119 return compressAlgo;
120 }
121
122 public void setCompression(Compression.Algorithm compressAlgo) {
123 this.compressAlgo = compressAlgo;
124 }
125
126 public boolean isUseHBaseChecksum() {
127 return usesHBaseChecksum;
128 }
129
130 public boolean isIncludesMvcc() {
131 return includesMvcc;
132 }
133
134 public void setIncludesMvcc(boolean includesMvcc) {
135 this.includesMvcc = includesMvcc;
136 }
137
138 public boolean isIncludesTags() {
139 return includesTags;
140 }
141
142 public void setIncludesTags(boolean includesTags) {
143 this.includesTags = includesTags;
144 }
145
146 public void setFileCreateTime(long fileCreateTime) {
147 this.fileCreateTime = fileCreateTime;
148 }
149
150 public boolean isCompressTags() {
151 return compressTags;
152 }
153
154 public void setCompressTags(boolean compressTags) {
155 this.compressTags = compressTags;
156 }
157
158 public ChecksumType getChecksumType() {
159 return checksumType;
160 }
161
162 public int getBytesPerChecksum() {
163 return bytesPerChecksum;
164 }
165
166 public int getBlocksize() {
167 return blocksize;
168 }
169
170 public long getFileCreateTime() {
171 return fileCreateTime;
172 }
173
174 public DataBlockEncoding getDataBlockEncoding() {
175 return encoding;
176 }
177
178 public void setDataBlockEncoding(DataBlockEncoding encoding) {
179 this.encoding = encoding;
180 }
181
182 public Encryption.Context getEncryptionContext() {
183 return cryptoContext;
184 }
185
186 public void setEncryptionContext(Encryption.Context cryptoContext) {
187 this.cryptoContext = cryptoContext;
188 }
189
190
191
192
193
194
195 @Override
196 public long heapSize() {
197 long size = ClassSize.align(ClassSize.OBJECT +
198
199 4 * ClassSize.REFERENCE +
200 2 * Bytes.SIZEOF_INT +
201
202 4 * Bytes.SIZEOF_BOOLEAN +
203 Bytes.SIZEOF_LONG);
204 return size;
205 }
206
207 @Override
208 public HFileContext clone() {
209 try {
210 return (HFileContext)(super.clone());
211 } catch (CloneNotSupportedException e) {
212 throw new AssertionError();
213 }
214 }
215
216 @Override
217 public String toString() {
218 StringBuilder sb = new StringBuilder();
219 sb.append("HFileContext [");
220 sb.append(" usesHBaseChecksum="); sb.append(usesHBaseChecksum);
221 sb.append(" checksumType="); sb.append(checksumType);
222 sb.append(" bytesPerChecksum="); sb.append(bytesPerChecksum);
223 sb.append(" blocksize="); sb.append(blocksize);
224 sb.append(" encoding="); sb.append(encoding);
225 sb.append(" includesMvcc="); sb.append(includesMvcc);
226 sb.append(" includesTags="); sb.append(includesTags);
227 sb.append(" compressAlgo="); sb.append(compressAlgo);
228 sb.append(" compressTags="); sb.append(compressTags);
229 sb.append(" cryptoContext=[ "); sb.append(cryptoContext); sb.append(" ]");
230 sb.append(" ]");
231 return sb.toString();
232 }
233
234 }