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.yetus.audience.InterfaceAudience;
023
024/**
025 * A way to write "inline" blocks into an {@link HFile}. Inline blocks are interspersed with data
026 * blocks. For example, Bloom filter chunks and leaf-level blocks of a multi-level block index are
027 * stored as inline blocks.
028 */
029@InterfaceAudience.Private
030public interface InlineBlockWriter {
031
032  /**
033   * Determines whether there is a new block to be written out. n * whether the file is being
034   * closed, in which case we need to write out all available data and not wait to accumulate
035   * another block
036   */
037  boolean shouldWriteBlock(boolean closing);
038
039  /**
040   * Writes the block to the provided stream. Must not write any magic records. Called only if
041   * {@link #shouldWriteBlock(boolean)} returned true. n * a stream (usually a compressing stream)
042   * to write the block to
043   */
044  void writeInlineBlock(DataOutput out) throws IOException;
045
046  /**
047   * Called after a block has been written, and its offset, raw size, and compressed size have been
048   * determined. Can be used to add an entry to a block index. If this type of inline blocks needs a
049   * block index, the inline block writer is responsible for maintaining it.
050   * @param offset           the offset of the block in the stream
051   * @param onDiskSize       the on-disk size of the block
052   * @param uncompressedSize the uncompressed size of the block
053   */
054  void blockWritten(long offset, int onDiskSize, int uncompressedSize);
055
056  /**
057   * The type of blocks this block writer produces.
058   */
059  BlockType getInlineBlockType();
060
061  /** Returns true if inline blocks produced by this writer should be cached */
062  boolean getCacheOnWrite();
063}