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. whether the file is being closed, in
034   * which case we need to write out all available data and not wait to accumulate another block
035   */
036  boolean shouldWriteBlock(boolean closing);
037
038  /**
039   * Writes the block to the provided stream. Must not write any magic records. Called only if
040   * {@link #shouldWriteBlock(boolean)} returned true. a stream (usually a compressing stream) to
041   * write the block to
042   */
043  void writeInlineBlock(DataOutput out) throws IOException;
044
045  /**
046   * Called after a block has been written, and its offset, raw size, and compressed size have been
047   * determined. Can be used to add an entry to a block index. If this type of inline blocks needs a
048   * block index, the inline block writer is responsible for maintaining it.
049   * @param offset           the offset of the block in the stream
050   * @param onDiskSize       the on-disk size of the block
051   * @param uncompressedSize the uncompressed size of the block
052   */
053  void blockWritten(long offset, int onDiskSize, int uncompressedSize);
054
055  /**
056   * The type of blocks this block writer produces.
057   */
058  BlockType getInlineBlockType();
059
060  /** Returns true if inline blocks produced by this writer should be cached */
061  boolean getCacheOnWrite();
062}