Search in sources :

Example 26 with RequestInfo

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

the class InMemoryCloudDestinationErrorSimulationTest method doPut.

/**
 * Do a put directly to the cloud mock servers.
 * @param partitionId partition id
 * @param expectedCode expected response error code
 * @return the blob id
 * @throws Exception
 */
private BlobId doPut(PartitionId partitionId, ServerErrorCode expectedCode) throws Exception {
    int blobSize = 4096;
    // direct put DataBlob
    BlobType blobType = BlobType.DataBlob;
    BlobProperties blobProperties = new BlobProperties(blobSize, "serviceId", "memberId", "contentType", false, Utils.Infinite_Time, Utils.getRandomShort(random), Utils.getRandomShort(random), false, null, null, null);
    byte[] userMetadata = new byte[10];
    random.nextBytes(userMetadata);
    byte[] putContent = new byte[blobSize];
    random.nextBytes(putContent);
    ByteBuf blobContent = PooledByteBufAllocator.DEFAULT.heapBuffer(blobSize);
    blobContent.writeBytes(putContent);
    BlobId blobId = new BlobId(routerConfig.routerBlobidCurrentVersion, BlobId.BlobIdType.NATIVE, mockClusterMap.getLocalDatacenterId(), blobProperties.getAccountId(), blobProperties.getContainerId(), partitionId, blobProperties.isEncrypted(), blobType == BlobType.MetadataBlob ? BlobId.BlobDataType.METADATA : BlobId.BlobDataType.DATACHUNK);
    ByteBuffer userMetadataBuf = ByteBuffer.wrap(userMetadata);
    // send to Cloud destinations.
    PutRequest request = new PutRequest(random.nextInt(), "clientId", blobId, blobProperties, userMetadataBuf.duplicate(), blobContent.retainedDuplicate(), blobContent.readableBytes(), blobType, null);
    RequestInfo requestInfo = new RequestInfo(hostname, port, request, replica, null);
    ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
    Assert.assertEquals("doPut should succeed.", responseInfo.getError(), null);
    // PutResponse response = PutResponse.readFrom(new NettyByteBufDataInputStream(responseInfo.content()));
    PutResponse response = (PutResponse) RouterUtils.mapToReceivedResponse((PutResponse) responseInfo.getResponse());
    Assert.assertEquals("The PutResponse is not expected.", expectedCode, response.getError());
    request.release();
    blobContent.release();
    return blobId;
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) BlobType(com.github.ambry.messageformat.BlobType) BlobProperties(com.github.ambry.messageformat.BlobProperties) PutRequest(com.github.ambry.protocol.PutRequest) ByteBuf(io.netty.buffer.ByteBuf) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo) PutResponse(com.github.ambry.protocol.PutResponse) BlobId(com.github.ambry.commons.BlobId) ByteBuffer(java.nio.ByteBuffer)

Example 27 with RequestInfo

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

the class InMemoryCloudDestinationErrorSimulationTest method testDeleteBlobErrorSimulation.

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

Example 28 with RequestInfo

use of com.github.ambry.network.RequestInfo 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 29 with RequestInfo

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

the class InMemoryCloudDestinationErrorSimulationTest method sendAndWaitForResponses.

/**
 * Submit all the requests that were handed over by the operation and wait until a response is received for every
 * one of them.
 * @param requestInfo the request handed over by the operation.
 * @return the response from the network client.
 */
private ResponseInfo sendAndWaitForResponses(RequestInfo requestInfo) {
    List<RequestInfo> requestList = new ArrayList<>();
    requestList.add(requestInfo);
    int sendCount = requestList.size();
    List<ResponseInfo> responseList = new ArrayList<>();
    responseList.addAll(mockNetworkClient.sendAndPoll(requestList, Collections.emptySet(), 100));
    requestList.clear();
    while (responseList.size() < sendCount) {
        responseList.addAll(mockNetworkClient.sendAndPoll(requestList, Collections.emptySet(), 100));
    }
    Assert.assertEquals("Only one request and response", responseList.size(), 1);
    ResponseInfo responseInfo = responseList.get(0);
    return responseInfo;
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) PartitionResponseInfo(com.github.ambry.protocol.PartitionResponseInfo) ArrayList(java.util.ArrayList) PartitionRequestInfo(com.github.ambry.protocol.PartitionRequestInfo) RequestInfo(com.github.ambry.network.RequestInfo)

Example 30 with RequestInfo

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

the class Http2ClientStreamStatsHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, Http2Frame frame) throws Exception {
    ReferenceCountUtil.retain(frame);
    RequestInfo requestInfo = ctx.channel().attr(Http2NetworkClient.REQUEST_INFO).get();
    requestInfo.responseFramesCount++;
    long time = System.currentTimeMillis() - requestInfo.getStreamSendTime();
    if (frame instanceof Http2HeadersFrame) {
        http2ClientMetrics.http2StreamRoundTripTime.update(time);
        requestInfo.setStreamHeaderFrameReceiveTime(System.currentTimeMillis());
        logger.debug("Header Frame received. Time from send: {}ms. Request: {}", time, requestInfo);
    } else if (frame instanceof Http2DataFrame) {
        logger.debug("Data Frame size: {}. Time from send: {}ms. Request: {}", ((Http2DataFrame) frame).content().readableBytes(), time, requestInfo);
    }
    if (frame instanceof Http2DataFrame && ((Http2DataFrame) frame).isEndStream()) {
        http2ClientMetrics.http2StreamFirstToLastFrameTime.update(time);
        http2ClientMetrics.http2ResponseFrameCount.update(requestInfo.responseFramesCount);
        logger.debug("All Frame received. Time from send: {}ms. Request: {}", time, requestInfo);
    }
    ctx.fireChannelRead(frame);
}
Also used : Http2DataFrame(io.netty.handler.codec.http2.Http2DataFrame) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) RequestInfo(com.github.ambry.network.RequestInfo)

Aggregations

RequestInfo (com.github.ambry.network.RequestInfo)45 ResponseInfo (com.github.ambry.network.ResponseInfo)31 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)14 GetResponse (com.github.ambry.protocol.GetResponse)12 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)11 PutResponse (com.github.ambry.protocol.PutResponse)10 ReplicaId (com.github.ambry.clustermap.ReplicaId)8 BlobId (com.github.ambry.commons.BlobId)8 Port (com.github.ambry.network.Port)8 PartitionResponseInfo (com.github.ambry.protocol.PartitionResponseInfo)7 BlobProperties (com.github.ambry.messageformat.BlobProperties)6 TtlUpdateResponse (com.github.ambry.protocol.TtlUpdateResponse)6 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)6 DataInputStream (java.io.DataInputStream)6 DeleteResponse (com.github.ambry.protocol.DeleteResponse)5 GetRequest (com.github.ambry.protocol.GetRequest)5 UndeleteResponse (com.github.ambry.protocol.UndeleteResponse)5 InMemAccountService (com.github.ambry.account.InMemAccountService)4 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)4