View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.io.TagCompressionContext;
26  import org.apache.hadoop.hbase.io.util.Dictionary;
27  
28  /**
29   * Context that holds the various dictionaries for compression in HLog.
30   */
31  @InterfaceAudience.Private
32  class CompressionContext {
33  
34    static final String ENABLE_WAL_TAGS_COMPRESSION = 
35        "hbase.regionserver.wal.tags.enablecompression";
36  
37    final Dictionary regionDict;
38    final Dictionary tableDict;
39    final Dictionary familyDict;
40    final Dictionary qualifierDict;
41    final Dictionary rowDict;
42    // Context used for compressing tags
43    TagCompressionContext tagCompressionContext = null;
44  
45    public CompressionContext(Class<? extends Dictionary> dictType, boolean recoveredEdits,
46        boolean hasTagCompression) throws SecurityException, NoSuchMethodException,
47        InstantiationException, IllegalAccessException, InvocationTargetException {
48      Constructor<? extends Dictionary> dictConstructor =
49          dictType.getConstructor();
50      regionDict = dictConstructor.newInstance();
51      tableDict = dictConstructor.newInstance();
52      familyDict = dictConstructor.newInstance();
53      qualifierDict = dictConstructor.newInstance();
54      rowDict = dictConstructor.newInstance();
55      if (recoveredEdits) {
56        // This will never change
57        regionDict.init(1);
58        tableDict.init(1);
59      } else {
60        regionDict.init(Short.MAX_VALUE);
61        tableDict.init(Short.MAX_VALUE);
62      }
63      rowDict.init(Short.MAX_VALUE);
64      familyDict.init(Byte.MAX_VALUE);
65      qualifierDict.init(Byte.MAX_VALUE);
66      if (hasTagCompression) {
67        tagCompressionContext = new TagCompressionContext(dictType, Short.MAX_VALUE);
68      }
69    }
70  
71    void clear() {
72      regionDict.clear();
73      tableDict.clear();
74      familyDict.clear();
75      qualifierDict.clear();
76      rowDict.clear();
77      if (tagCompressionContext != null) {
78        tagCompressionContext.clear();
79      }
80    }
81  }