use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class TtlUpdateNotificationSystem method individualErrorCodesTest.
/**
* Tests to make sure {@link ServerErrorCode}s map to the right {@link RouterErrorCode}.
* @throws Exception
*/
@Test
public void individualErrorCodesTest() throws Exception {
Map<ServerErrorCode, RouterErrorCode> errorCodeMap = new HashMap<>();
errorCodeMap.put(ServerErrorCode.Blob_Deleted, RouterErrorCode.BlobDeleted);
errorCodeMap.put(ServerErrorCode.Blob_Expired, RouterErrorCode.BlobExpired);
errorCodeMap.put(ServerErrorCode.Blob_Not_Found, RouterErrorCode.BlobDoesNotExist);
errorCodeMap.put(ServerErrorCode.Disk_Unavailable, RouterErrorCode.AmbryUnavailable);
errorCodeMap.put(ServerErrorCode.Replica_Unavailable, RouterErrorCode.AmbryUnavailable);
errorCodeMap.put(ServerErrorCode.Blob_Update_Not_Allowed, RouterErrorCode.BlobUpdateNotAllowed);
errorCodeMap.put(ServerErrorCode.Blob_Authorization_Failure, RouterErrorCode.BlobAuthorizationFailure);
for (ServerErrorCode errorCode : ServerErrorCode.values()) {
if (errorCode == ServerErrorCode.No_Error || errorCode == ServerErrorCode.Blob_Already_Updated) {
continue;
}
ArrayList<ServerErrorCode> serverErrorCodes = new ArrayList<>(Collections.nCopies(serverCount, ServerErrorCode.Blob_Not_Found));
// has to be repeated because the op tracker returns failure if it sees 8/9 failures and the success target is 2
serverErrorCodes.set(3, errorCode);
serverErrorCodes.set(5, errorCode);
Collections.shuffle(serverErrorCodes);
setServerErrorCodes(serverErrorCodes, serverLayout);
// In production, disk_unavailable usually means disk is bad with I/O errors. For now, the only way to fix this is
// to replace disk and relies on replication to restore data. If all replicas return disk unavailable (should be
// extremely rare in real world), it means blob is no long present and it's ok to return BlobDoesNotExist.
RouterErrorCode expected = errorCode == ServerErrorCode.Disk_Unavailable ? RouterErrorCode.BlobDoesNotExist : errorCodeMap.getOrDefault(errorCode, RouterErrorCode.UnexpectedInternalError);
executeOpAndVerify(blobIds, expected, false, true, true, false);
}
serverLayout.getMockServers().forEach(MockServer::resetServerErrors);
assertTtl(router, blobIds, TTL_SECS);
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class TtlUpdateNotificationSystem method resolveRouterErrorCode.
/**
* Helper method to resolve router error code. This accounts for combined disk_unavailable and not_found situation.
* @param serverErrorCodes a list of error code which servers will return.
* @param routerErrorCode the router error code solely decided by getPrecedenceLevel() method (which might be overridden)
* @return the resolved router error code.
*/
private RouterErrorCode resolveRouterErrorCode(List<ServerErrorCode> serverErrorCodes, RouterErrorCode routerErrorCode) {
RouterErrorCode resolvedErrorCode = routerErrorCode;
if (routerErrorCode == RouterErrorCode.AmbryUnavailable) {
int diskDownCount = 0;
int notFoundCount = 0;
for (ServerErrorCode errorCode : serverErrorCodes) {
if (errorCode == ServerErrorCode.Disk_Unavailable) {
diskDownCount++;
} else if (errorCode == ServerErrorCode.Blob_Not_Found) {
notFoundCount++;
}
}
if (diskDownCount + notFoundCount > serverCount - 2) {
resolvedErrorCode = RouterErrorCode.BlobDoesNotExist;
}
}
return resolvedErrorCode;
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class DeleteManagerTest method testSelectorError.
/**
* Test the case when the {@link com.github.ambry.network.Selector} of {@link SocketNetworkClient}
* experiences various exceptions. The order of received responses is the same as defined in {@code serverErrorCodes}.
*/
@Test
public void testSelectorError() throws Exception {
ServerErrorCode[] serverErrorCodes = new ServerErrorCode[9];
Arrays.fill(serverErrorCodes, ServerErrorCode.No_Error);
HashMap<MockSelectorState, RouterErrorCode> errorCodeHashMap = new HashMap<>();
errorCodeHashMap.put(MockSelectorState.DisconnectOnSend, RouterErrorCode.OperationTimedOut);
errorCodeHashMap.put(MockSelectorState.ThrowExceptionOnAllPoll, RouterErrorCode.OperationTimedOut);
errorCodeHashMap.put(MockSelectorState.ThrowExceptionOnConnect, RouterErrorCode.OperationTimedOut);
errorCodeHashMap.put(MockSelectorState.ThrowExceptionOnSend, RouterErrorCode.OperationTimedOut);
errorCodeHashMap.put(MockSelectorState.ThrowThrowableOnSend, RouterErrorCode.RouterClosed);
for (MockSelectorState state : MockSelectorState.values()) {
if (state == MockSelectorState.Good || state == MockSelectorState.FailConnectionInitiationOnPoll) {
// FailConnectionInitiationOnPoll is temporarily used for warm up failure test, skip it here
continue;
}
mockSelectorState.set(state);
setServerErrorCodes(serverErrorCodes, partition, serverLayout);
CountDownLatch operationCompleteLatch = new CountDownLatch(1);
future = router.deleteBlob(blobIdString, null, new ClientCallback(operationCompleteLatch), quotaChargeCallback);
do {
// increment mock time
mockTime.sleep(1000);
} while (!operationCompleteLatch.await(10, TimeUnit.MILLISECONDS));
assertFailureAndCheckErrorCode(future, errorCodeHashMap.get(state));
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class MockRouterCallback method testFailureOnServerErrors.
/**
* Tests the case where all servers return the same server level error code
* @throws Exception
*/
@Test
public void testFailureOnServerErrors() throws Exception {
// set the status to various server level errors (remove all partition level errors or non errors)
EnumSet<ServerErrorCode> serverErrors = EnumSet.complementOf(EnumSet.of(ServerErrorCode.Blob_Deleted, ServerErrorCode.Blob_Expired, ServerErrorCode.No_Error, ServerErrorCode.Blob_Authorization_Failure, ServerErrorCode.Blob_Not_Found));
for (ServerErrorCode serverErrorCode : serverErrors) {
mockServerLayout.getMockServers().forEach(server -> server.setServerErrorForAllRequests(serverErrorCode));
RouterErrorCode expectedRouterError;
switch(serverErrorCode) {
case Replica_Unavailable:
expectedRouterError = RouterErrorCode.AmbryUnavailable;
break;
case Disk_Unavailable:
// if all the disks are unavailable (which should be extremely rare), after replacing these disks, the blob is
// definitely not present.
expectedRouterError = RouterErrorCode.BlobDoesNotExist;
break;
default:
expectedRouterError = RouterErrorCode.UnexpectedInternalError;
}
assertOperationFailure(expectedRouterError);
}
}
use of com.github.ambry.server.ServerErrorCode in project ambry by linkedin.
the class MockRouterCallback method testBlobAuthorizationFailureOverrideAll.
/**
* Test the case where servers return different {@link ServerErrorCode} or success, and the {@link GetBlobInfoOperation}
* is able to resolve and conclude the correct {@link RouterErrorCode}. The get blob operation should be able
* to resolve the router error code as {@code Blob_Authorization_Failure}.
* @throws Exception
*/
@Test
public void testBlobAuthorizationFailureOverrideAll() throws Exception {
// set it to 2 for more coverage
successTarget = 2;
Properties props = getNonBlockingRouterProperties(true);
routerConfig = new RouterConfig(new VerifiableProperties(props));
ServerErrorCode[] serverErrorCodes = new ServerErrorCode[9];
serverErrorCodes[0] = ServerErrorCode.Blob_Not_Found;
serverErrorCodes[1] = ServerErrorCode.Data_Corrupt;
serverErrorCodes[2] = ServerErrorCode.IO_Error;
serverErrorCodes[3] = ServerErrorCode.Partition_Unknown;
serverErrorCodes[4] = ServerErrorCode.Disk_Unavailable;
serverErrorCodes[5] = ServerErrorCode.Blob_Authorization_Failure;
serverErrorCodes[6] = ServerErrorCode.Unknown_Error;
serverErrorCodes[7] = ServerErrorCode.Unknown_Error;
serverErrorCodes[8] = ServerErrorCode.No_Error;
testErrorPrecedence(serverErrorCodes, RouterErrorCode.BlobAuthorizationFailure);
}
Aggregations