Search in sources :

Example 11 with ServerErrorCode

use of com.github.ambry.commons.ServerErrorCode in project ambry by linkedin.

the class AmbryRequests method handleBlobStoreControlRequest.

/**
 * Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#BlobStoreControl}.
 * @param requestStream the serialized bytes of the request.
 * @param adminRequest the {@link AdminRequest} received.
 * @return the {@link AdminResponse} to the request.
 * @throws IOException if there is any I/O error reading from the {@code requestStream}.
 */
private AdminResponse handleBlobStoreControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
    ServerErrorCode error;
    BlobStoreControlAdminRequest blobStoreControlAdminRequest = BlobStoreControlAdminRequest.readFrom(requestStream, adminRequest);
    if (blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition() > 0) {
        PartitionId partitionId = blobStoreControlAdminRequest.getPartitionId();
        if (partitionId != null) {
            error = validateRequest(partitionId, RequestOrResponseType.AdminRequest);
            if (error.equals(ServerErrorCode.No_Error)) {
                if (blobStoreControlAdminRequest.shouldEnable()) {
                    // TODO: start BlobStore properly
                    error = ServerErrorCode.Temporarily_Disabled;
                } else {
                    Collection<PartitionId> partitionIds = Collections.singletonList(partitionId);
                    if (storageManager.disableCompactionForBlobStore(partitionId)) {
                        controlRequestForPartitions(RequestOrResponseType.PutRequest, partitionIds, false);
                        controlRequestForPartitions(RequestOrResponseType.DeleteRequest, partitionIds, false);
                        if (replicationManager.controlReplicationForPartitions(partitionIds, Collections.<String>emptyList(), false)) {
                            if (isRemoteLagLesserOrEqual(partitionIds, 0, blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition())) {
                                controlRequestForPartitions(RequestOrResponseType.GetRequest, partitionIds, false);
                                controlRequestForPartitions(RequestOrResponseType.ReplicaMetadataRequest, partitionIds, false);
                                // Shutdown the BlobStore completely
                                if (storageManager.shutdownBlobStore(partitionId)) {
                                    error = ServerErrorCode.No_Error;
                                    logger.info("store shutdown for partition: {}", partitionId);
                                } else {
                                    error = ServerErrorCode.Unknown_Error;
                                    logger.error("Shutting down BlobStore fails on {}", partitionId);
                                }
                            } else {
                                error = ServerErrorCode.Retry_After_Backoff;
                                logger.debug("Catchup not done on {}", partitionIds);
                            }
                        } else {
                            error = ServerErrorCode.Unknown_Error;
                            logger.error("Could not disable replication on {}", partitionIds);
                        }
                    } else {
                        error = ServerErrorCode.Unknown_Error;
                        logger.error("Disable compaction on given BlobStore failed for {}", partitionId);
                    }
                }
            } else {
                logger.debug("Validate request fails for {} with error code {}", partitionId, error);
            }
        } else {
            error = ServerErrorCode.Partition_Unknown;
            logger.debug("The partition Id should not be null.");
        }
    } else {
        error = ServerErrorCode.Bad_Request;
        logger.debug("The number of replicas to catch up should not be less or equal to zero {}", blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition());
    }
    return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId) ServerErrorCode(com.github.ambry.commons.ServerErrorCode)

Aggregations

ServerErrorCode (com.github.ambry.commons.ServerErrorCode)11 PartitionId (com.github.ambry.clustermap.PartitionId)6 DataInputStream (java.io.DataInputStream)5 ArrayList (java.util.ArrayList)5 MessageFormatException (com.github.ambry.messageformat.MessageFormatException)4 AdminResponse (com.github.ambry.protocol.AdminResponse)4 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)4 Store (com.github.ambry.store.Store)4 StoreException (com.github.ambry.store.StoreException)4 IOException (java.io.IOException)4 DeleteMessageFormatInputStream (com.github.ambry.messageformat.DeleteMessageFormatInputStream)2 MessageFormatInputStream (com.github.ambry.messageformat.MessageFormatInputStream)2 MessageFormatWriteSet (com.github.ambry.messageformat.MessageFormatWriteSet)2 PutMessageFormatInputStream (com.github.ambry.messageformat.PutMessageFormatInputStream)2 ServerNetworkResponseMetrics (com.github.ambry.network.ServerNetworkResponseMetrics)2 GetResponse (com.github.ambry.protocol.GetResponse)2 FindToken (com.github.ambry.store.FindToken)2 MessageInfo (com.github.ambry.store.MessageInfo)2 Histogram (com.codahale.metrics.Histogram)1 ReplicaId (com.github.ambry.clustermap.ReplicaId)1