@NotThreadSafe public class NettyDataWriter extends Object implements DataWriter
Protocol: 1. The client streams packets (start from pos 0) to the server. The client pauses if the client buffer is full, resumes if the buffer is not full. 2. The server reads packets from the channel and writes them to the block worker. See the server side implementation for details. 3. The client can either send an EOF packet or a CANCEL packet to end the write request. The client has to wait for the response from the data server for the EOF or CANCEL packet to make sure that the server has cleaned its states. 4. To make it simple to handle errors, the channel is closed if any error occurs.
NOTE: this class is NOT threadsafe. Do not call cancel/close while some other threads are writing.
DataWriter.Factory
Modifier and Type | Field and Description |
---|---|
protected Protocol.WriteRequest |
mPartialRequest |
Modifier | Constructor and Description |
---|---|
protected |
NettyDataWriter(FileSystemContext context,
WorkerNetAddress address,
long length,
long packetSize,
RequestType type,
OutStreamOptions options,
io.netty.channel.Channel channel)
Creates an instance of
NettyDataWriter . |
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels an operation.
|
int |
chunkSize() |
void |
close() |
static NettyDataWriter |
create(FileSystemContext context,
WorkerNetAddress address,
long length,
RequestType type,
OutStreamOptions options) |
void |
flush()
Flushes all the pending chunks.
|
Throwable |
getPacketWriteException()
Get the exception object that created during packet writing.
|
protected Protocol.RequestType |
getRequestType(RequestType requestType) |
Optional<String> |
getUfsContentHash() |
long |
pos() |
void |
writeChunk(byte[] bytes,
int off,
int len)
Write chunk by sending a write request.
|
void |
writeChunk(io.netty.buffer.ByteBuf buf)
Writes a chunk.
|
protected Protocol.WriteRequest mPartialRequest
protected NettyDataWriter(FileSystemContext context, WorkerNetAddress address, long length, long packetSize, RequestType type, OutStreamOptions options, io.netty.channel.Channel channel)
NettyDataWriter
.context
- the file system contextaddress
- the data server addresslength
- the length of the file to write, set to Long.MAX_VALUE if unknownpacketSize
- the packet sizetype
- type of the write requestoptions
- details of the write request which are constant for all requestschannel
- netty channelpublic static NettyDataWriter create(FileSystemContext context, WorkerNetAddress address, long length, RequestType type, OutStreamOptions options) throws IOException
context
- the file system contextaddress
- the data server addresslength
- the length of the block or file to write, set to Long.MAX_VALUE if unknowntype
- type of the write requestoptions
- the options of the output streamNettyDataWriter
IOException
protected Protocol.RequestType getRequestType(RequestType requestType)
public long pos()
pos
in interface DataWriter
public Optional<String> getUfsContentHash()
getUfsContentHash
in interface DataWriter
public void writeChunk(byte[] bytes, int off, int len) throws IOException
bytes
- the bytes to be writtenoff
- the offset of the given byte arraylen
- the length to be writtenIOException
public void writeChunk(io.netty.buffer.ByteBuf buf) throws IOException
DataWriter
writeChunk
in interface DataWriter
buf
- the chunkIOException
public void cancel()
Cancelable
cancel
in interface Cancelable
public void flush() throws IOException
DataWriter
flush
in interface DataWriter
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public int chunkSize()
chunkSize
in interface DataWriter
public Throwable getPacketWriteException()
Copyright © 2023. All Rights Reserved.