@NotThreadSafe public final 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 | Method and Description |
---|---|
void |
cancel()
Cancels an operation.
|
int |
chunkSize() |
void |
close() |
static NettyDataWriter |
create(FileSystemContext context,
WorkerNetAddress address,
long id,
long length,
RequestType type,
OutStreamOptions options) |
void |
flush()
Flushes all the pending chunks.
|
Optional<String> |
getUfsContentHash() |
long |
pos() |
void |
writeChunk(io.netty.buffer.ByteBuf buf)
Writes a chunk.
|
public static NettyDataWriter create(FileSystemContext context, WorkerNetAddress address, long id, long length, RequestType type, OutStreamOptions options) throws IOException
context
- the file system contextaddress
- the data server addressid
- the block or UFS IDlength
- 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
public long pos()
pos
in interface DataWriter
public Optional<String> getUfsContentHash()
getUfsContentHash
in interface DataWriter
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
Copyright © 2023. All Rights Reserved.