@NotThreadSafe public class BlockReadHandler extends Object implements io.grpc.stub.StreamObserver<ReadRequest>
BlockReadRequest
s.
Protocol: Check GrpcDataReader
for additional information.
1. Once a read request is received, the handler creates a DataReader
which reads
chunks of data from the block worker and pushes them to the buffer.
2. The DataReader
pauses if there are too many packets in flight, and resumes if there
is room available.
3. The channel is closed if there is any exception during the data read/write.
Threading model:
Only two threads are involved at a given point of time: gRPC event thread, data reader thread.
1. The gRPC event thread accepts the read request, handles write callbacks. If any exception
occurs (e.g. failed to read from stream or respond to stream) or the read request is cancelled
by the client, the gRPC event thread notifies the data reader thread.
2. The data reader thread keeps reading from the file and writes to buffer. Before reading a
new data chunk, it checks whether there are notifications (e.g. cancel, error), if
there is, handle them properly. See more information about the notifications in the javadoc
of BlockReadRequestContext
about CANCEL, EOF, and ERROR flags.BlockReadRequestContext
Modifier and Type | Method and Description |
---|---|
protected BlockReadRequestContext |
createRequestContext(ReadRequest request) |
void |
onCompleted() |
void |
onError(Throwable cause) |
void |
onNext(ReadRequest request) |
void |
onReady()
Ready to restart data reader.
|
boolean |
tooManyPendingChunks() |
public void onNext(ReadRequest request)
onNext
in interface io.grpc.stub.StreamObserver<ReadRequest>
public boolean tooManyPendingChunks()
public void onError(Throwable cause)
onError
in interface io.grpc.stub.StreamObserver<ReadRequest>
public void onCompleted()
onCompleted
in interface io.grpc.stub.StreamObserver<ReadRequest>
protected BlockReadRequestContext createRequestContext(ReadRequest request)
request
- the block read requestpublic void onReady()
Copyright © 2023. All Rights Reserved.