static class HFileBlock.Writer extends Object implements ShipperListener
HFile
block writer. The intended usage pattern is as follows:
HFileBlock.Writer
, providing a compression algorithm.
startWriting(org.apache.hadoop.hbase.io.hfile.BlockType)
and get a data stream to write to.
Modifier and Type | Class and Description |
---|---|
private static class |
HFileBlock.Writer.State |
Modifier and Type | Field and Description |
---|---|
private ByteBuffAllocator |
allocator |
private ByteArrayOutputStream |
baosInMemory
The stream we use to accumulate data into a block in an uncompressed format.
|
private BlockType |
blockType
Current block type.
|
private HFileDataBlockEncoder |
dataBlockEncoder
Data block encoder used for data blocks
|
private HFileBlockEncodingContext |
dataBlockEncodingCtx |
private HFileBlockDefaultEncodingContext |
defaultBlockEncodingCtx
block encoding context for non-data blocks
|
private HFileContext |
fileContext
Meta data that holds information about the hfileblock
|
private ByteArrayOutputStream |
onDiskBlockBytesWithHeader
Bytes to be written to the file system, including the header.
|
private byte[] |
onDiskChecksum
The size of the checksum data on disk.
|
private long |
prevOffset
The offset of the previous block of the same type
|
private long[] |
prevOffsetByType
Offset of previous block by block type.
|
private long |
startOffset
Current block's start offset in the
HFile . |
private HFileBlock.Writer.State |
state
Writer state.
|
private DataOutputStream |
userDataStream
A stream that we write uncompressed bytes to, which compresses them and writes them to
baosInMemory . |
Constructor and Description |
---|
Writer(org.apache.hadoop.conf.Configuration conf,
HFileDataBlockEncoder dataBlockEncoder,
HFileContext fileContext) |
Writer(org.apache.hadoop.conf.Configuration conf,
HFileDataBlockEncoder dataBlockEncoder,
HFileContext fileContext,
ByteBuffAllocator allocator) |
Modifier and Type | Method and Description |
---|---|
void |
beforeShipped()
The action that needs to be performed before
Shipper.shipped() is performed n |
(package private) int |
blockSizeWritten()
Returns the number of bytes written into the current block so far, or zero if not writing the
block at the moment.
|
private ByteBuff |
cloneOnDiskBufferWithHeader()
Clones the header followed by the on-disk (compressed/encoded/encrypted) data.
|
(package private) ByteBuff |
cloneUncompressedBufferWithHeader()
Clones the header followed by the uncompressed data, even if using compression.
|
int |
encodedBlockSizeWritten()
Returns the number of bytes written into the current block so far, or zero if not writing the
block at the moment.
|
(package private) void |
ensureBlockReady()
Transitions the block writer from the "writing" state to the "block ready" state.
|
private void |
expectState(HFileBlock.Writer.State expectedState) |
private void |
finishBlock()
Finish up writing of the block.
|
protected void |
finishBlockAndWriteHeaderAndData(DataOutputStream out)
Writes the header and the compressed data of this block (or uncompressed data when not using
compression) into the given stream.
|
(package private) HFileBlock |
getBlockForCaching(CacheConfig cacheConf)
Creates a new HFileBlock.
|
(package private) EncodingState |
getEncodingState() |
(package private) byte[] |
getHeaderAndDataForTest()
Returns the header or the compressed data (or uncompressed data when not using compression)
as a byte array.
|
(package private) int |
getOnDiskSizeWithHeader()
Returns the on-disk size of the block.
|
(package private) int |
getOnDiskSizeWithoutHeader()
Returns the on-disk size of the data portion of the block.
|
(package private) int |
getUncompressedSizeWithHeader()
The uncompressed size of the block data, including header size.
|
(package private) int |
getUncompressedSizeWithoutHeader()
The uncompressed size of the block data.
|
(package private) boolean |
isWriting()
Returns true if a block is being written
|
private void |
putHeader(byte[] dest,
int offset,
int onDiskSize,
int uncompressedSize,
int onDiskDataSize)
Put the header into the given byte array at the given offset.
|
private void |
putHeader(ByteArrayOutputStream dest,
int onDiskSize,
int uncompressedSize,
int onDiskDataSize) |
private void |
putHeader(ByteBuff buff,
int onDiskSize,
int uncompressedSize,
int onDiskDataSize) |
(package private) void |
release()
Releases resources used by this writer.
|
(package private) DataOutputStream |
startWriting(BlockType newBlockType)
Starts writing into the block.
|
(package private) void |
write(Cell cell)
Writes the Cell to this block
|
(package private) 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. |
(package private) 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. |
private HFileBlock.Writer.State state
private final HFileDataBlockEncoder dataBlockEncoder
private HFileBlockEncodingContext dataBlockEncodingCtx
private HFileBlockDefaultEncodingContext defaultBlockEncodingCtx
private ByteArrayOutputStream baosInMemory
HConstants.HFILEBLOCK_HEADER_SIZE
bytes into this stream.private BlockType blockType
startWriting(BlockType)
. Could be changed in
finishBlock()
from BlockType.DATA
to BlockType.ENCODED_DATA
.private DataOutputStream userDataStream
baosInMemory
.private ByteArrayOutputStream onDiskBlockBytesWithHeader
private byte[] onDiskChecksum
private long startOffset
HFile
. Set in
writeHeaderAndData(FSDataOutputStream)
.private long[] prevOffsetByType
private long prevOffset
private HFileContext fileContext
private final ByteBuffAllocator allocator
public Writer(org.apache.hadoop.conf.Configuration conf, HFileDataBlockEncoder dataBlockEncoder, HFileContext fileContext)
dataBlockEncoder
- data block encoding algorithm to usepublic Writer(org.apache.hadoop.conf.Configuration conf, HFileDataBlockEncoder dataBlockEncoder, HFileContext fileContext, ByteBuffAllocator allocator)
public void beforeShipped()
ShipperListener
Shipper.shipped()
is performed nbeforeShipped
in interface ShipperListener
EncodingState getEncodingState()
DataOutputStream startWriting(BlockType newBlockType) throws IOException
IOException
void write(Cell cell) throws IOException
IOException
void ensureBlockReady() throws IOException
IOException
private void finishBlock() throws IOException
IOException
private void putHeader(byte[] dest, int offset, int onDiskSize, int uncompressedSize, int onDiskDataSize)
onDiskSize
- size of the block on disk header + data + checksumuncompressedSize
- size of the block after decompression (but before optional data block
decoding) including headeronDiskDataSize
- size of the block on disk with header and data but not including the
checksumsprivate void putHeader(ByteBuff buff, int onDiskSize, int uncompressedSize, int onDiskDataSize)
private void putHeader(ByteArrayOutputStream dest, int onDiskSize, int uncompressedSize, int onDiskDataSize)
void writeHeaderAndData(org.apache.hadoop.fs.FSDataOutputStream out) throws IOException
writeHeaderAndData(FSDataOutputStream)
, but records the offset of this
block so that it can be referenced in the next block of the same type.IOException
protected void finishBlockAndWriteHeaderAndData(DataOutputStream out) throws IOException
out
- the output stream to write theIOException
byte[] getHeaderAndDataForTest() throws IOException
IOException
void release()
int getOnDiskSizeWithoutHeader()
int getOnDiskSizeWithHeader()
int getUncompressedSizeWithoutHeader()
int getUncompressedSizeWithHeader()
boolean isWriting()
public int encodedBlockSizeWritten()
int blockSizeWritten()
ByteBuff cloneUncompressedBufferWithHeader()
private ByteBuff cloneOnDiskBufferWithHeader()
private void expectState(HFileBlock.Writer.State expectedState)
void writeBlock(HFileBlock.BlockWritable bw, org.apache.hadoop.fs.FSDataOutputStream out) throws IOException
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.bw
- the block-writable object to write as a blockout
- the file system output streamIOException
HFileBlock getBlockForCaching(CacheConfig cacheConf)
TODO: Should there be an option where a cache can ask that hbase preserve block checksums for checking after a block comes out of the cache? Otehrwise, cache is responsible for blocks being wholesome (ECC memory or if file-backed, it does checksumming).
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.