Search in sources :

Example 1 with ResponseInfo

use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.

the class MockRouterCallback method assertOperationFailure.

/**
 * Assert that operation fails with the expected error code
 * @param errorCode expected error code on failure
 * @throws RouterException
 */
private void assertOperationFailure(RouterErrorCode errorCode) throws RouterException, IOException, InterruptedException {
    NonBlockingRouter.currentOperationsCount.incrementAndGet();
    GetBlobInfoOperation op = new GetBlobInfoOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobId, options, null, routerCallback, kms, cryptoService, cryptoJobHandler, time);
    ArrayList<RequestInfo> requestListToFill = new ArrayList<>();
    requestRegistrationCallback.requestListToFill = requestListToFill;
    op.poll(requestRegistrationCallback);
    Assert.assertEquals("There should only be as many requests at this point as requestParallelism", requestParallelism, correlationIdToGetOperation.size());
    CountDownLatch onPollLatch = new CountDownLatch(1);
    routerCallback.setOnPollLatch(onPollLatch);
    List<ResponseInfo> responses = sendAndWaitForResponses(requestListToFill);
    for (ResponseInfo responseInfo : responses) {
        GetResponse getResponse = responseInfo.getError() == null ? GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), mockClusterMap) : null;
        op.handleResponse(responseInfo, getResponse);
        if (op.isOperationComplete()) {
            break;
        }
    }
    if (!op.isOperationComplete()) {
        Assert.assertTrue("Latch should have been zeroed ", onPollLatch.await(500, TimeUnit.MILLISECONDS));
        op.poll(requestRegistrationCallback);
    }
    Assert.assertTrue("Operation should be complete at this time", op.isOperationComplete());
    RouterException routerException = (RouterException) op.getOperationException();
    Assert.assertEquals(errorCode, routerException.getErrorCode());
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) ArrayList(java.util.ArrayList) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) RequestInfo(com.github.ambry.network.RequestInfo) CountDownLatch(java.util.concurrent.CountDownLatch) DataInputStream(java.io.DataInputStream) GetResponse(com.github.ambry.protocol.GetResponse)

Example 2 with ResponseInfo

use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.

the class MockRouterCallback method testBlobNotFoundCase.

/**
 * Test the case where every server returns Blob_Not_Found. All servers must have been contacted,
 * due to cross-colo proxying.
 * @throws Exception
 */
@Test
public void testBlobNotFoundCase() throws Exception {
    NonBlockingRouter.currentOperationsCount.incrementAndGet();
    GetBlobInfoOperation op = new GetBlobInfoOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobId, options, null, routerCallback, kms, cryptoService, cryptoJobHandler, time);
    ArrayList<RequestInfo> requestListToFill = new ArrayList<>();
    requestRegistrationCallback.requestListToFill = requestListToFill;
    for (MockServer server : mockServerLayout.getMockServers()) {
        server.setServerErrorForAllRequests(ServerErrorCode.Blob_Not_Found);
    }
    while (!op.isOperationComplete()) {
        op.poll(requestRegistrationCallback);
        List<ResponseInfo> responses = sendAndWaitForResponses(requestListToFill);
        for (ResponseInfo responseInfo : responses) {
            GetResponse getResponse = responseInfo.getError() == null ? GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), mockClusterMap) : null;
            op.handleResponse(responseInfo, getResponse);
            if (op.isOperationComplete()) {
                break;
            }
        }
    }
    Assert.assertEquals("Must have attempted sending requests to all replicas", replicasCount, correlationIdToGetOperation.size());
    Assert.assertTrue("Operation should be complete at this time", op.isOperationComplete());
    RouterException routerException = (RouterException) op.getOperationException();
    Assert.assertEquals(RouterErrorCode.BlobDoesNotExist, routerException.getErrorCode());
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) ArrayList(java.util.ArrayList) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) RequestInfo(com.github.ambry.network.RequestInfo) DataInputStream(java.io.DataInputStream) GetResponse(com.github.ambry.protocol.GetResponse) PutManagerTest(com.github.ambry.router.PutManagerTest) Test(org.junit.Test)

Example 3 with ResponseInfo

use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.

the class MockRouterCallback method testVariousErrors.

