Search in sources :

Example 1 with ReadChunkResponseProto

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;
}
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)

Example 2 with ReadChunkResponseProto

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.");
    }
}
Also used : ReadChunkResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ReadChunkResponseProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadChunkResponseProto)2 StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)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 WriteChunkRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.WriteChunkRequestProto)1 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)1