use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class ServerAdminTool method triggerCompaction.
/**
* Triggers compaction on {@code dataNodeId} for the partition defined in {@code partitionIdStr}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param partitionId the {@link PartitionId} to compact.
* @return the {@link ServerErrorCode} that is returned.
* @throws IOException
* @throws TimeoutException
*/
public ServerErrorCode triggerCompaction(DataNodeId dataNodeId, PartitionId partitionId) throws IOException, TimeoutException {
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.TriggerCompaction, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, adminRequest);
AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
response.release();
return adminResponse.getError();
}
use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class ServerAdminTool method isCaughtUp.
/**
* Sends a {@link CatchupStatusAdminRequest} for {@code partitionIdStr} to {@code dataNodeId}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param partitionId the {@link PartitionId} to check catchup status for. If {@code null}, status is for all
* partitions on {@code dataNodeId}
* @param acceptableLagInBytes that lag in bytes that is considered OK.
* @param numReplicasCaughtUpPerPartition the number of replicas that have to be within {@code acceptableLagInBytes}
* (per partition). The min of this value or the total count of replicas - 1 is
* considered.
* @return the {@link ServerErrorCode} and the catchup status that is returned if the error code is
* {@link ServerErrorCode#No_Error}, otherwise {@code false}.
* @throws IOException
* @throws TimeoutException
*/
public Pair<ServerErrorCode, Boolean> isCaughtUp(DataNodeId dataNodeId, PartitionId partitionId, long acceptableLagInBytes, short numReplicasCaughtUpPerPartition) throws IOException, TimeoutException {
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.CatchupStatus, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
CatchupStatusAdminRequest catchupStatusRequest = new CatchupStatusAdminRequest(acceptableLagInBytes, numReplicasCaughtUpPerPartition, adminRequest);
ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, catchupStatusRequest);
CatchupStatusAdminResponse adminResponse = CatchupStatusAdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
response.release();
return new Pair<>(adminResponse.getError(), adminResponse.getError() == ServerErrorCode.No_Error && adminResponse.isCaughtUp());
}
use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class ServerAdminTool method sendRequestGetResponse.
/**
* Sends {@code request} to {@code dataNodeId} and returns the response as a {@link ByteBuffer}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param partitionId the {@link PartitionId} associated with request.
* @param request the request to send.
* @return the response as a {@link ResponseInfo} if the response was successfully received. {@code null} otherwise.
* @throws TimeoutException
*/
private ResponseInfo sendRequestGetResponse(DataNodeId dataNodeId, PartitionId partitionId, SendWithCorrelationId request) throws TimeoutException {
ReplicaId replicaId = getReplicaFromNode(dataNodeId, partitionId);
String hostname = dataNodeId.getHostname();
Port port = dataNodeId.getPortToConnectTo();
String identifier = hostname + ":" + port.getPort();
RequestInfo requestInfo = new RequestInfo(hostname, port, request, replicaId, null);
List<RequestInfo> requestInfos = Collections.singletonList(requestInfo);
ResponseInfo responseInfo = null;
long startTimeMs = time.milliseconds();
do {
if (time.milliseconds() - startTimeMs > OPERATION_TIMEOUT_MS) {
throw new TimeoutException(identifier + ": Operation did not complete within " + OPERATION_TIMEOUT_MS + " ms");
}
List<ResponseInfo> responseInfos = networkClient.sendAndPoll(requestInfos, Collections.emptySet(), POLL_TIMEOUT_MS);
if (responseInfos.size() > 1) {
// May need to relax this check because response list may contain more than 1 response
throw new IllegalStateException("Received more than one response even though a single request was sent");
} else if (!responseInfos.isEmpty()) {
responseInfo = responseInfos.get(0);
}
requestInfos = Collections.emptyList();
} while (responseInfo == null);
if (responseInfo.getError() != null) {
throw new IllegalStateException(identifier + ": Encountered error while trying to send request - " + responseInfo.getError());
}
return responseInfo;
}
use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class InMemoryCloudDestinationErrorSimulationTest method testGetBlobInfoErrorSimulation.
/**
* test error simulation for GetBlobInfoRequest
* @throws Exception
*/
@Test
public void testGetBlobInfoErrorSimulation() throws Exception {
BlobId blobId = doPut(partitionId);
ArrayList<BlobId> blobIdList = new ArrayList<BlobId>();
blobIdList.add(blobId);
PartitionRequestInfo partitionRequestInfo = new PartitionRequestInfo(partitionId, blobIdList);
ArrayList<PartitionRequestInfo> partitionRequestInfoList = new ArrayList<PartitionRequestInfo>();
partitionRequestInfoList.add(partitionRequestInfo);
GetRequest getRequest = new GetRequest(1234, "clientId", MessageFormatFlags.BlobInfo, partitionRequestInfoList, GetOption.None);
RequestInfo requestInfo = new RequestInfo(hostname, port, getRequest, replica, null);
ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
GetResponse response = responseInfo.getError() == null ? (GetResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
PartitionResponseInfo partitionResponseInfo = response.getPartitionResponseInfoList().get(0);
Assert.assertEquals("GetBlobInfo should succeed.", response.getError(), ServerErrorCode.No_Error);
Assert.assertEquals("GetBlobInfo partitionResponseInfo should succeed.", partitionResponseInfo.getErrorCode(), ServerErrorCode.No_Error);
responseInfo.release();
// inject error for cloud colo.
cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.ID_Not_Found);
getRequest = new GetRequest(1234, "clientId", MessageFormatFlags.BlobInfo, partitionRequestInfoList, GetOption.None);
requestInfo = new RequestInfo(hostname, port, getRequest, replica, null);
responseInfo = sendAndWaitForResponses(requestInfo);
response = responseInfo.getError() == null ? (GetResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
partitionResponseInfo = response.getPartitionResponseInfoList().get(0);
Assert.assertEquals("GetBlobInfo responseInfo should have no error.", response.getError(), ServerErrorCode.No_Error);
Assert.assertEquals("GetBlobInfo partitionResponseInfo should be Blob_Not_Found", partitionResponseInfo.getErrorCode(), ServerErrorCode.Blob_Not_Found);
responseInfo.release();
}
use of com.github.ambry.network.ResponseInfo in project ambry by linkedin.
the class Http2ClientResponseHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
http2ClientMetrics.http2StreamExceptionCount.inc();
logger.info("Exception caught in Http2ClientResponseHandler {} {}. Closing stream channel. Cause: ", ctx.channel().hashCode(), ctx.channel(), cause);
RequestInfo requestInfo = releaseAndCloseStreamChannel(ctx.channel());
if (requestInfo != null) {
responseInfoQueue.put(new ResponseInfo(requestInfo, NetworkClientErrorCode.NetworkError, null));
// Will be removed from
}
}
Aggregations