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);
}
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();
}
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());
}
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());
}
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);
}
Aggregations