private void testVariousErrors(String dcWherePutHappened) throws Exception {
    NonBlockingRouter.currentOperationsCount.incrementAndGet();
    GetBlobInfoOperation op = new GetBlobInfoOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, blobId, options, null, routerCallback, kms, cryptoService, cryptoJobHandler, time);
    ArrayList<RequestInfo> requestListToFill = new ArrayList<>();
    requestRegistrationCallback.requestListToFill = requestListToFill;
    ArrayList<MockServer> mockServers = new ArrayList<>(mockServerLayout.getMockServers());
    // set the status to various server level or partition level errors (not Blob_Deleted or Blob_Expired).
    mockServers.get(0).setServerErrorForAllRequests(ServerErrorCode.Unknown_Error);
    mockServers.get(1).setServerErrorForAllRequests(ServerErrorCode.Unknown_Error);
    mockServers.get(2).setServerErrorForAllRequests(ServerErrorCode.IO_Error);
    mockServers.get(3).setServerErrorForAllRequests(ServerErrorCode.Blob_Not_Found);
    mockServers.get(4).setServerErrorForAllRequests(ServerErrorCode.Data_Corrupt);
    mockServers.get(5).setServerErrorForAllRequests(ServerErrorCode.Blob_Not_Found);
    mockServers.get(6).setServerErrorForAllRequests(ServerErrorCode.Blob_Not_Found);
    mockServers.get(7).setServerErrorForAllRequests(ServerErrorCode.Disk_Unavailable);
    mockServers.get(8).setServerErrorForAllRequests(ServerErrorCode.Unknown_Error);
    // clear the hard error in one of the servers in the datacenter where the put happened.
    for (int i = 0; i < mockServers.size(); i++) {
        MockServer mockServer = mockServers.get(i);
        if (mockServer.getDataCenter().equals(dcWherePutHappened)) {
            mockServer.setServerErrorForAllRequests(ServerErrorCode.No_Error);
            break;
        }
    }
    while (!op.isOperationComplete()) {
        op.poll(requestRegistrationCallback);
        List<ResponseInfo> responses = sendAndWaitForResponses(requestListToFill);
        for (ResponseInfo responseInfo : responses) {
            GetResponse getResponse = responseInfo.getError() == null ? GetResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseInfo.getResponse())), mockClusterMap) : null;
            op.handleResponse(responseInfo, getResponse);
            if (op.isOperationComplete()) {
                break;
            }
        }
    }
    Assert.assertTrue("Operation should be complete at this time", op.isOperationComplete());
    assertSuccess(op);
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) ArrayList(java.util.ArrayList) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) RequestInfo(com.github.ambry.network.RequestInfo) DataInputStream(java.io.DataInputStream) GetResponse(com.github.ambry.protocol.GetResponse)

Example 4 with ResponseInfo

use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.

the class NonBlockingRouterTest method testResponseDeserializationError.

/**
 * Test that operations succeed even in the presence of responses that are corrupt and fail to deserialize.
 * @param opHelper the {@link OperationHelper}
 * @param networkClient the {@link NetworkClient}
 * @param blobId the id of the blob to get/delete. For puts, this will be null.
 * @throws Exception
 */
