use of com.github.ambry.protocol.AdminResponse 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.AdminResponse 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.AdminResponse in project ambry by linkedin.
the class AmbryRequests method handleRequestControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#RequestControl}.
* @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 handleRequestControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
RequestControlAdminRequest controlRequest = RequestControlAdminRequest.readFrom(requestStream, adminRequest);
RequestOrResponseType toControl = controlRequest.getRequestTypeToControl();
ServerErrorCode error;
Collection<PartitionId> partitionIds;
if (!requestsDisableInfo.containsKey(toControl)) {
metrics.badRequestError.inc();
error = ServerErrorCode.Bad_Request;
} else {
error = ServerErrorCode.No_Error;
if (controlRequest.getPartitionId() != null) {
error = validateRequest(controlRequest.getPartitionId(), RequestOrResponseType.AdminRequest);
partitionIds = Collections.singletonList(controlRequest.getPartitionId());
} else {
partitionIds = partitionsInCurrentNode;
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
controlRequestForPartitions(toControl, partitionIds, controlRequest.shouldEnable());
for (PartitionId partitionId : partitionIds) {
logger.info("Enable state for {} on {} is {}", toControl, partitionId, isRequestEnabled(toControl, partitionId));
}
}
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryRequests method handleReplicationControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#ReplicationControl}.
* @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 handleReplicationControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
Collection<PartitionId> partitionIds;
ServerErrorCode error = ServerErrorCode.No_Error;
ReplicationControlAdminRequest replControlRequest = ReplicationControlAdminRequest.readFrom(requestStream, adminRequest);
if (replControlRequest.getPartitionId() != null) {
error = validateRequest(replControlRequest.getPartitionId(), RequestOrResponseType.AdminRequest);
partitionIds = Collections.singletonList(replControlRequest.getPartitionId());
} else {
partitionIds = partitionsInCurrentNode;
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
if (replicationManager.controlReplicationForPartitions(partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable())) {
error = ServerErrorCode.No_Error;
} else {
logger.error("Could not set enable status for replication of {} from {} to {}. Check partition validity and" + " origins list", partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable());
error = ServerErrorCode.Bad_Request;
}
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.protocol.AdminResponse 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;
}
Aggregations