1 /* 2 * Copyright 2011 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.hadoop.hbase.io.hfile; 21 22 import java.io.DataOutput; 23 import java.io.IOException; 24 25 /** 26 * A way to write "inline" blocks into an {@link HFile}. Inline blocks are 27 * interspersed with data blocks. For example, Bloom filter chunks and 28 * leaf-level blocks of a multi-level block index are stored as inline blocks. 29 */ 30 public interface InlineBlockWriter { 31 32 /** 33 * Determines whether there is a new block to be written out. 34 * 35 * @param closing 36 * whether the file is being closed, in which case we need to write 37 * out all available data and not wait to accumulate another block 38 */ 39 boolean shouldWriteBlock(boolean closing); 40 41 /** 42 * Writes the block to the provided stream. Must not write any magic records. 43 * Called only if {@link #shouldWriteBlock(boolean)} returned true. 44 * 45 * @param out 46 * a stream (usually a compressing stream) to write the block to 47 */ 48 void writeInlineBlock(DataOutput out) throws IOException; 49 50 /** 51 * Called after a block has been written, and its offset, raw size, and 52 * compressed size have been determined. Can be used to add an entry to a 53 * block index. If this type of inline blocks needs a block index, the inline 54 * block writer is responsible for maintaining it. 55 * 56 * @param offset the offset of the block in the stream 57 * @param onDiskSize the on-disk size of the block 58 * @param uncompressedSize the uncompressed size of the block 59 */ 60 void blockWritten(long offset, int onDiskSize, int uncompressedSize); 61 62 /** 63 * The type of blocks this block writer produces. 64 */ 65 BlockType getInlineBlockType(); 66 67 /** 68 * @return true if inline blocks produced by this writer should be cached 69 */ 70 boolean cacheOnWrite(); 71 }