Search in sources :

Example 21 with AdminResponse

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

the class AmbryServerRequests 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 StoreException, IOException {
    ServerErrorCode error;
    BlobStoreControlAdminRequest blobStoreControlAdminRequest = BlobStoreControlAdminRequest.readFrom(requestStream, adminRequest);
    PartitionId partitionId = blobStoreControlAdminRequest.getPartitionId();
    if (partitionId != null) {
        switch(blobStoreControlAdminRequest.getStoreControlAction()) {
            case StopStore:
                short numReplicasCaughtUpPerPartition = blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition();
                logger.info("Handling stop store request and {} replica(s) per partition should catch up before stopping store {}", numReplicasCaughtUpPerPartition, partitionId);
                error = handleStopStoreRequest(partitionId, numReplicasCaughtUpPerPartition);
                break;
            case StartStore:
                logger.info("Handling start store request on {}", partitionId);
                error = handleStartStoreRequest(partitionId);
                break;
            case AddStore:
                logger.info("Handling add store request for {}", partitionId);
                error = handleAddStoreRequest(partitionId);
                break;
            case RemoveStore:
                logger.info("Handling remove store request on {}", partitionId);
                error = handleRemoveStoreRequest(partitionId);
                break;
            default:
                throw new IllegalArgumentException("NetworkRequest type not supported: " + blobStoreControlAdminRequest.getStoreControlAction());
        }
    } else {
        error = ServerErrorCode.Bad_Request;
        logger.debug("The partition Id should not be null.");
    }
    return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
Also used : AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 22 with AdminResponse

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

the class AmbryServerRequests method handleAdminRequest.

/**
 * Handles an administration request. These requests can query for or change the internal state of the server.
 * @param request the request that needs to be handled.
 * @throws InterruptedException if response sending is interrupted.
 * @throws IOException if there are I/O errors carrying our the required operation.
 */
@Override
public void handleAdminRequest(NetworkRequest request) throws InterruptedException, IOException {
    long requestQueueTime = SystemTime.getInstance().milliseconds() - request.getStartTimeInMs();
    long totalTimeSpent = requestQueueTime;
    long startTime = SystemTime.getInstance().milliseconds();
    DataInputStream requestStream = new DataInputStream(request.getInputStream());
    AdminRequest adminRequest = AdminRequest.readFrom(requestStream, clusterMap);
    Histogram processingTimeHistogram = null;
    Histogram responseQueueTimeHistogram = null;
    Histogram responseSendTimeHistogram = null;
    Histogram requestTotalTimeHistogram = null;
    AdminResponse response = null;
    try {
        switch(adminRequest.getType()) {
            case TriggerCompaction:
                metrics.triggerCompactionRequestQueueTimeInMs.update(requestQueueTime);
                metrics.triggerCompactionRequestRate.mark();
                processingTimeHistogram = metrics.triggerCompactionResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.triggerCompactionResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.triggerCompactionResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.triggerCompactionRequestTotalTimeInMs;
                response = handleTriggerCompactionRequest(adminRequest);
                break;
            case RequestControl:
                metrics.requestControlRequestQueueTimeInMs.update(requestQueueTime);
                metrics.requestControlRequestRate.mark();
                processingTimeHistogram = metrics.requestControlResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.requestControlResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.requestControlResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.requestControlRequestTotalTimeInMs;
                response = handleRequestControlRequest(requestStream, adminRequest);
                break;
            case ReplicationControl:
                metrics.replicationControlRequestQueueTimeInMs.update(requestQueueTime);
                metrics.replicationControlRequestRate.mark();
                processingTimeHistogram = metrics.replicationControlResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.replicationControlResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.replicationControlResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.replicationControlRequestTotalTimeInMs;
                response = handleReplicationControlRequest(requestStream, adminRequest);
                break;
            case CatchupStatus:
                metrics.catchupStatusRequestQueueTimeInMs.update(requestQueueTime);
                metrics.catchupStatusRequestRate.mark();
                processingTimeHistogram = metrics.catchupStatusResponseQueueTimeInMs;
                responseQueueTimeHistogram = metrics.catchupStatusResponseQueueTimeInMs;
                responseSendTimeHistogram = metrics.catchupStatusResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.catchupStatusRequestTotalTimeInMs;
                response = handleCatchupStatusRequest(requestStream, adminRequest);
                break;
            case BlobStoreControl:
                metrics.blobStoreControlRequestQueueTimeInMs.update(requestQueueTime);
                metrics.blobStoreControlRequestRate.mark();
                processingTimeHistogram = metrics.blobStoreControlRequestQueueTimeInMs;
                responseQueueTimeHistogram = metrics.blobStoreControlRequestQueueTimeInMs;
                responseSendTimeHistogram = metrics.blobStoreControlResponseSendTimeInMs;
                requestTotalTimeHistogram = metrics.blobStoreControlRequestTotalTimeInMs;
                response = handleBlobStoreControlRequest(requestStream, adminRequest);
                break;
        }
    } catch (Exception e) {
        logger.error("Unknown exception for admin request {}", adminRequest, e);
        metrics.unExpectedAdminOperationError.inc();
        response = new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), ServerErrorCode.Unknown_Error);
        switch(adminRequest.getType()) {
            case CatchupStatus:
                response = new CatchupStatusAdminResponse(false, response);
                break;
        }
    } finally {
        long processingTime = SystemTime.getInstance().milliseconds() - startTime;
        totalTimeSpent += processingTime;
        publicAccessLogger.info("{} {} processingTime {}", adminRequest, response, processingTime);
        processingTimeHistogram.update(processingTime);
    }
    requestResponseChannel.sendResponse(response, request, new ServerNetworkResponseMetrics(responseQueueTimeHistogram, responseSendTimeHistogram, requestTotalTimeHistogram, null, null, totalTimeSpent));
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) ServerNetworkResponseMetrics(com.github.ambry.network.ServerNetworkResponseMetrics) AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Histogram(com.codahale.metrics.Histogram) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) DataInputStream(java.io.DataInputStream) StoreException(com.github.ambry.store.StoreException) IOException(java.io.IOException)

