Search in sources :

Example 1 with AdminRequest

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

the class AmbryRequests 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.
 */
private void handleAdminRequest(Request 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) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) 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) MessageFormatException(com.github.ambry.messageformat.MessageFormatException)

Example 2 with AdminRequest

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

the class AmbryRequestsTest method stopBlobStoreFailureTest.

/**
 * Tests for the response received on a {@link BlobStoreControlAdminRequest} for different failure cases
 * @throws InterruptedException
 * @throws IOException
 */
@Test
public void stopBlobStoreFailureTest() throws InterruptedException, IOException {
    List<? extends PartitionId> partitionIds = clusterMap.getAllPartitionIds();
    PartitionId id = partitionIds.get(0);
    int correlationId = TestUtils.RANDOM.nextInt();
    String clientId = UtilsTest.getRandomString(10);
    short numReplicasCaughtUpPerPartition = -1;
    // test invalid numReplicasCaughtUpPerPartition
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    BlobStoreControlAdminRequest blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    Response response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Bad_Request);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    // test partition unknown
    numReplicasCaughtUpPerPartition = 3;
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, null, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Partition_Unknown);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    // test validate request failure
    storageManager.returnNullStore = true;
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Disk_Unavailable);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    storageManager.returnNullStore = false;
    // test disable compaction failure
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    storageManager.returnValueOfDisablingCompaction = false;
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Unknown_Error);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    storageManager.returnValueOfDisablingCompaction = true;
    // test disable compaction with runtime exception
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    storageManager.exceptionToThrowOnDisablingCompaction = new IllegalStateException();
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Unknown_Error);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    storageManager.exceptionToThrowOnDisablingCompaction = null;
    // test disable replication failure
    replicationManager.reset();
    replicationManager.controlReplicationReturnVal = false;
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Unknown_Error);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    // test peers catchup failure
    replicationManager.reset();
    replicationManager.controlReplicationReturnVal = true;
    // all replicas of this partition > acceptableLag
    generateLagOverrides(1, 1);
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Retry_After_Backoff);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    // test shutdown BlobStore failure
    replicationManager.reset();
    replicationManager.controlReplicationReturnVal = true;
    storageManager.returnValueOfShutdownBlobStore = false;
    generateLagOverrides(0, 0);
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Unknown_Error);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    // test shutdown BlobStore with runtime exception
    storageManager.exceptionToThrowOnShuttingdownBlobStore = new IllegalStateException();
    adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, id, correlationId, clientId);
    blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, false, adminRequest);
    response = sendRequestGetResponse(blobStoreControlAdminRequest, ServerErrorCode.Unknown_Error);
    assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
    storageManager.exceptionToThrowOnShuttingdownBlobStore = null;
}
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) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId) UtilsTest(com.github.ambry.utils.UtilsTest) Test(org.junit.Test)

Example 3 with AdminRequest

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

the class AmbryRequestsTest 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 = UtilsTest.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 : 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) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse)

Example 4 with AdminRequest

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

the class AmbryRequestsTest 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 = UtilsTest.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();
    } 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));
    }
}
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) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 5 with AdminRequest

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

the class ServerAdminTool method triggerCompaction.

/**
 * Triggers compaction on {@code dataNodeId} for the partition defined in {@code partitionIdStr}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param partitionId the {@link PartitionId} to compact.
 * @return the {@link ServerErrorCode} that is returned.
 * @throws IOException
 * @throws TimeoutException
 */
public ServerErrorCode triggerCompaction(DataNodeId dataNodeId, PartitionId partitionId) throws IOException, TimeoutException {
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.TriggerCompaction, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, adminRequest);
    AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
    response.release();
    return adminResponse.getError();
}
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) ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse)

Aggregations

AdminRequest (com.github.ambry.protocol.AdminRequest)21 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)21 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)21 AdminResponse (com.github.ambry.protocol.AdminResponse)20 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)18 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)18 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)18 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)8 PartitionId (com.github.ambry.clustermap.PartitionId)6 ResponseInfo (com.github.ambry.network.ResponseInfo)5 DataInputStream (java.io.DataInputStream)5 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 Histogram (com.codahale.metrics.Histogram)2