001/*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.io.hfile;
020
021import java.io.DataOutput;
022import java.io.IOException;
023
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * A way to write "inline" blocks into an {@link HFile}. Inline blocks are
028 * interspersed with data blocks. For example, Bloom filter chunks and
029 * leaf-level blocks of a multi-level block index are stored as inline blocks.
030 */
031@InterfaceAudience.Private
032public interface InlineBlockWriter {
033
034  /**
035   * Determines whether there is a new block to be written out.
036   *
037   * @param closing
038   *          whether the file is being closed, in which case we need to write
039   *          out all available data and not wait to accumulate another block
040   */
041  boolean shouldWriteBlock(boolean closing);
042
043  /**
044   * Writes the block to the provided stream. Must not write any magic records.
045   * Called only if {@link #shouldWriteBlock(boolean)} returned true.
046   *
047   * @param out
048   *          a stream (usually a compressing stream) to write the block to
049   */
050  void writeInlineBlock(DataOutput out) throws IOException;
051
052  /**
053   * Called after a block has been written, and its offset, raw size, and
054   * compressed size have been determined. Can be used to add an entry to a
055   * block index. If this type of inline blocks needs a block index, the inline
056   * block writer is responsible for maintaining it.
057   *
058   * @param offset the offset of the block in the stream
059   * @param onDiskSize the on-disk size of the block
060   * @param uncompressedSize the uncompressed size of the block
061   */
062  void blockWritten(long offset, int onDiskSize, int uncompressedSize);
063
064  /**
065   * The type of blocks this block writer produces.
066   */
067  BlockType getInlineBlockType();
068
069  /**
070   * @return true if inline blocks produced by this writer should be cached
071   */
072  boolean getCacheOnWrite();
073}