org.apache.hadoop.hbase.io.hfile
Class HFileBlock.Writer

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFileBlock.Writer
Enclosing class:
HFileBlock

public static class HFileBlock.Writer
extends Object

Unified version 2 HFile block writer. The intended usage pattern is as follows:


Constructor Summary
HFileBlock.Writer(Compression.Algorithm compressionAlgorithm)
           
 
Method Summary
 int blockSizeWritten()
          Returns the number of bytes written into the current block so far, or zero if not writing the block at the moment.
 HFileBlock getBlockForCaching()
           
 byte[] getHeaderAndData()
          Returns the header or the compressed data (or uncompressed data when not using compression) as a byte array.
 int getOnDiskSizeWithHeader()
          Returns the on-disk size of the block.
 int getOnDiskSizeWithoutHeader()
          Returns the on-disk size of the data portion of the block.
 ByteBuffer getUncompressedBufferWithHeader()
          Similar to getUncompressedBufferWithHeader() but returns a byte buffer.
 int getUncompressedSizeWithHeader()
          The uncompressed size of the block data, including header size.
 int getUncompressedSizeWithoutHeader()
          The uncompressed size of the block data.
 boolean isWriting()
           
 void releaseCompressor()
          Releases the compressor this writer uses to compress blocks into the compressor pool.
 DataOutputStream startWriting(BlockType newBlockType, boolean cacheOnWrite)
          Starts writing into the block.
 void writeBlock(HFileBlock.BlockWritable bw, org.apache.hadoop.fs.FSDataOutputStream out)
          Takes the given HFileBlock.BlockWritable instance, creates a new block of its appropriate type, writes the writable into this block, and flushes the block into the output stream.
 void writeHeaderAndData(org.apache.hadoop.fs.FSDataOutputStream out)
          Similar to writeHeaderAndData(FSDataOutputStream), but records the offset of this block so that it can be referenced in the next block of the same type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HFileBlock.Writer

public HFileBlock.Writer(Compression.Algorithm compressionAlgorithm)
Parameters:
compressionAlgorithm - compression algorithm to use
Method Detail

startWriting

public DataOutputStream startWriting(BlockType newBlockType,
                                     boolean cacheOnWrite)
                              throws IOException
Starts writing into the block. The previous block's data is discarded.

Returns:
the stream the user can write their data into
Throws:
IOException

writeHeaderAndData

public void writeHeaderAndData(org.apache.hadoop.fs.FSDataOutputStream out)
                        throws IOException
Similar to writeHeaderAndData(FSDataOutputStream), but records the offset of this block so that it can be referenced in the next block of the same type.

Parameters:
out -
Throws:
IOException

getHeaderAndData

public byte[] getHeaderAndData()
                        throws IOException
Returns the header or the compressed data (or uncompressed data when not using compression) as a byte array. Can be called in the "writing" state or in the "block ready" state. If called in the "writing" state, transitions the writer to the "block ready" state.

Returns:
header and data as they would be stored on disk in a byte array
Throws:
IOException

releaseCompressor

public void releaseCompressor()
Releases the compressor this writer uses to compress blocks into the compressor pool. Needs to be called before the writer is discarded.


getOnDiskSizeWithoutHeader

public int getOnDiskSizeWithoutHeader()
Returns the on-disk size of the data portion of the block. This is the compressed size if compression is enabled. Can only be called in the "block ready" state. Header is not compressed, and its size is not included in the return value.

Returns:
the on-disk size of the block, not including the header.

getOnDiskSizeWithHeader

public int getOnDiskSizeWithHeader()
Returns the on-disk size of the block. Can only be called in the "block ready" state.

Returns:
the on-disk size of the block ready to be written, including the header size

getUncompressedSizeWithoutHeader

public int getUncompressedSizeWithoutHeader()
The uncompressed size of the block data. Does not include header size.


getUncompressedSizeWithHeader

public int getUncompressedSizeWithHeader()
The uncompressed size of the block data, including header size.


isWriting

public boolean isWriting()
Returns:
true if a block is being written

blockSizeWritten

public int blockSizeWritten()
Returns the number of bytes written into the current block so far, or zero if not writing the block at the moment. Note that this will return zero in the "block ready" state as well.

Returns:
the number of bytes written

getUncompressedBufferWithHeader

public ByteBuffer getUncompressedBufferWithHeader()
Similar to getUncompressedBufferWithHeader() but returns a byte buffer.

Returns:
uncompressed block for caching on write in the form of a buffer

writeBlock

public void writeBlock(HFileBlock.BlockWritable bw,
                       org.apache.hadoop.fs.FSDataOutputStream out)
                throws IOException
Takes the given HFileBlock.BlockWritable instance, creates a new block of its appropriate type, writes the writable into this block, and flushes the block into the output stream. The writer is instructed not to buffer uncompressed bytes for cache-on-write.

Parameters:
bw - the block-writable object to write as a block
out - the file system output stream
Throws:
IOException

getBlockForCaching

public HFileBlock getBlockForCaching()


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.