Search in sources :

Example 11 with AdminResponse

use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.

the class AmbryServerRequests method handleRequestControlRequest.

/**
 * Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#RequestControl}.
 * @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 handleRequestControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
    RequestControlAdminRequest controlRequest = RequestControlAdminRequest.readFrom(requestStream, adminRequest);
    RequestOrResponseType toControl = controlRequest.getRequestTypeToControl();
    ServerErrorCode error;
    Collection<PartitionId> partitionIds;
    if (!requestsDisableInfo.containsKey(toControl)) {
        metrics.badRequestError.inc();
        error = ServerErrorCode.Bad_Request;
    } else {
        error = ServerErrorCode.No_Error;
        if (controlRequest.getPartitionId() != null) {
            error = validateRequest(controlRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
            partitionIds = Collections.singletonList(controlRequest.getPartitionId());
        } else {
            partitionIds = storeManager.getLocalPartitions();
        }
        if (!error.equals(ServerErrorCode.Partition_Unknown)) {
            controlRequestForPartitions(EnumSet.of(toControl), partitionIds, controlRequest.shouldEnable());
            for (PartitionId partitionId : partitionIds) {
                logger.info("Enable state for {} on {} is {}", toControl, partitionId, isRequestEnabled(toControl, partitionId));
            }
        }
    }
    return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
Also used : AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) RequestOrResponseType(com.github.ambry.protocol.RequestOrResponseType) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 12 with AdminResponse

use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.

the class AmbryServerRequests method handleReplicationControlRequest.

/**
 * Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#ReplicationControl}.
 * @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 handleReplicationControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
    Collection<PartitionId> partitionIds;
    ServerErrorCode error = ServerErrorCode.No_Error;
    ReplicationControlAdminRequest replControlRequest = ReplicationControlAdminRequest.readFrom(requestStream, adminRequest);
    if (replControlRequest.getPartitionId() != null) {
        error = validateRequest(replControlRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
        partitionIds = Collections.singletonList(replControlRequest.getPartitionId());
    } else {
        partitionIds = storeManager.getLocalPartitions();
    }
    if (!error.equals(ServerErrorCode.Partition_Unknown)) {
        if (replicationEngine.controlReplicationForPartitions(partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable())) {
            error = ServerErrorCode.No_Error;
        } else {
            logger.error("Could not set enable status for replication of {} from {} to {}. Check partition validity and" + " origins list", partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable());
            error = ServerErrorCode.Bad_Request;
        }
    }
    return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
Also used : AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 13 with AdminResponse

use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.

the class AmbryServerRequestsTest method doCatchupStatusTest.

// catchupStatusSuccessTest() and catchupStatusFailureTest() helpers
/**
 * Does the test for {@link AdminRequestOrResponseType#CatchupStatus} by checking that the request is correctly
 * deserialized in {@link AmbryRequests} and the necessary info obtained from {@link ReplicationManager}.
 * @param id the {@link PartitionId} to disable replication on. Can be {@code null}.
 * @param acceptableLagInBytes the value of acceptable lag to set in the {@link CatchupStatusAdminRequest}.
 * @param numReplicasCaughtUpPerPartition the value of num replicas caught up per partition to set in the
 *                          {@link CatchupStatusAdminRequest}.
 * @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
 * @param expectedIsCaughtUp the expected return from {@link CatchupStatusAdminResponse#isCaughtUp()}.
 * @throws InterruptedException
 * @throws IOException
 */
private void doCatchupStatusTest(PartitionId id, long acceptableLagInBytes, short numReplicasCaughtUpPerPartition, ServerErrorCode expectedServerErrorCode, boolean expectedIsCaughtUp) throws InterruptedException, IOException {
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = TestUtils.getRandomString(10);
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.CatchupStatus, id, correlationId, clientId);
    CatchupStatusAdminRequest catchupStatusRequest = new CatchupStatusAdminRequest(acceptableLagInBytes, numReplicasCaughtUpPerPartition, adminRequest);
    Response response = sendRequestGetResponse(catchupStatusRequest, expectedServerErrorCode);
    assertTrue("Response not of type CatchupStatusAdminResponse", response instanceof CatchupStatusAdminResponse);
    CatchupStatusAdminResponse adminResponse = (CatchupStatusAdminResponse) response;
    assertEquals("Catchup status not as expected", expectedIsCaughtUp, adminResponse.isCaughtUp());
    response.release();
}
Also used : ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Response(com.github.ambry.protocol.Response) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse)

Example 14 with AdminResponse

use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.

the class AmbryServerRequestsTest method sendAndVerifyRequestControlRequest.

/**
 * Sends and verifies that a {@link AdminRequestOrResponseType#RequestControl} request received the error code
 * expected.
 * @param toControl the {@link AdminRequestOrResponseType#RequestControl} to control.
 * @param enable {@code true} if {@code toControl} needs to be enabled. {@code false} otherwise.
 * @param id the {@link PartitionId} to send the request for. Can be {@code null}.
 * @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
 * @throws InterruptedException
 * @throws IOException
 */
private void sendAndVerifyRequestControlRequest(RequestOrResponseType toControl, boolean enable, PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = TestUtils.getRandomString(10);
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.RequestControl, id, correlationId, clientId);
    RequestControlAdminRequest controlRequest = new RequestControlAdminRequest(toControl, enable, adminRequest);
    Response response = sendRequestGetResponse(controlRequest, expectedServerErrorCode);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    response.release();
}
Also used : ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Response(com.github.ambry.protocol.Response) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest)

Example 15 with AdminResponse

use of com.github.ambry.protocol.AdminResponse 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

AdminResponse (com.github.ambry.protocol.AdminResponse)28 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)25 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)22 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)22 AdminRequest (com.github.ambry.protocol.AdminRequest)20 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)19 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)19 PartitionId (com.github.ambry.clustermap.PartitionId)14 GetResponse (com.github.ambry.protocol.GetResponse)13 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)11 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)11 Response (com.github.ambry.protocol.Response)11 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)7 DataInputStream (java.io.DataInputStream)5 ServerErrorCode (com.github.ambry.commons.ServerErrorCode)4 ResponseInfo (com.github.ambry.network.ResponseInfo)4 IOException (java.io.IOException)4 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)3 MessageFormatException (com.github.ambry.messageformat.MessageFormatException)3 ConnectedChannel (com.github.ambry.network.ConnectedChannel)3