use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkRequestProto 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;
}
Aggregations