Example 23 with AdminResponse

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

the class AmbryServerRequestsTest method sendAndVerifyStoreControlRequest.

/**
 * Sends and verifies that a {@link AdminRequestOrResponseType#BlobStoreControl} request received the error code
 * expected.
 * @param partitionId the {@link PartitionId} to send the request for. Can be {@code null}.
 * @param storeControlRequestType type of control operation that will be performed on certain store.
 * @param numReplicasCaughtUpPerPartition the number of peer replicas which have caught up with this store before proceeding.
 * @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
 * @throws InterruptedException
 * @throws IOException
 */
private void sendAndVerifyStoreControlRequest(PartitionId partitionId, BlobStoreControlAction storeControlRequestType, short numReplicasCaughtUpPerPartition, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = TestUtils.getRandomString(10);
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, partitionId, correlationId, clientId);
    BlobStoreControlAdminRequest blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, storeControlRequestType, adminRequest);
    Response response = sendRequestGetResponse(blobStoreControlAdminRequest, 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) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Example 24 with AdminResponse

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

the class AmbryServerRequestsTest method doScheduleCompactionTest.

// scheduleCompactionSuccessTest() and scheduleCompactionFailuresTest() helpers
/**
 * Schedules a compaction for {@code id} and checks that the {@link ServerErrorCode} returned matches
 * {@code expectedServerErrorCode}.
 * @param id the {@link PartitionId} to schedule compaction for.
 * @param expectedServerErrorCode the {@link ServerErrorCode} expected when the request is processed.
 * @throws InterruptedException
 * @throws IOException
 */
private void doScheduleCompactionTest(PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = TestUtils.getRandomString(10);
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.TriggerCompaction, id, correlationId, clientId);
    Response response = sendRequestGetResponse(adminRequest, expectedServerErrorCode);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
}
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)

Example 25 with AdminResponse

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

the class AmbryServerRequestsTest method sendAndVerifyReplicationControlRequest.

/**
 * Sends and verifies that a {@link AdminRequestOrResponseType#ReplicationControl} request received the error code
 * expected and that {@link AmbryRequests} sent the right details to {@link ReplicationManager}.
 * @param origins the list of datacenters from which replication should be enabled/disabled.
 * @param enable {@code true} if replication 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 sendAndVerifyReplicationControlRequest(List<String> origins, boolean enable, PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = TestUtils.getRandomString(10);
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, id, correlationId, clientId);
    ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(origins, enable, adminRequest);
    Response response = sendRequestGetResponse(controlRequest, expectedServerErrorCode);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    List<PartitionId> idsVal;
    if (id == null) {
        idsVal = clusterMap.getAllPartitionIds(null);
    } else {
        idsVal = Collections.singletonList(id);
    }
    if (!expectedServerErrorCode.equals(ServerErrorCode.Unknown_Error)) {
        assertEquals("Origins not as provided in request", origins, replicationManager.originsVal);
        assertEquals("Enable not as provided in request", enable, replicationManager.enableVal);
        assertEquals("Ids not as provided in request", idsVal.size(), replicationManager.idsVal.size());
        assertTrue("Ids not as provided in request", replicationManager.idsVal.containsAll(idsVal));
    }
    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) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId)

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