001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.hbase.regionserver.wal; 020 021import java.lang.reflect.Constructor; 022import java.lang.reflect.InvocationTargetException; 023 024import org.apache.hadoop.hbase.HBaseInterfaceAudience; 025import org.apache.yetus.audience.InterfaceAudience; 026import org.apache.hadoop.hbase.io.TagCompressionContext; 027import org.apache.hadoop.hbase.io.util.Dictionary; 028 029/** 030 * Context that holds the various dictionaries for compression in WAL. 031 */ 032@InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX}) 033public class CompressionContext { 034 035 static final String ENABLE_WAL_TAGS_COMPRESSION = 036 "hbase.regionserver.wal.tags.enablecompression"; 037 038 // visible only for WALKey, until we move everything into o.a.h.h.wal 039 public final Dictionary regionDict; 040 public final Dictionary tableDict; 041 public final Dictionary familyDict; 042 final Dictionary qualifierDict; 043 final Dictionary rowDict; 044 // Context used for compressing tags 045 TagCompressionContext tagCompressionContext = null; 046 047 public CompressionContext(Class<? extends Dictionary> dictType, boolean recoveredEdits, 048 boolean hasTagCompression) throws SecurityException, NoSuchMethodException, 049 InstantiationException, IllegalAccessException, InvocationTargetException { 050 Constructor<? extends Dictionary> dictConstructor = 051 dictType.getConstructor(); 052 regionDict = dictConstructor.newInstance(); 053 tableDict = dictConstructor.newInstance(); 054 familyDict = dictConstructor.newInstance(); 055 qualifierDict = dictConstructor.newInstance(); 056 rowDict = dictConstructor.newInstance(); 057 if (recoveredEdits) { 058 // This will never change 059 regionDict.init(1); 060 tableDict.init(1); 061 } else { 062 regionDict.init(Short.MAX_VALUE); 063 tableDict.init(Short.MAX_VALUE); 064 } 065 rowDict.init(Short.MAX_VALUE); 066 familyDict.init(Byte.MAX_VALUE); 067 qualifierDict.init(Byte.MAX_VALUE); 068 if (hasTagCompression) { 069 tagCompressionContext = new TagCompressionContext(dictType, Short.MAX_VALUE); 070 } 071 } 072 073 void clear() { 074 regionDict.clear(); 075 tableDict.clear(); 076 familyDict.clear(); 077 qualifierDict.clear(); 078 rowDict.clear(); 079 if (tagCompressionContext != null) { 080 tagCompressionContext.clear(); 081 } 082 } 083}