private void testResponseDeserializationError(OperationHelper opHelper, NetworkClient networkClient, BlobId blobId) throws Exception {
    mockSelectorState.set(MockSelectorState.Good);
    FutureResult futureResult = opHelper.submitOperation(blobId);
    int requestParallelism = opHelper.requestParallelism;
    List<RequestInfo> allRequests = new ArrayList<>();
    long loopStartTimeMs = SystemTime.getInstance().milliseconds();
    while (allRequests.size() < requestParallelism) {
        if (loopStartTimeMs + AWAIT_TIMEOUT_MS < SystemTime.getInstance().milliseconds()) {
            Assert.fail("Waited too long for requests.");
        }
        opHelper.pollOpManager(allRequests);
    }
    List<ResponseInfo> responseInfoList = new ArrayList<>();
    loopStartTimeMs = SystemTime.getInstance().milliseconds();
    do {
        if (loopStartTimeMs + AWAIT_TIMEOUT_MS < SystemTime.getInstance().milliseconds()) {
            Assert.fail("Waited too long for the response.");
        }
        responseInfoList.addAll(networkClient.sendAndPoll(allRequests, 10));
        allRequests.clear();
    } while (responseInfoList.size() < requestParallelism);
    // corrupt the first response.
    ByteBuffer response = responseInfoList.get(0).getResponse();
    byte b = response.get(response.limit() - 1);
    response.put(response.limit() - 1, (byte) ~b);
    for (ResponseInfo responseInfo : responseInfoList) {
        opHelper.handleResponse(responseInfo);
    }
    allRequests.clear();
    if (testEncryption) {
        opHelper.awaitOpCompletionOrTimeOut(futureResult);
    } else {
        opHelper.pollOpManager(allRequests);
    }
    try {
        futureResult.get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (ExecutionException e) {
        Assert.fail("Operation should have succeeded with one corrupt response");
    }
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) ArrayList(java.util.ArrayList) RequestInfo(com.github.ambry.network.RequestInfo) ExecutionException(java.util.concurrent.ExecutionException) ByteBuffer(java.nio.ByteBuffer)

Example 5 with ResponseInfo

use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.

the class ServerAdminTool method getGetResponse.

/**
 * Sends a {@link GetRequest} based on the provided parameters and returns the response stream if the request was
 * successful. {@code null} otherwise.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param blobId the {@link BlobId} to operate on.
 * @param flags the {@link MessageFormatFlags} associated with the {@link GetRequest}.
 * @param getOption the {@link GetOption} to send with the {@link GetRequest}.
 * @param clusterMap the {@link ClusterMap} to use.
 * @return the {@link ServerErrorCode} and response stream if the request was successful. {@code null} for the
 * response stream otherwise.
 * @throws Exception
 */
private Pair<ServerErrorCode, InputStream> getGetResponse(DataNodeId dataNodeId, BlobId blobId, MessageFormatFlags flags, GetOption getOption, ClusterMap clusterMap) throws Exception {
    PartitionId partitionId = blobId.getPartition();
    PartitionRequestInfo partitionRequestInfo = new PartitionRequestInfo(partitionId, Collections.singletonList(blobId));
    List<PartitionRequestInfo> partitionRequestInfos = new ArrayList<>();
    partitionRequestInfos.add(partitionRequestInfo);
    GetRequest getRequest = new GetRequest(correlationId.incrementAndGet(), CLIENT_ID, flags, partitionRequestInfos, getOption);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, getRequest);
    InputStream serverResponseStream = new NettyByteBufDataInputStream(response.content());
    response.release();
    GetResponse getResponse = GetResponse.readFrom(new DataInputStream(serverResponseStream), clusterMap);
    ServerErrorCode partitionErrorCode = getResponse.getPartitionResponseInfoList().get(0).getErrorCode();
    ServerErrorCode errorCode = partitionErrorCode == ServerErrorCode.No_Error ? getResponse.getError() : partitionErrorCode;
    InputStream stream = errorCode == ServerErrorCode.No_Error ? getResponse.getInputStream() : null;
    return new Pair<>(errorCode, stream);
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) InputStream(java.io.InputStream) GetRequest(com.github.ambry.protocol.GetRequest) ArrayList(java.util.ArrayList) PartitionId(com.github.ambry.clustermap.PartitionId) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) DataInputStream(java.io.DataInputStream) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) GetResponse(com.github.ambry.protocol.GetResponse) ServerErrorCode(com.github.ambry.server.ServerErrorCode) Pair(com.github.ambry.utils.Pair)

Aggregations

ResponseInfo (com.github.ambry.network.ResponseInfo)44 RequestInfo (com.github.ambry.network.RequestInfo)33 ArrayList (java.util.ArrayList)25 Test (org.junit.Test)18 GetResponse (com.github.ambry.protocol.GetResponse)17 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)17 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)12 BlobProperties (com.github.ambry.messageformat.BlobProperties)9 PutResponse (com.github.ambry.protocol.PutResponse)9 DataInputStream (java.io.DataInputStream)9 BlobId (com.github.ambry.commons.BlobId)8 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)6 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)6 ReplicaId (com.github.ambry.clustermap.ReplicaId)5 VerifiableProperties (com.github.ambry.config.VerifiableProperties)5 AdminRequest (com.github.ambry.protocol.AdminRequest)5 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)5 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)5 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)5 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)5