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