use of alluxio.grpc.ReadResponse in project alluxio by Alluxio.
the class BufferCachingGrpcDataReader method readChunk.
/**
* Reads a chunk of data.
*
* @return a chunk of data
*/
@Nullable
@VisibleForTesting
protected DataBuffer readChunk() throws IOException {
Preconditions.checkState(!mClient.get().isShutdown(), "Data reader is closed while reading data chunks.");
DataBuffer buffer = null;
ReadResponse response = null;
response = mStream.receive(mDataTimeoutMs);
if (response == null) {
return null;
}
Preconditions.checkState(response.hasChunk() && response.getChunk().hasData(), "response should always contain chunk");
ByteBuffer byteBuffer = response.getChunk().getData().asReadOnlyByteBuffer();
buffer = new NioDataBuffer(byteBuffer, byteBuffer.remaining());
mPosToRead += buffer.readableBytes();
try {
mStream.send(mReadRequest.toBuilder().setOffsetReceived(mPosToRead).build());
} catch (Exception e) {
// nothing is done as the receipt is sent at best effort
LOG.debug("Failed to send receipt of data to worker {} for request {}", mAddress, mReadRequest, e);
}
Preconditions.checkState(mPosToRead - mReadRequest.getOffset() <= mReadRequest.getLength());
return buffer;
}
use of alluxio.grpc.ReadResponse in project alluxio by Alluxio.
the class BlockReadHandlerTest method checkAllReadResponses.
/**
* Checks all the read responses.
*/
private void checkAllReadResponses(List<ReadResponse> responses, long checksumExpected) throws Exception {
long checksumActual = 0;
CommonUtils.waitFor("response", () -> mResponseCompleted || mError != null, WaitForOptions.defaults().setTimeoutMs(Constants.MINUTE_MS));
for (ReadResponse readResponse : responses) {
if (readResponse == null) {
Assert.fail();
break;
}
assertTrue(readResponse.hasChunk());
assertTrue(readResponse.getChunk().hasData());
ByteString buffer = readResponse.getChunk().getData();
if (buffer != null) {
for (byte b : buffer) {
checksumActual += BufferUtils.byteToInt(b);
}
}
}
assertEquals(checksumExpected, checksumActual);
}
Aggregations