Search in sources :

Example 46 with ServerErrorCode

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ServerErrorCode(com.github.ambry.server.ServerErrorCode) Test(org.junit.Test)

Example 47 with ServerErrorCode

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;
}
Also used : ServerErrorCode(com.github.ambry.server.ServerErrorCode)

Example 48 with ServerErrorCode

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));
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CountDownLatch(java.util.concurrent.CountDownLatch) ServerErrorCode(com.github.ambry.server.ServerErrorCode) Test(org.junit.Test)

Example 49 with ServerErrorCode

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);
    }
}
Also used : ServerErrorCode(com.github.ambry.server.ServerErrorCode) PutManagerTest(com.github.ambry.router.PutManagerTest) Test(org.junit.Test)

Example 50 with ServerErrorCode

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RouterConfig(com.github.ambry.config.RouterConfig) ServerErrorCode(com.github.ambry.server.ServerErrorCode) PutManagerTest(com.github.ambry.router.PutManagerTest) Test(org.junit.Test)

Aggregations

ServerErrorCode (com.github.ambry.server.ServerErrorCode)56 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 DataInputStream (java.io.DataInputStream)16 BlobProperties (com.github.ambry.messageformat.BlobProperties)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)11 BlobId (com.github.ambry.commons.BlobId)10 VerifiableProperties (com.github.ambry.config.VerifiableProperties)10 MessageFormatException (com.github.ambry.messageformat.MessageFormatException)9 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)9 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)8 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)8 RouterConfig (com.github.ambry.config.RouterConfig)8 Map (java.util.Map)8 Properties (java.util.Properties)8 DataNodeId (com.github.ambry.clustermap.DataNodeId)7 PartitionId (com.github.ambry.clustermap.PartitionId)7 MessageInfo (com.github.ambry.store.MessageInfo)7 IdUndeletedStoreException (com.github.ambry.store.IdUndeletedStoreException)6