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, HFileDataBlockEncoder dataBlockEncoder, boolean includesMemstoreTS, int minorVersion, ChecksumType checksumType, int bytesPerChecksum)
           
 
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()
          Creates a new HFileBlock.
 boolean isWriting()
           
 void releaseCompressor()
          Releases the compressor this writer uses to compress blocks into the compressor pool.
 DataOutputStream startWriting(BlockType newBlockType)
          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,
                         HFileDataBlockEncoder dataBlockEncoder,
                         boolean includesMemstoreTS,
                         int minorVersion,
                         ChecksumType checksumType,
                         int bytesPerChecksum)
Parameters:
compressionAlgorithm - compression algorithm to use
dataBlockEncoderAlgo - data block encoding algorithm to use
checksumType - type of checksum
bytesPerChecksum - bytes per checksum
Method Detail

startWriting

public DataOutputStream startWriting(BlockType newBlockType)
                              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

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.


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

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()
Creates a new HFileBlock. Checksums have already been validated, so the byte buffer passed into the constructor of this newly created block does not have checksum data even though the header minor version is MINOR_VERSION_WITH_CHECKSUM. This is indicated by setting a 0 value in bytesPerChecksum.



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