View Javadoc

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