Search in sources :

Example 66 with DataNodeId

use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.

the class ReplicationTestHelper method getNewReplicaToAdd.

protected ReplicaId getNewReplicaToAdd(MockClusterMap clusterMap) {
    DataNodeId currentNode = clusterMap.getDataNodeIds().get(0);
    PartitionId newPartition = clusterMap.createNewPartition(clusterMap.getDataNodes());
    return newPartition.getReplicaIds().stream().filter(r -> r.getDataNodeId() == currentNode).findFirst().get();
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) DataNodeId(com.github.ambry.clustermap.DataNodeId)

Example 67 with DataNodeId

use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.

the class ReplicationTestHelper method createStorageManagerAndReplicationManager.

/**
 * Helper method to create storage manager and replication manager
 * @param clusterMap {@link ClusterMap} to use
 * @param clusterMapConfig {@link ClusterMapConfig} to use
 * @param clusterParticipant {@link com.github.ambry.clustermap.ClusterParticipant} for listener registration.
 * @return a pair of storage manager and replication manager
 * @throws Exception
 */
protected Pair<StorageManager, ReplicationManager> createStorageManagerAndReplicationManager(ClusterMap clusterMap, ClusterMapConfig clusterMapConfig, MockHelixParticipant clusterParticipant, ConnectionPool mockConnectionPool) throws Exception {
    StoreConfig storeConfig = new StoreConfig(verifiableProperties);
    DataNodeId dataNodeId = clusterMap.getDataNodeIds().get(0);
    MockStoreKeyConverterFactory storeKeyConverterFactory = new MockStoreKeyConverterFactory(null, null);
    storeKeyConverterFactory.setConversionMap(new HashMap<>());
    storeKeyConverterFactory.setReturnInputIfAbsent(true);
    StoreKeyFactory storeKeyFactory = new BlobIdFactory(clusterMap);
    StorageManager storageManager = new StorageManager(storeConfig, new DiskManagerConfig(verifiableProperties), Utils.newScheduler(1, true), new MetricRegistry(), null, clusterMap, dataNodeId, null, clusterParticipant == null ? null : Collections.singletonList(clusterParticipant), new MockTime(), null, new InMemAccountService(false, false));
    storageManager.start();
    MockReplicationManager replicationManager = new MockReplicationManager(replicationConfig, clusterMapConfig, storeConfig, storageManager, clusterMap, dataNodeId, storeKeyConverterFactory, clusterParticipant, mockConnectionPool, new MockFindTokenHelper(storeKeyFactory, replicationConfig), BlobIdTransformer.class.getName(), storeKeyFactory, time);
    return new Pair<>(storageManager, replicationManager);
}
Also used : DiskManagerConfig(com.github.ambry.config.DiskManagerConfig) MockStoreKeyConverterFactory(com.github.ambry.store.MockStoreKeyConverterFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) StorageManager(com.github.ambry.store.StorageManager) BlobIdFactory(com.github.ambry.commons.BlobIdFactory) StoreKeyFactory(com.github.ambry.store.StoreKeyFactory) InMemAccountService(com.github.ambry.account.InMemAccountService) StoreConfig(com.github.ambry.config.StoreConfig) DataNodeId(com.github.ambry.clustermap.DataNodeId) MockTime(com.github.ambry.utils.MockTime) Pair(com.github.ambry.utils.Pair)

Example 68 with DataNodeId

use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.

the class AdaptiveOperationTracker method getLatencyHistogram.

/**
 * Gets the {@link Histogram} that tracks request latencies to the class of replicas (intra or inter DC) that
 * {@code replicaId} belongs to.
 * @param replicaId the {@link ReplicaId} whose request latency is going to be tracked.
 * @return the {@link CachedHistogram} associated with this replica.
 */
CachedHistogram getLatencyHistogram(ReplicaId replicaId) {
    boolean isLocalReplica = replicaId.getDataNodeId().getDatacenterName().equals(datacenterName);
    CachedHistogram histogramToReturn;
    switch(routerConfig.routerOperationTrackerMetricScope) {
        case Datacenter:
            histogramToReturn = isLocalReplica ? localDcHistogram : crossDcHistogram;
            break;
        case Partition:
            PartitionId partitionId = replicaId.getPartitionId();
            histogramToReturn = isLocalReplica ? localDcResourceToHistogram.computeIfAbsent(partitionId, k -> createHistogram(routerConfig, false)) : crossDcResourceToHistogram.computeIfAbsent(partitionId, k -> createHistogram(routerConfig, false));
            break;
        case DataNode:
            DataNodeId dataNodeId = replicaId.getDataNodeId();
            histogramToReturn = isLocalReplica ? localDcResourceToHistogram.computeIfAbsent(dataNodeId, k -> createHistogram(routerConfig, false)) : crossDcResourceToHistogram.computeIfAbsent(dataNodeId, k -> createHistogram(routerConfig, false));
            break;
        case Disk:
            DiskId diskId = replicaId.getDiskId();
            histogramToReturn = isLocalReplica ? localDcResourceToHistogram.computeIfAbsent(diskId, k -> createHistogram(routerConfig, false)) : crossDcResourceToHistogram.computeIfAbsent(diskId, k -> createHistogram(routerConfig, false));
            break;
        default:
            throw new IllegalArgumentException("Unsupported operation tracker metric scope.");
    }
    return histogramToReturn;
}
Also used : PartitionId(com.github.ambry.clustermap.PartitionId) DataNodeId(com.github.ambry.clustermap.DataNodeId) CachedHistogram(com.github.ambry.utils.CachedHistogram) DiskId(com.github.ambry.clustermap.DiskId)

