Search in sources :

Example 1 with TtlUpdateResponse

use of com.github.ambry.protocol.TtlUpdateResponse in project ambry by linkedin.

the class InMemoryCloudDestinationErrorSimulationTest method testTtlUpdateErrorSimulation.

/**
 * test error simulation for TtlUpdateRequest
 * @throws Exception
 */
@Test
public void testTtlUpdateErrorSimulation() throws Exception {
    BlobId blobId = doPut(partitionId);
    TtlUpdateRequest ttlUpdateRequest = new TtlUpdateRequest(1234, "clientId", blobId, Utils.Infinite_Time, SystemTime.getInstance().milliseconds());
    RequestInfo requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, null);
    ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
    TtlUpdateResponse response = responseInfo.getError() == null ? (TtlUpdateResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
    Assert.assertEquals("TtlUpdate should succeed.", response.getError(), ServerErrorCode.No_Error);
    response.release();
    // inject error for cloud colo.
    cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.TTL_Expired);
    ttlUpdateRequest = new TtlUpdateRequest(1234, "clientId", blobId, Utils.Infinite_Time, SystemTime.getInstance().milliseconds());
    requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, null);
    responseInfo = sendAndWaitForResponses(requestInfo);
    response = responseInfo.getError() == null ? ((TtlUpdateResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse())) : null;
    Assert.assertEquals("TtlUpdate should return Blob_Expired.", response.getError(), ServerErrorCode.Blob_Expired);
    response.release();
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) TtlUpdateRequest(com.github.ambry.protocol.TtlUpdateRequest) TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) BlobId(com.github.ambry.commons.BlobId) Test(org.junit.Test)

Example 2 with TtlUpdateResponse

use of com.github.ambry.protocol.TtlUpdateResponse in project ambry by linkedin.

the class TtlUpdateManager method handleResponse.

/**
 * Handles responses received for each of the {@link TtlUpdateOperation} within this TtlUpdateManager.
 * @param responseInfo the {@link ResponseInfo} containing the response.
 */
void handleResponse(ResponseInfo responseInfo) {
    long startTime = time.milliseconds();
    TtlUpdateResponse ttlUpdateResponse = RouterUtils.extractResponseAndNotifyResponseHandler(responseHandler, routerMetrics, responseInfo, TtlUpdateResponse::readFrom, TtlUpdateResponse::getError);
    RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
    int correlationId = ((TtlUpdateRequest) routerRequestInfo.getRequest()).getCorrelationId();
    TtlUpdateOperation ttlUpdateOperation = correlationIdToTtlUpdateOperation.remove(correlationId);
    // If it is still an active operation, hand over the response. Otherwise, ignore.
    if (ttlUpdateOperations.contains(ttlUpdateOperation)) {
        boolean exceptionEncountered = false;
        try {
            ttlUpdateOperation.handleResponse(responseInfo, ttlUpdateResponse);
        } catch (Exception e) {
            exceptionEncountered = true;
            ttlUpdateOperation.setOperationException(new RouterException("TTLUpdate handleResponse encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError));
        }
        if (exceptionEncountered || ttlUpdateOperation.isOperationComplete()) {
            if (ttlUpdateOperations.remove(ttlUpdateOperation)) {
                onComplete(ttlUpdateOperation);
            }
        }
        routerMetrics.ttlUpdateManagerHandleResponseTimeMs.update(time.milliseconds() - startTime);
    } else {
        routerMetrics.ignoredResponseCount.inc();
    }
}
Also used : TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) TtlUpdateRequest(com.github.ambry.protocol.TtlUpdateRequest) RequestInfo(com.github.ambry.network.RequestInfo)

Example 3 with TtlUpdateResponse

use of com.github.ambry.protocol.TtlUpdateResponse in project ambry by linkedin.

the class ServerTestUtil method updateBlobTtl.

/**
 * Updates the TTL of the given {@code blobId}
 * @param channel the {@link ConnectedChannel} to make the {@link GetRequest} on.
 * @param blobId the ID of the blob to TTL update
 * @param ts the operation time
 * @throws IOException
 */
static void updateBlobTtl(ConnectedChannel channel, BlobId blobId, long ts) throws IOException {
    TtlUpdateRequest ttlUpdateRequest = new TtlUpdateRequest(1, "updateBlobTtl", blobId, Utils.Infinite_Time, ts);
    DataInputStream stream = channel.sendAndReceive(ttlUpdateRequest).getInputStream();
    TtlUpdateResponse ttlUpdateResponse = TtlUpdateResponse.readFrom(stream);
    releaseNettyBufUnderneathStream(stream);
    assertEquals("Unexpected ServerErrorCode for TtlUpdateRequest", ServerErrorCode.No_Error, ttlUpdateResponse.getError());
}
Also used : TtlUpdateRequest(com.github.ambry.protocol.TtlUpdateRequest) TtlUpdateResponse(com.github.ambry.protocol.TtlUpdateResponse) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) DataInputStream(java.io.DataInputStream)

Aggregations

TtlUpdateRequest (com.github.ambry.protocol.TtlUpdateRequest)3 TtlUpdateResponse (com.github.ambry.protocol.TtlUpdateResponse)3 RequestInfo (com.github.ambry.network.RequestInfo)2 BlobId (com.github.ambry.commons.BlobId)1 ResponseInfo (com.github.ambry.network.ResponseInfo)1 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)1 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)1 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)1 DataInputStream (java.io.DataInputStream)1 Test (org.junit.Test)1