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