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.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   * Context that holds the various dictionaries for compression in WAL.
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    // visible only for WALKey, until we move everything into o.a.h.h.wal
39    public final Dictionary regionDict;
40    public final Dictionary tableDict;
41    public final Dictionary familyDict;
42    final Dictionary qualifierDict;
43    final Dictionary rowDict;
44    // Context used for compressing tags
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        // This will never change
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  }