Example 69 with DataNodeId

use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.

the class BackgroundDeleter method onResponse.

/**
 * Handle the response from polling the {@link NetworkClient}.
 * @param responseInfoList the list of {@link ResponseInfo} containing the responses.
 */
protected void onResponse(List<ResponseInfo> responseInfoList) {
    for (ResponseInfo responseInfo : responseInfoList) {
        try {
            RequestInfo requestInfo = responseInfo.getRequestInfo();
            if (requestInfo == null) {
                // If requestInfo is null, it means request has been failed previously due to long wait in pending requests
                // queue. The failed request was already handled by one of the managers(PutManager, GetManager, etc). Current
                // response comes from timed-out connection associated with previous request. Router only needs to notify
                // responseHandler to mark the data node resource down.
                DataNodeId dataNodeId = responseInfo.getDataNode();
                responseHandler.onConnectionTimeout(dataNodeId);
            } else {
                long responseReceiveTime = requestInfo.getStreamHeaderFrameReceiveTime();
                if (responseReceiveTime != -1) {
                    routerMetrics.responseReceiveToHandleLatencyMs.update(System.currentTimeMillis() - responseReceiveTime);
                }
                RequestOrResponseType type = ((RequestOrResponse) requestInfo.getRequest()).getRequestType();
                logger.debug("Handling response of type {} for {}", type, requestInfo.getRequest().getCorrelationId());
                switch(type) {
                    case PutRequest:
                        putManager.handleResponse(responseInfo);
                        break;
                    case GetRequest:
                        getManager.handleResponse(responseInfo);
                        break;
                    case DeleteRequest:
                        deleteManager.handleResponse(responseInfo);
                        break;
                    case TtlUpdateRequest:
                        ttlUpdateManager.handleResponse(responseInfo);
                        break;
                    case UndeleteRequest:
                        undeleteManager.handleResponse(responseInfo);
                        break;
                    default:
                        logger.error("Unexpected response type: {} received, discarding", type);
                }
            }
        } catch (Exception e) {
            logger.error("Unexpected error received while handling a response: ", e);
            routerMetrics.operationManagerHandleResponseErrorCount.inc();
        }
    }
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) RequestOrResponseType(com.github.ambry.protocol.RequestOrResponseType) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) RequestInfo(com.github.ambry.network.RequestInfo) DataNodeId(com.github.ambry.clustermap.DataNodeId) IOException(java.io.IOException)

Example 70 with DataNodeId

use of com.github.ambry.clustermap.DataNodeId in project ambry by linkedin.

the class NonBlockingRouterTest method testWarmUpConnectionFailureHandling.

/**
 * Test that Response Handler correctly handles disconnected connections after warming up.
 */
@Test
public void testWarmUpConnectionFailureHandling() throws Exception {
    try {
        Properties props = getNonBlockingRouterProperties("DC3");
        MockServerLayout mockServerLayout = new MockServerLayout(mockClusterMap);
        mockSelectorState.set(MockSelectorState.FailConnectionInitiationOnPoll);
        setRouter(props, mockServerLayout, new LoggingNotificationSystem());
        for (DataNodeId node : mockClusterMap.getDataNodes()) {
            assertTrue("Node should be marked as timed out by ResponseHandler.", ((MockDataNodeId) node).isTimedOut());
        }
    } finally {
        if (router != null) {
            router.close();
        }
        mockSelectorState.set(MockSelectorState.Good);
    }
}
Also used : LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DataNodeId(com.github.ambry.clustermap.DataNodeId) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Test(org.junit.Test)

Aggregations

DataNodeId (com.github.ambry.clustermap.DataNodeId)92 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)45 HashMap (java.util.HashMap)29 PartitionId (com.github.ambry.clustermap.PartitionId)28 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)27 ReplicaId (com.github.ambry.clustermap.ReplicaId)25 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)23 VerifiableProperties (com.github.ambry.config.VerifiableProperties)23 MetricRegistry (com.codahale.metrics.MetricRegistry)22 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)22 List (java.util.List)22 Map (java.util.Map)22 Port (com.github.ambry.network.Port)21 ClusterMap (com.github.ambry.clustermap.ClusterMap)20 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)19 StoreKeyFactory (com.github.ambry.store.StoreKeyFactory)18 BlobIdFactory (com.github.ambry.commons.BlobIdFactory)17 HashSet (java.util.HashSet)16 Properties (java.util.Properties)16