Search in sources :

Example 41 with ResponseInfo

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

the class TtlUpdateNotificationSystem method sendRequestsGetResponses.

// helpers
// general
/**
 * Sends all the requests that the {@code manager} may have ready
 * @param futureResult the {@link FutureResult} that tracks the operation
 * @param manager the {@link TtlUpdateManager} to poll for requests
 * @param advanceTime if {@code true}, advances time after each poll and handleResponse iteration
 * @param ignoreUnrecognizedRequests if {@code true}, doesn't throw an exception if a response is received for a
 *                                   request not sent in this execution of the function
 */
private void sendRequestsGetResponses(FutureResult<Void> futureResult, TtlUpdateManager manager, boolean advanceTime, boolean ignoreUnrecognizedRequests) {
    List<RequestInfo> requestInfoList = new ArrayList<>();
    Set<Integer> requestsToDrop = new HashSet<>();
    Set<RequestInfo> requestAcks = new HashSet<>();
    List<RequestInfo> referenceRequestInfos = new ArrayList<>();
    while (!futureResult.isDone()) {
        manager.poll(requestInfoList, requestsToDrop);
        referenceRequestInfos.addAll(requestInfoList);
        List<ResponseInfo> responseInfoList = new ArrayList<>();
        try {
            responseInfoList = networkClient.sendAndPoll(requestInfoList, requestsToDrop, AWAIT_TIMEOUT_MS);
        } catch (RuntimeException | Error e) {
            if (!advanceTime) {
                throw e;
            }
        }
        for (ResponseInfo responseInfo : responseInfoList) {
            RequestInfo requestInfo = responseInfo.getRequestInfo();
            assertNotNull("RequestInfo is null", requestInfo);
            if (!referenceRequestInfos.contains(requestInfo)) {
                if (ignoreUnrecognizedRequests) {
                    continue;
                }
                throw new IllegalStateException("Received response for unrecognized request");
            } else if (requestAcks.contains(requestInfo)) {
                // received a second response for the same request
                throw new IllegalStateException("Received response more than once for a request");
            }
            requestAcks.add(requestInfo);
            RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
            RequestOrResponseType type = ((RequestOrResponse) routerRequestInfo.getRequest()).getRequestType();
            switch(type) {
                case TtlUpdateRequest:
                    manager.handleResponse(responseInfo);
                    break;
                default:
                    throw new IllegalStateException("Unrecognized request type: " + type);
            }
        }
        if (advanceTime) {
            time.sleep(ADVANCE_TIME_INCREMENT_MS);
        }
        responseInfoList.forEach(ResponseInfo::release);
        requestInfoList.clear();
    }
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) RequestOrResponseType(com.github.ambry.protocol.RequestOrResponseType) ArrayList(java.util.ArrayList) RequestInfo(com.github.ambry.network.RequestInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) HashSet(java.util.HashSet)

Example 42 with ResponseInfo

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

the class ServerAdminTool method controlRequest.

/**
 * Sends a {@link RequestControlAdminRequest} to set the enable state of {@code toControl} on {@code partitionIdStr}
 * to {@code enable} in {@code dataNodeId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param partitionId the {@link PartitionId} to control requests to. Can be {@code null}.
 * @param toControl the {@link RequestOrResponseType} to control.
 * @param enable the enable (or disable) status required for {@code toControl}.
 * @return the {@link ServerErrorCode} that is returned.
 * @throws IOException
 * @throws TimeoutException
 */
public ServerErrorCode controlRequest(DataNodeId dataNodeId, PartitionId partitionId, RequestOrResponseType toControl, boolean enable) throws IOException, TimeoutException {
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.RequestControl, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
    RequestControlAdminRequest controlRequest = new RequestControlAdminRequest(toControl, enable, adminRequest);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, controlRequest);
    AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
    response.release();
    return adminResponse.getError();
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest)

Example 43 with ResponseInfo

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

the class ServerAdminTool method controlBlobStore.

/**
 * Sends a {@link BlobStoreControlAdminRequest} to start or stop a store associated with {@code partitionId}
 * on {@code dataNodeId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param partitionId the {@link PartitionId} to start or stop.
 * @param numReplicasCaughtUpPerPartition the minimum number of peers should catch up with partition if the store is
 *                                        being stopped
 * @param storeControlRequestType the type of control operation that will performed on certain store.
 * @return the {@link ServerErrorCode} that is returned.
 * @throws IOException
 * @throws TimeoutException
 */
private ServerErrorCode controlBlobStore(DataNodeId dataNodeId, PartitionId partitionId, short numReplicasCaughtUpPerPartition, BlobStoreControlAction storeControlRequestType) throws IOException, TimeoutException {
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
    BlobStoreControlAdminRequest controlRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, storeControlRequestType, adminRequest);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, controlRequest);
    AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
    response.release();
    return adminResponse.getError();
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Example 44 with ResponseInfo

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

the class ServerAdminTool method controlReplication.

/**
 * Sends a {@link ReplicationControlAdminRequest} to enable/disable replication from {@code origins} for
 * {@code partitionIdStr} in {@code dataNodeId}.
 * @param dataNodeId the {@link DataNodeId} to contact.
 * @param partitionId the {@link PartitionId} to control replication for. Can be {@code null}.
 * @param origins the names of the datacenters from which replication should be controlled.
 * @param enable the enable (or disable) status required for replication from {@code origins}.
 * @return the {@link ServerErrorCode} that is returned.
 * @throws IOException
 * @throws TimeoutException
 */
public ServerErrorCode controlReplication(DataNodeId dataNodeId, PartitionId partitionId, List<String> origins, boolean enable) throws IOException, TimeoutException {
    AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
    ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(origins, enable, adminRequest);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, controlRequest);
    AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
    response.release();
    return adminResponse.getError();
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest)

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