@InterfaceAudience.Private public class FanOutOneBlockAsyncDFSOutput extends Object implements AsyncFSOutput
Use the createOutput method in FanOutOneBlockAsyncDFSOutputHelper
to create. The mainly
usage of this class is implementing WAL, so we only expose a little HDFS configurations in the
method. And we place it here under util package because we want to make it independent of WAL
implementation thus easier to move it to HDFS project finally.
Note that, all connections to datanode will run in the same EventLoop
which means we only
need one thread here. But be careful, we do some blocking operations in close()
and
recoverAndClose(CancelableProgressable)
methods, so do not call them inside
EventLoop
. And for write(byte[])
write(byte[], int, int)
,
buffered()
and flush(boolean)
, if you call them outside EventLoop
,
there will be an extra context-switch.
Advantages compare to DFSOutputStream:
Modifier and Type | Method and Description |
---|---|
int |
buffered()
Return the current size of buffered data.
|
void |
close()
End the current block and complete file at namenode.
|
CompletableFuture<Long> |
flush(boolean syncBlock)
Flush the buffer out to datanodes.
|
org.apache.hadoop.hdfs.protocol.DatanodeInfo[] |
getPipeline()
Return current pipeline.
|
void |
recoverAndClose(CancelableProgressable reporter)
The close method when error occurred.
|
void |
write(byte[] b)
Just call write(b, 0, b.length).
|
void |
write(byte[] b,
int off,
int len)
Copy the data into the buffer.
|
void |
write(ByteBuffer bb)
Copy the data in the given
bb into the buffer. |
void |
writeInt(int i)
Write an int to the buffer.
|
public void writeInt(int i)
AsyncFSOutput
writeInt
in interface AsyncFSOutput
public void write(ByteBuffer bb)
AsyncFSOutput
bb
into the buffer.write
in interface AsyncFSOutput
public void write(byte[] b)
AsyncFSOutput
write
in interface AsyncFSOutput
AsyncFSOutput.write(byte[], int, int)
public void write(byte[] b, int off, int len)
AsyncFSOutput
AsyncFSOutput.flush(boolean)
to flush the
buffer manually.write
in interface AsyncFSOutput
public int buffered()
AsyncFSOutput
buffered
in interface AsyncFSOutput
public org.apache.hadoop.hdfs.protocol.DatanodeInfo[] getPipeline()
AsyncFSOutput
getPipeline
in interface AsyncFSOutput
public CompletableFuture<Long> flush(boolean syncBlock)
flush
in interface AsyncFSOutput
syncBlock
- will call hsync if true, otherwise hflush.public void recoverAndClose(CancelableProgressable reporter) throws IOException
recoverAndClose
in interface AsyncFSOutput
IOException
public void close() throws IOException
recoverAndClose(CancelableProgressable)
if this method throws an exception.close
in interface Closeable
close
in interface AutoCloseable
close
in interface AsyncFSOutput
IOException
Copyright © 2007–2017 The Apache Software Foundation. All rights reserved.