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();
}
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);
}
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;
}
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();
}
}
}
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);
}
}
Aggregations