Search in sources :

Example 11 with StorageContainerException

use of org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException in project ozone by apache.

the class KeyValueHandler method handleReadChunk.

/**
 * Handle Read Chunk operation. Calls ChunkManager to process the request.
 */
ContainerCommandResponseProto handleReadChunk(ContainerCommandRequestProto request, KeyValueContainer kvContainer, DispatcherContext dispatcherContext) {
    if (!request.hasReadChunk()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Malformed Read Chunk request. trace ID: {}", request.getTraceID());
        }
        return malformedRequest(request);
    }
    ChunkBuffer data;
    try {
        BlockID blockID = BlockID.getFromProtobuf(request.getReadChunk().getBlockID());
        ChunkInfo chunkInfo = ChunkInfo.getFromProtoBuf(request.getReadChunk().getChunkData());
        Preconditions.checkNotNull(chunkInfo);
        checkContainerIsHealthy(kvContainer, blockID, Type.ReadChunk);
        BlockUtils.verifyBCSId(kvContainer, blockID);
        if (dispatcherContext == null) {
            dispatcherContext = new DispatcherContext.Builder().build();
        }
        boolean isReadChunkV0 = getReadChunkVersion(request.getReadChunk()).equals(ContainerProtos.ReadChunkVersion.V0);
        if (isReadChunkV0) {
            // For older clients, set ReadDataIntoSingleBuffer to true so that
            // all the data read from chunk file is returned as a single
            // ByteString. Older clients cannot process data returned as a list
            // of ByteStrings.
            chunkInfo.setReadDataIntoSingleBuffer(true);
        }
        data = chunkManager.readChunk(kvContainer, blockID, chunkInfo, dispatcherContext);
        // For client reads, the client is expected to validate.
        if (dispatcherContext.isReadFromTmpFile()) {
            validateChunkChecksumData(data, chunkInfo);
        }
        metrics.incContainerBytesStats(Type.ReadChunk, chunkInfo.getLen());
    } catch (StorageContainerException ex) {
        return ContainerUtils.logAndReturnError(LOG, ex, request);
    } catch (IOException ex) {
        return ContainerUtils.logAndReturnError(LOG, new StorageContainerException("Read Chunk failed", ex, IO_EXCEPTION), request);
    }
    Preconditions.checkNotNull(data, "Chunk data is null");
    return getReadChunkResponse(request, data, byteBufferToByteString);
}
Also used : ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) BlockID(org.apache.hadoop.hdds.client.BlockID) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) IOException(java.io.IOException)

Example 12 with StorageContainerException

use of org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException in project ozone by apache.

the class KeyValueHandler method handleUpdateContainer.

/**
 * Handles Update Container Request. If successful, the container metadata
 * is updated.
 */
ContainerCommandResponseProto handleUpdateContainer(ContainerCommandRequestProto request, KeyValueContainer kvContainer) {
    if (!request.hasUpdateContainer()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Malformed Update Container request. trace ID: {}", request.getTraceID());
        }
        return malformedRequest(request);
    }
    boolean forceUpdate = request.getUpdateContainer().getForceUpdate();
    List<KeyValue> keyValueList = request.getUpdateContainer().getMetadataList();
    Map<String, String> metadata = new HashMap<>();
    for (KeyValue keyValue : keyValueList) {
        metadata.put(keyValue.getKey(), keyValue.getValue());
    }
    try {
        if (!metadata.isEmpty()) {
            kvContainer.update(metadata, forceUpdate);
        }
    } catch (StorageContainerException ex) {
        return ContainerUtils.logAndReturnError(LOG, ex, request);
    }
    return getSuccessResponse(request);
}
Also used : KeyValue(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.KeyValue) HashMap(java.util.HashMap) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)

Example 13 with StorageContainerException

use of org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException in project ozone by apache.

the class KeyValueHandler method closeContainer.

