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.lang.reflect.Constructor;
22 import java.lang.reflect.InvocationTargetException;
23
24 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.hbase.io.TagCompressionContext;
27 import org.apache.hadoop.hbase.io.util.Dictionary;
28
29
30
31
32 @InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
33 public class CompressionContext {
34
35 static final String ENABLE_WAL_TAGS_COMPRESSION =
36 "hbase.regionserver.wal.tags.enablecompression";
37
38
39 public final Dictionary regionDict;
40 public final Dictionary tableDict;
41 public final Dictionary familyDict;
42 final Dictionary qualifierDict;
43 final Dictionary rowDict;
44
45 TagCompressionContext tagCompressionContext = null;
46
47 public CompressionContext(Class<? extends Dictionary> dictType, boolean recoveredEdits,
48 boolean hasTagCompression) throws SecurityException, NoSuchMethodException,
49 InstantiationException, IllegalAccessException, InvocationTargetException {
50 Constructor<? extends Dictionary> dictConstructor =
51 dictType.getConstructor();
52 regionDict = dictConstructor.newInstance();
53 tableDict = dictConstructor.newInstance();
54 familyDict = dictConstructor.newInstance();
55 qualifierDict = dictConstructor.newInstance();
56 rowDict = dictConstructor.newInstance();
57 if (recoveredEdits) {
58
59 regionDict.init(1);
60 tableDict.init(1);
61 } else {
62 regionDict.init(Short.MAX_VALUE);
63 tableDict.init(Short.MAX_VALUE);
64 }
65 rowDict.init(Short.MAX_VALUE);
66 familyDict.init(Byte.MAX_VALUE);
67 qualifierDict.init(Byte.MAX_VALUE);
68 if (hasTagCompression) {
69 tagCompressionContext = new TagCompressionContext(dictType, Short.MAX_VALUE);
70 }
71 }
72
73 void clear() {
74 regionDict.clear();
75 tableDict.clear();
76 familyDict.clear();
77 qualifierDict.clear();
78 rowDict.clear();
79 if (tagCompressionContext != null) {
80 tagCompressionContext.clear();
81 }
82 }
83 }