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 */ 018package org.apache.hadoop.hbase.regionserver.compactions; 019 020import java.io.IOException; 021import java.util.List; 022import java.util.Map; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.ExtendedCell; 025import org.apache.hadoop.hbase.regionserver.CustomTieringMultiFileWriter; 026import org.apache.hadoop.hbase.regionserver.DateTieredMultiFileWriter; 027import org.apache.hadoop.hbase.regionserver.HStore; 028import org.apache.yetus.audience.InterfaceAudience; 029 030@InterfaceAudience.Private 031public class CustomTieredCompactor extends DateTieredCompactor { 032 033 public static final String TIERING_VALUE_PROVIDER = 034 "hbase.hstore.custom-tiering-value.provider.class"; 035 private TieringValueProvider tieringValueProvider; 036 037 public CustomTieredCompactor(Configuration conf, HStore store) throws IOException { 038 super(conf, store); 039 String className = 040 conf.get(TIERING_VALUE_PROVIDER, CustomCellTieringValueProvider.class.getName()); 041 try { 042 tieringValueProvider = 043 (TieringValueProvider) Class.forName(className).getConstructor().newInstance(); 044 tieringValueProvider.init(conf); 045 } catch (Exception e) { 046 throw new IOException("Unable to load configured tiering value provider '" + className + "'", 047 e); 048 } 049 } 050 051 @Override 052 protected List<ExtendedCell> decorateCells(List<ExtendedCell> cells) { 053 return tieringValueProvider.decorateCells(cells); 054 } 055 056 @Override 057 protected DateTieredMultiFileWriter createMultiWriter(final CompactionRequestImpl request, 058 final List<Long> lowerBoundaries, final Map<Long, String> lowerBoundariesPolicies) { 059 return new CustomTieringMultiFileWriter(lowerBoundaries, lowerBoundariesPolicies, 060 needEmptyFile(request), CustomTieredCompactor.this.tieringValueProvider::getTieringValue); 061 } 062 063 public interface TieringValueProvider { 064 065 void init(Configuration configuration) throws Exception; 066 067 default List<ExtendedCell> decorateCells(List<ExtendedCell> cells) { 068 return cells; 069 } 070 071 long getTieringValue(ExtendedCell cell); 072 } 073 074}