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