@Override
public void closeContainer(Container container) throws IOException {
    container.writeLock();
    try {
        final State state = container.getContainerState();
        // Close call is idempotent.
        if (state == State.CLOSED) {
            return;
        }
        if (state == State.UNHEALTHY) {
            throw new StorageContainerException("Cannot close container #" + container.getContainerData().getContainerID() + " while in " + state + " state.", ContainerProtos.Result.CONTAINER_UNHEALTHY);
        }
        // The container has to be either in CLOSING or in QUASI_CLOSED state.
        if (state != State.CLOSING && state != State.QUASI_CLOSED) {
            ContainerProtos.Result error = state == State.INVALID ? INVALID_CONTAINER_STATE : CONTAINER_INTERNAL_ERROR;
            throw new StorageContainerException("Cannot close container #" + container.getContainerData().getContainerID() + " while in " + state + " state.", error);
        }
        container.close();
        sendICR(container);
    } finally {
        container.writeUnlock();
    }
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) State(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)

Example 14 with StorageContainerException

use of org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException in project ozone by apache.

the class KeyValueHandler method handleGetBlock.

/**
 * Handle Get Block operation. Calls BlockManager to process the request.
 */
ContainerCommandResponseProto handleGetBlock(ContainerCommandRequestProto request, KeyValueContainer kvContainer) {
    if (!request.hasGetBlock()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Malformed Get Key request. trace ID: {}", request.getTraceID());
        }
        return malformedRequest(request);
    }
    ContainerProtos.BlockData responseData;
    try {
        BlockID blockID = BlockID.getFromProtobuf(request.getGetBlock().getBlockID());
        checkContainerIsHealthy(kvContainer, blockID, Type.GetBlock);
        responseData = blockManager.getBlock(kvContainer, blockID).getProtoBufMessage();
        final long numBytes = responseData.getSerializedSize();
        metrics.incContainerBytesStats(Type.GetBlock, numBytes);
    } catch (StorageContainerException ex) {
        return ContainerUtils.logAndReturnError(LOG, ex, request);
    } catch (IOException ex) {
        return ContainerUtils.logAndReturnError(LOG, new StorageContainerException("Get Key failed", ex, IO_EXCEPTION), request);
    }
    return getBlockDataResponse(request, responseData);
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) BlockID(org.apache.hadoop.hdds.client.BlockID) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) IOException(java.io.IOException)

Example 15 with StorageContainerException

use of org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException in project ozone by apache.

the class KeyValueHandler method checkContainerOpen.

/**
 * Check if container is open. Throw exception otherwise.
 * @param kvContainer
 * @throws StorageContainerException
 */
private void checkContainerOpen(KeyValueContainer kvContainer) throws StorageContainerException {
    final State containerState = kvContainer.getContainerState();
    /*
     * In a closing state, follower will receive transactions from leader.
     * Once the leader is put to closing state, it will reject further requests
     * from clients. Only the transactions which happened before the container
     * in the leader goes to closing state, will arrive here even the container
     * might already be in closing state here.
     */
    if (containerState == State.OPEN || containerState == State.CLOSING) {
        return;
    }
    final ContainerProtos.Result result;
    switch(containerState) {
        case QUASI_CLOSED:
            result = CLOSED_CONTAINER_IO;
            break;
        case CLOSED:
            result = CLOSED_CONTAINER_IO;
            break;
        case UNHEALTHY:
            result = CONTAINER_UNHEALTHY;
            break;
        case INVALID:
            result = INVALID_CONTAINER_STATE;
            break;
        default:
            result = CONTAINER_INTERNAL_ERROR;
    }
    String msg = "Requested operation not allowed as ContainerState is " + containerState;
    throw new StorageContainerException(msg, result);
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) State(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)

Aggregations

StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)55 IOException (java.io.IOException)23 BlockID (org.apache.hadoop.hdds.client.BlockID)16 Test (org.junit.Test)15 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)14 ChunkInfo (org.apache.hadoop.ozone.container.common.helpers.ChunkInfo)11 KeyValueContainer (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)11 File (java.io.File)10 KeyValueContainerData (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData)9 BlockData (org.apache.hadoop.ozone.container.common.helpers.BlockData)8 State (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State)5 Container (org.apache.hadoop.ozone.container.common.interfaces.Container)5 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)5 ChunkInfo (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo)4 ContainerCommandResponseProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto)4 WriteChunkRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.WriteChunkRequestProto)4 XceiverClientSpi (org.apache.hadoop.hdds.scm.XceiverClientSpi)4 ContainerNotOpenException (org.apache.hadoop.hdds.scm.container.common.helpers.ContainerNotOpenException)4 HddsVolume (org.apache.hadoop.ozone.container.common.volume.HddsVolume)4 ChunkManager (org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager)4