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 java.io.DataOutput; 021import java.io.IOException; 022import org.apache.hadoop.hbase.Cell; 023import org.apache.hadoop.hbase.CellComparator; 024import org.apache.hadoop.hbase.ExtendedCell; 025import org.apache.hadoop.hbase.io.HeapSize; 026import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; 027import org.apache.hadoop.hbase.io.encoding.IndexBlockEncoding; 028import org.apache.hadoop.hbase.util.Bytes; 029import org.apache.yetus.audience.InterfaceAudience; 030 031/** 032 * Controls what kind of index block encoding is used. If index block encoding is not set or the 033 * given block is not a index block (encoded or not), methods should just return the unmodified 034 * block. 035 */ 036@InterfaceAudience.Private 037public interface HFileIndexBlockEncoder { 038 /** Type of encoding used for index blocks in HFile. Stored in file info. */ 039 byte[] INDEX_BLOCK_ENCODING = Bytes.toBytes("INDEX_BLOCK_ENCODING"); 040 041 /** 042 * Save metadata in HFile which will be written to disk 043 * @param writer writer for a given HFile 044 * @exception IOException on disk problems 045 */ 046 void saveMetadata(HFile.Writer writer) throws IOException; 047 048 void encode(BlockIndexChunk blockIndexChunk, boolean rootIndexBlock, DataOutput out) 049 throws IOException; 050 051 /** Returns the index block encoding */ 052 IndexBlockEncoding getIndexBlockEncoding(); 053 054 EncodedSeeker createSeeker(); 055 056 interface EncodedSeeker extends HeapSize { 057 void initRootIndex(HFileBlock blk, int numEntries, CellComparator comparator, int treeLevel) 058 throws IOException; 059 060 boolean isEmpty(); 061 062 ExtendedCell getRootBlockKey(int i); 063 064 int getRootBlockCount(); 065 066 ExtendedCell midkey(HFile.CachingBlockReader cachingBlockReader) throws IOException; 067 068 int rootBlockContainingKey(Cell key); 069 070 BlockWithScanInfo loadDataBlockWithScanInfo(ExtendedCell key, HFileBlock currentBlock, 071 boolean cacheBlocks, boolean pread, boolean isCompaction, 072 DataBlockEncoding expectedDataBlockEncoding, HFile.CachingBlockReader cachingBlockReader) 073 throws IOException; 074 } 075}