public static class HFileBlockIndex.BlockIndexWriter extends Object implements InlineBlockWriter
Modifier and Type | Field and Description |
---|---|
private HFileBlock.Writer |
blockWriter |
private CacheConfig |
cacheConf
CacheConfig, or null if cache-on-write is disabled
|
private HFileBlockIndex.BlockIndexChunk |
curInlineChunk
Current leaf-level chunk.
|
private byte[] |
firstKey |
private int |
maxChunkSize
The maximum size guideline of all multi-level index blocks.
|
private int |
minIndexNumEntries
The maximum level of multi-level index blocks
|
private String |
nameForCaching
Name to use for computing cache keys
|
private int |
numLevels
The number of block index levels.
|
private HFileBlockIndex.BlockIndexChunk |
rootChunk
While the index is being written, this represents the current block
index referencing all leaf blocks, with one exception.
|
private boolean |
singleLevelOnly
Whether we require this block index to always be single-level.
|
private long |
totalBlockOnDiskSize
Total compressed size of all index blocks.
|
private long |
totalBlockUncompressedSize
Total uncompressed size of all index blocks.
|
private long |
totalNumEntries
The total number of leaf-level entries, i.e.
|
Constructor and Description |
---|
HFileBlockIndex.BlockIndexWriter()
Creates a single-level block index writer
|
HFileBlockIndex.BlockIndexWriter(HFileBlock.Writer blockWriter,
CacheConfig cacheConf,
String nameForCaching)
Creates a multi-level block index writer.
|
Modifier and Type | Method and Description |
---|---|
void |
addEntry(byte[] firstKey,
long blockOffset,
int blockDataSize)
Add one index entry to the current leaf-level block.
|
void |
blockWritten(long offset,
int onDiskSize,
int uncompressedSize)
Called after an inline block has been written so that we can add an
entry referring to that block to the parent-level index.
|
void |
ensureSingleLevel() |
private void |
expectNumLevels(int expectedNumLevels) |
boolean |
getCacheOnWrite() |
BlockType |
getInlineBlockType()
The type of blocks this block writer produces.
|
int |
getNumLevels() |
int |
getNumRootEntries() |
long |
getTotalUncompressedSize()
The total uncompressed size of the root index block, intermediate-level
index blocks, and leaf-level index blocks.
|
void |
setMaxChunkSize(int maxChunkSize) |
void |
setMinIndexNumEntries(int minIndexNumEntries) |
boolean |
shouldWriteBlock(boolean closing)
Whether there is an inline block ready to be written.
|
long |
writeIndexBlocks(org.apache.hadoop.fs.FSDataOutputStream out)
Writes the root level and intermediate levels of the block index into
the output stream, generating the tree from bottom up.
|
void |
writeInlineBlock(DataOutput out)
Write out the current inline index block.
|
private void |
writeIntermediateBlock(org.apache.hadoop.fs.FSDataOutputStream out,
HFileBlockIndex.BlockIndexChunk parent,
HFileBlockIndex.BlockIndexChunk curChunk) |
private HFileBlockIndex.BlockIndexChunk |
writeIntermediateLevel(org.apache.hadoop.fs.FSDataOutputStream out,
HFileBlockIndex.BlockIndexChunk currentLevel)
Split the current level of the block index into intermediate index
blocks of permitted size and write those blocks to disk.
|
void |
writeSingleLevelIndex(DataOutput out,
String description)
Writes the block index data as a single level only.
|
private HFileBlockIndex.BlockIndexChunk rootChunk
writeIndexBlocks(FSDataOutputStream)
, this contains the final
root-level index.private HFileBlockIndex.BlockIndexChunk curInlineChunk
private int numLevels
writeIndexBlocks(FSDataOutputStream)
has been called. The
initial value accounts for the root level, and will be increased to two
as soon as we find out there is a leaf-level in
blockWritten(long, int, int)
.private HFileBlock.Writer blockWriter
private byte[] firstKey
private long totalNumEntries
private long totalBlockOnDiskSize
private long totalBlockUncompressedSize
private int maxChunkSize
private int minIndexNumEntries
private boolean singleLevelOnly
private CacheConfig cacheConf
private String nameForCaching
public HFileBlockIndex.BlockIndexWriter()
public HFileBlockIndex.BlockIndexWriter(HFileBlock.Writer blockWriter, CacheConfig cacheConf, String nameForCaching)
blockWriter
- the block writer to use to write index blockscacheConf
- used to determine when and how a block should be cached-on-write.public void setMaxChunkSize(int maxChunkSize)
public void setMinIndexNumEntries(int minIndexNumEntries)
public long writeIndexBlocks(org.apache.hadoop.fs.FSDataOutputStream out) throws IOException
out
- FSDataOutputStreamIOException
public void writeSingleLevelIndex(DataOutput out, String description) throws IOException
out
- the buffered output stream to write the index to. Typically a
stream writing into an HFile
block.description
- a short description of the index being written. Used
in a log message.IOException
private HFileBlockIndex.BlockIndexChunk writeIntermediateLevel(org.apache.hadoop.fs.FSDataOutputStream out, HFileBlockIndex.BlockIndexChunk currentLevel) throws IOException
out
- currentLevel
- the current level of the block index, such as the a
chunk referencing all leaf-level index blocksIOException
private void writeIntermediateBlock(org.apache.hadoop.fs.FSDataOutputStream out, HFileBlockIndex.BlockIndexChunk parent, HFileBlockIndex.BlockIndexChunk curChunk) throws IOException
IOException
public final int getNumRootEntries()
public int getNumLevels()
private void expectNumLevels(int expectedNumLevels)
public boolean shouldWriteBlock(boolean closing)
shouldWriteBlock
in interface InlineBlockWriter
closing
- whether the file is being closed, in which case we need to write
out all available data and not wait to accumulate another blockpublic void writeInlineBlock(DataOutput out) throws IOException
writeInlineBlock
in interface InlineBlockWriter
out
- IOException
public void blockWritten(long offset, int onDiskSize, int uncompressedSize)
blockWritten
in interface InlineBlockWriter
offset
- the offset of the block in the streamonDiskSize
- the on-disk size of the blockuncompressedSize
- the uncompressed size of the blockpublic BlockType getInlineBlockType()
InlineBlockWriter
getInlineBlockType
in interface InlineBlockWriter
public void addEntry(byte[] firstKey, long blockOffset, int blockDataSize)
public void ensureSingleLevel() throws IOException
IOException
- if we happened to write a multi-level index.public boolean getCacheOnWrite()
getCacheOnWrite
in interface InlineBlockWriter
public long getTotalUncompressedSize()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.