use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto in project ozone by apache.
the class ContainerStateMachine method readStateMachineData.
private ByteString readStateMachineData(ContainerCommandRequestProto requestProto, long term, long index) throws IOException {
// the stateMachine data is not present in the stateMachine cache,
// increment the stateMachine cache miss count
metrics.incNumReadStateMachineMissCount();
WriteChunkRequestProto writeChunkRequestProto = requestProto.getWriteChunk();
ContainerProtos.ChunkInfo chunkInfo = writeChunkRequestProto.getChunkData();
// prepare the chunk to be read
ReadChunkRequestProto.Builder readChunkRequestProto = ReadChunkRequestProto.newBuilder().setBlockID(writeChunkRequestProto.getBlockID()).setChunkData(chunkInfo).setReadChunkVersion(ContainerProtos.ReadChunkVersion.V1);
ContainerCommandRequestProto dataContainerCommandProto = ContainerCommandRequestProto.newBuilder(requestProto).setCmdType(Type.ReadChunk).setReadChunk(readChunkRequestProto).build();
DispatcherContext context = new DispatcherContext.Builder().setTerm(term).setLogIndex(index).setReadFromTmpFile(true).build();
// read the chunk
ContainerCommandResponseProto response = dispatchCommand(dataContainerCommandProto, context);
if (response.getResult() != ContainerProtos.Result.SUCCESS) {
StorageContainerException sce = new StorageContainerException(response.getMessage(), response.getResult());
LOG.error("gid {} : ReadStateMachine failed. cmd {} logIndex {} msg : " + "{} Container Result: {}", gid, response.getCmdType(), index, response.getMessage(), response.getResult());
stateMachineHealthy.set(false);
throw sce;
}
ReadChunkResponseProto responseProto = response.getReadChunk();
ByteString data;
if (responseProto.hasData()) {
data = responseProto.getData();
} else {
data = BufferUtils.concatByteStrings(responseProto.getDataBuffers().getBuffersList());
}
// assert that the response has data in it.
Preconditions.checkNotNull(data, "read chunk data is null for chunk: %s", chunkInfo);
Preconditions.checkState(data.size() == chunkInfo.getLen(), "read chunk len=%s does not match chunk expected len=%s for chunk:%s", data.size(), chunkInfo.getLen(), chunkInfo);
return data;
}
use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto in project ozone by apache.
the class ChunkInputStream method readChunk.
/**
* Send RPC call to get the chunk from the container.
*/
@VisibleForTesting
protected ByteBuffer[] readChunk(ChunkInfo readChunkInfo) throws IOException {
ReadChunkResponseProto readChunkResponse;
try {
List<CheckedBiFunction> validators = ContainerProtocolCalls.getValidatorList();
validators.add(validator);
readChunkResponse = ContainerProtocolCalls.readChunk(xceiverClient, readChunkInfo, blockID, validators, token);
} catch (IOException e) {
if (e instanceof StorageContainerException) {
throw e;
}
throw new IOException("Unexpected OzoneException: " + e.toString(), e);
}
if (readChunkResponse.hasData()) {
return readChunkResponse.getData().asReadOnlyByteBufferList().toArray(new ByteBuffer[0]);
} else if (readChunkResponse.hasDataBuffers()) {
List<ByteString> buffersList = readChunkResponse.getDataBuffers().getBuffersList();
return BufferUtils.getReadOnlyByteBuffersArray(buffersList);
} else {
throw new IOException("Unexpected error while reading chunk data " + "from container. No data returned.");
}
}
Aggregations