Search in sources :

Example 1 with CatchupStatusAdminRequest

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

the class AmbryRequests method handleCatchupStatusRequest.

/**
 * Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#CatchupStatus}.
 * @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 handleCatchupStatusRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
    Collection<PartitionId> partitionIds;
    ServerErrorCode error = ServerErrorCode.No_Error;
    boolean isCaughtUp = false;
    CatchupStatusAdminRequest catchupStatusRequest = CatchupStatusAdminRequest.readFrom(requestStream, adminRequest);
    if (catchupStatusRequest.getAcceptableLagInBytes() < 0) {
        error = ServerErrorCode.Bad_Request;
    } else if (catchupStatusRequest.getNumReplicasCaughtUpPerPartition() <= 0) {
        error = ServerErrorCode.Bad_Request;
    } else {
        if (catchupStatusRequest.getPartitionId() != null) {
            error = validateRequest(catchupStatusRequest.getPartitionId(), RequestOrResponseType.AdminRequest);
            partitionIds = Collections.singletonList(catchupStatusRequest.getPartitionId());
        } else {
            partitionIds = partitionsInCurrentNode;
        }
        if (!error.equals(ServerErrorCode.Partition_Unknown)) {
            error = ServerErrorCode.No_Error;
            isCaughtUp = isRemoteLagLesserOrEqual(partitionIds, catchupStatusRequest.getAcceptableLagInBytes(), catchupStatusRequest.getNumReplicasCaughtUpPerPartition());
        }
    }
    AdminResponse adminResponse = new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
    return new CatchupStatusAdminResponse(isCaughtUp, adminResponse);
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) PartitionId(com.github.ambry.clustermap.PartitionId) ServerErrorCode(com.github.ambry.commons.ServerErrorCode)

Example 2 with CatchupStatusAdminRequest

use of com.github.ambry.protocol.CatchupStatusAdminRequest 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 3 with CatchupStatusAdminRequest

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

the class ServerAdminTool method isCaughtUp.

/**
 * Sends a {@link CatchupStatusAdminRequest} for {@code partitionIdStr} to {@code dataNodeId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param partitionId the {@link PartitionId} to check catchup status for. If {@code null}, status is for all
 *                    partitions on {@code dataNodeId}
 * @param acceptableLagInBytes that lag in bytes that is considered OK.
 * @param numReplicasCaughtUpPerPartition the number of replicas that have to be within {@code acceptableLagInBytes}
 *                                        (per partition). The min of this value or the total count of replicas - 1 is
 *                                        considered.
 * @return the {@link ServerErrorCode} and the catchup status that is returned if the error code is
 *          {@link ServerErrorCode#No_Error}, otherwise {@code false}.
 * @throws IOException
 * @throws TimeoutException
 */
public Pair<ServerErrorCode, Boolean> isCaughtUp(DataNodeId dataNodeId, PartitionId partitionId, long acceptableLagInBytes, short numReplicasCaughtUpPerPartition) throws IOException, TimeoutException {
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.CatchupStatus, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
    CatchupStatusAdminRequest catchupStatusRequest = new CatchupStatusAdminRequest(acceptableLagInBytes, numReplicasCaughtUpPerPartition, adminRequest);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, catchupStatusRequest);
    CatchupStatusAdminResponse adminResponse = CatchupStatusAdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
    response.release();
    return new Pair<>(adminResponse.getError(), adminResponse.getError() == ServerErrorCode.No_Error && adminResponse.isCaughtUp());
}
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) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Pair(com.github.ambry.utils.Pair)

Example 4 with CatchupStatusAdminRequest

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

the class AmbryRequestsTest 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 = UtilsTest.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());
}
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) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse)

Example 5 with CatchupStatusAdminRequest

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

the class AmbryServerRequests method handleCatchupStatusRequest.

/**
 * Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#CatchupStatus}.
 * @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 handleCatchupStatusRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
    Collection<PartitionId> partitionIds;
    ServerErrorCode error = ServerErrorCode.No_Error;
    boolean isCaughtUp = false;
    CatchupStatusAdminRequest catchupStatusRequest = CatchupStatusAdminRequest.readFrom(requestStream, adminRequest);
    if (catchupStatusRequest.getAcceptableLagInBytes() < 0) {
        error = ServerErrorCode.Bad_Request;
    } else if (catchupStatusRequest.getNumReplicasCaughtUpPerPartition() <= 0) {
        error = ServerErrorCode.Bad_Request;
    } else {
        if (catchupStatusRequest.getPartitionId() != null) {
            error = validateRequest(catchupStatusRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
            partitionIds = Collections.singletonList(catchupStatusRequest.getPartitionId());
        } else {
            partitionIds = storeManager.getLocalPartitions();
        }
        if (!error.equals(ServerErrorCode.Partition_Unknown)) {
            error = ServerErrorCode.No_Error;
            isCaughtUp = isRemoteLagLesserOrEqual(partitionIds, catchupStatusRequest.getAcceptableLagInBytes(), catchupStatusRequest.getNumReplicasCaughtUpPerPartition());
        }
    }
    AdminResponse adminResponse = new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
    return new CatchupStatusAdminResponse(isCaughtUp, adminResponse);
}
Also used : AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) PartitionId(com.github.ambry.clustermap.PartitionId)

Aggregations

CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)5 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)5 AdminResponse (com.github.ambry.protocol.AdminResponse)4 AdminRequest (com.github.ambry.protocol.AdminRequest)3 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)3 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)3 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)3 PartitionId (com.github.ambry.clustermap.PartitionId)2 GetResponse (com.github.ambry.protocol.GetResponse)2 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)2 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)2 Response (com.github.ambry.protocol.Response)2 ServerErrorCode (com.github.ambry.commons.ServerErrorCode)1 ResponseInfo (com.github.ambry.network.ResponseInfo)1 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)1 Pair (com.github.ambry.utils.Pair)1