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.io.hfile; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Allows for defining different compression rate predicates on its implementing classes. Useful 024 * when compression is in place, and we want to define block size based on the compressed size, 025 * rather than the default behaviour that considers the uncompressed size only. Since we don't 026 * actually know the compressed size until we actual apply compression in the block byte buffer, we 027 * need to "predicate" this compression rate and minimize compression execution to avoid excessive 028 * resources usage. Different approaches for predicating the compressed block size can be defined by 029 * implementing classes. The <code>updateLatestBlockSizes</code> allows for updating uncompressed 030 * and compressed size values, and is called during block finishing (when we finally apply 031 * compression on the block data). Final block size predicate logic is implemented in 032 * <code>shouldFinishBlock</code>, which is called by the block writer once uncompressed size has 033 * reached the configured BLOCK size, and additional checks should be applied to decide if the block 034 * can be finished. 035 */ 036@InterfaceAudience.Private 037public interface BlockCompressedSizePredicator { 038 039 String BLOCK_COMPRESSED_SIZE_PREDICATOR = "hbase.block.compressed.size.predicator"; 040 041 String MAX_BLOCK_SIZE_UNCOMPRESSED = "hbase.block.max.size.uncompressed"; 042 043 /** 044 * Updates the predicator with both compressed and uncompressed sizes of latest block written. To 045 * be called once the block is finshed and flushed to disk after compression. 046 * @param context the HFileContext containg the configured max block size. 047 * @param uncompressed the uncompressed size of last block written. 048 * @param compressed the compressed size of last block written. 049 */ 050 void updateLatestBlockSizes(HFileContext context, int uncompressed, int compressed); 051 052 /** 053 * Decides if the block should be finished based on the comparison of its uncompressed size 054 * against an adjusted size based on a predicated compression factor. 055 * @param uncompressed true if the block should be finished. 056 */ 057 boolean shouldFinishBlock(int uncompressed); 058 059}