Search in sources :

Example 1 with ReadChunkRequestProto

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;
}
Also used : WriteChunkRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.WriteChunkRequestProto) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) ReadChunkResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ReadChunkRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkRequestProto) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)1 ContainerCommandRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto)1 ContainerCommandResponseProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto)1 ReadChunkRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkRequestProto)1 ReadChunkResponseProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto)1 WriteChunkRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.WriteChunkRequestProto)1 StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)1 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)1