Class FanOutOneBlockAsyncDFSOutput
java.lang.Object
org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutput
- All Implemented Interfaces:
Closeable,AutoCloseable,AsyncFSOutput
An asynchronous HDFS output stream implementation which fans out data to datanode and only
supports writing file with only one block.
Use the createOutput method in FanOutOneBlockAsyncDFSOutputHelper to create. The main
usage of this class is implementing WAL, so we only expose a little HDFS configurations in the
method. And we place it here under io package because we want to make it independent of WAL
implementation thus easier to move it to HDFS project finally.
Note that, although we support pipelined flush, i.e, write new data and then flush before the previous flush succeeds, the implementation is not thread safe, so you should not call its methods concurrently.
Advantages compare to DFSOutputStream:
- The fan out mechanism. This will reduce the latency.
- Fail-fast when connection to datanode error. The WAL implementation could open new writer ASAP.
- We could benefit from netty's ByteBuf management mechanism.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classprivate static final classprivate static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate final org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocatorprivate final org.apache.hadoop.hdfs.protocol.ExtendedBlockprivate org.apache.hbase.thirdparty.io.netty.buffer.ByteBufprivate final org.apache.hadoop.hdfs.DFSClientprivate final Stringprivate final org.apache.hadoop.conf.Configurationprivate final Map<org.apache.hbase.thirdparty.io.netty.channel.Channel,org.apache.hadoop.hdfs.protocol.DatanodeInfo> private final org.apache.hadoop.hdfs.DistributedFileSystemprivate final org.apache.hadoop.crypto.Encryptorprivate final longprivate final org.apache.hadoop.hdfs.protocol.DatanodeInfo[]private static final intprivate final intprivate final org.apache.hadoop.hdfs.protocol.ClientProtocolprivate longprivate longprivate final SendBufSizePredictorprivate final Stringprivate final StreamSlowMonitorprivate final org.apache.hadoop.util.DataChecksumprivate intprivate final ConcurrentLinkedDeque<FanOutOneBlockAsyncDFSOutput.Callback> -
Constructor Summary
ConstructorsConstructorDescriptionFanOutOneBlockAsyncDFSOutput(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.hdfs.DistributedFileSystem dfs, org.apache.hadoop.hdfs.DFSClient client, org.apache.hadoop.hdfs.protocol.ClientProtocol namenode, String clientName, String src, long fileId, org.apache.hadoop.hdfs.protocol.LocatedBlock locatedBlock, org.apache.hadoop.crypto.Encryptor encryptor, Map<org.apache.hbase.thirdparty.io.netty.channel.Channel, org.apache.hadoop.hdfs.protocol.DatanodeInfo> datanodeInfoMap, org.apache.hadoop.util.DataChecksum summer, org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocator alloc, StreamSlowMonitor streamSlowMonitor) -
Method Summary
Modifier and TypeMethodDescriptionintbuffered()Return the current size of buffered data.voidclose()End the current block and complete file at namenode.private voidprivate voidcompleted(org.apache.hbase.thirdparty.io.netty.channel.Channel channel) private voidendBlock()private voidfailed(org.apache.hbase.thirdparty.io.netty.channel.Channel channel, Supplier<Throwable> errorSupplier) private voidfailWaitingAckQueue(org.apache.hbase.thirdparty.io.netty.channel.Channel channel, Supplier<Throwable> errorSupplier) flush(boolean syncBlock) Flush the buffer out to datanodes.private voidflush0(CompletableFuture<Long> future, boolean syncBlock) private voidflushBuffer(CompletableFuture<Long> future, org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf dataBuf, long nextPacketOffsetInBlock, boolean syncBlock) (package private) Map<org.apache.hbase.thirdparty.io.netty.channel.Channel,org.apache.hadoop.hdfs.protocol.DatanodeInfo> org.apache.hadoop.hdfs.protocol.DatanodeInfo[]Return current pipeline.longReturns byteSize success synced to underlying filesystem.booleanisBroken()Whether the stream is broken.voidrecoverAndClose(CancelableProgressable reporter) The close method when error occurred.private voidsetupReceiver(int timeoutMs) voidwrite(byte[] b) Just call write(b, 0, b.length).voidwrite(byte[] b, int off, int len) Copy the data into the buffer.voidwrite(ByteBuffer bb) Copy the data in the givenbbinto the buffer.voidwriteInt(int i) Write an int to the buffer.
-
Field Details
-
MAX_DATA_LEN
- See Also:
-
conf
-
dfs
-
client
-
namenode
-
clientName
-
src
-
fileId
-
block
-
locations
-
encryptor
-
datanodeInfoMap
private final Map<org.apache.hbase.thirdparty.io.netty.channel.Channel,org.apache.hadoop.hdfs.protocol.DatanodeInfo> datanodeInfoMap -
summer
-
maxDataLen
-
alloc
-
waitingAckQueue
-
ackedBlockLength
-
nextPacketOffsetInBlock
-
trailingPartialChunkLength
-
nextPacketSeqno
-
buf
-
sendBufSizePRedictor
-
state
-
streamSlowMonitor
-
-
Constructor Details
-
FanOutOneBlockAsyncDFSOutput
FanOutOneBlockAsyncDFSOutput(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.hdfs.DistributedFileSystem dfs, org.apache.hadoop.hdfs.DFSClient client, org.apache.hadoop.hdfs.protocol.ClientProtocol namenode, String clientName, String src, long fileId, org.apache.hadoop.hdfs.protocol.LocatedBlock locatedBlock, org.apache.hadoop.crypto.Encryptor encryptor, Map<org.apache.hbase.thirdparty.io.netty.channel.Channel, org.apache.hadoop.hdfs.protocol.DatanodeInfo> datanodeInfoMap, org.apache.hadoop.util.DataChecksum summer, org.apache.hbase.thirdparty.io.netty.buffer.ByteBufAllocator alloc, StreamSlowMonitor streamSlowMonitor)
-
-
Method Details
-
completed
-
failed
-
failWaitingAckQueue
private void failWaitingAckQueue(org.apache.hbase.thirdparty.io.netty.channel.Channel channel, Supplier<Throwable> errorSupplier) -
setupReceiver
-
writeInt
Description copied from interface:AsyncFSOutputWrite an int to the buffer.- Specified by:
writeIntin interfaceAsyncFSOutput
-
write
Description copied from interface:AsyncFSOutputCopy the data in the givenbbinto the buffer.- Specified by:
writein interfaceAsyncFSOutput
-
write
Description copied from interface:AsyncFSOutputJust call write(b, 0, b.length).- Specified by:
writein interfaceAsyncFSOutput- See Also:
-
write
Description copied from interface:AsyncFSOutputCopy the data into the buffer. Note that you need to callAsyncFSOutput.flush(boolean)to flush the buffer manually.- Specified by:
writein interfaceAsyncFSOutput
-
buffered
Description copied from interface:AsyncFSOutputReturn the current size of buffered data.- Specified by:
bufferedin interfaceAsyncFSOutput
-
getPipeline
Description copied from interface:AsyncFSOutputReturn current pipeline. Empty array if no pipeline.- Specified by:
getPipelinein interfaceAsyncFSOutput
-
flushBuffer
private void flushBuffer(CompletableFuture<Long> future, org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf dataBuf, long nextPacketOffsetInBlock, boolean syncBlock) -
flush0
-
flush
Flush the buffer out to datanodes.- Specified by:
flushin interfaceAsyncFSOutput- Parameters:
syncBlock- will call hsync if true, otherwise hflush.- Returns:
- A CompletableFuture that hold the acked length after flushing.
-
endBlock
- Throws:
IOException
-
closeDataNodeChannelsAndAwait
-
recoverAndClose
The close method when error occurred. Now we just call recoverFileLease.- Specified by:
recoverAndClosein interfaceAsyncFSOutput- Throws:
IOException
-
close
End the current block and complete file at namenode. You should callrecoverAndClose(CancelableProgressable)if this method throws an exception.- Specified by:
closein interfaceAsyncFSOutput- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isBroken
Description copied from interface:AsyncFSOutputWhether the stream is broken.- Specified by:
isBrokenin interfaceAsyncFSOutput
-
getSyncedLength
Description copied from interface:AsyncFSOutputReturns byteSize success synced to underlying filesystem.- Specified by:
getSyncedLengthin interfaceAsyncFSOutput
-
getDatanodeInfoMap
Map<org.apache.hbase.thirdparty.io.netty.channel.Channel,org.apache.hadoop.hdfs.protocol.DatanodeInfo> getDatanodeInfoMap()
-