use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class OperationTrackerTest method buildOperationTrackerWithStateTransitionTest.
/**
* Test cases where some replicas have changed their state in the middle of constructing operation tracker. The code
* should be able to get correct number of replicas even with concurrent state transition. The most common case is
* replica changes from OFFLINE to BOOTSTRAP/STANDBY while the replica pool is being populated in the tracker.
*/
@Test
public void buildOperationTrackerWithStateTransitionTest() {
assumeTrue(replicasStateEnabled);
initialize();
originatingDcName = localDcName;
// pick one replica from originating dc and set it to OFFLINE initially
ReplicaId originatingReplica = mockPartition.replicaIds.stream().filter(r -> r.getDataNodeId().getDatacenterName().equals(localDcName)).findAny().get();
// pick another replica from remote dc and set it to OFFLINE initially
ReplicaId remoteReplica = mockPartition.replicaIds.stream().filter(r -> !r.getDataNodeId().getDatacenterName().equals(localDcName)).findAny().get();
mockPartition.replicaAndState.put(remoteReplica, ReplicaState.OFFLINE);
mockPartition.replicaAndState.put(originatingReplica, ReplicaState.OFFLINE);
// induce concurrent state transition between "getEligibleReplicas()" and "routerOperationTrackerIncludeDownReplicas"
mockPartition.resetReplicaStateCount = 5;
mockPartition.resetAllReplicasToStandbyState = true;
SimpleOperationTracker ot = (SimpleOperationTracker) getOperationTracker(true, 2, 3, RouterOperation.GetBlobOperation, true);
assertEquals("Mismatch in replica count in the pool", 12, ot.getReplicaPoolSize());
Iterator<ReplicaId> iterator = ot.getReplicaIterator();
List<ReplicaId> orderedReplicas = new ArrayList<>();
while (iterator.hasNext()) {
orderedReplicas.add(iterator.next());
}
assertEquals("Mismatch in last replica", remoteReplica, orderedReplicas.get(orderedReplicas.size() - 1));
assertEquals("Mismatch in last but one replica", originatingReplica, orderedReplicas.get(orderedReplicas.size() - 2));
mockPartition.resetAllReplicasToStandbyState = false;
}
use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class OperationTrackerTest method replicasOrderingTestOriginatingNotLocal.
/**
* Test to ensure that replicas in originating DC are right after local DC replicas.
*/
@Test
public void replicasOrderingTestOriginatingNotLocal() {
initialize();
originatingDcName = datanodes.get(datanodes.size() - 1).getDatacenterName();
OperationTracker ot = getOperationTracker(true, 3, 6, RouterOperation.GetBlobOperation, true);
sendRequests(ot, 6, false);
for (int i = 0; i < 3; i++) {
ReplicaId replica = inflightReplicas.poll();
// fail first 3 requests to local
ot.onResponse(replica, TrackedRequestFinalState.FAILURE);
assertEquals("Should be local DC", localDcName, replica.getDataNodeId().getDatacenterName());
}
assertFalse("Operation should have not succeeded", ot.hasSucceeded());
for (int i = 0; i < 3; i++) {
ReplicaId replica = inflightReplicas.poll();
ot.onResponse(replica, TrackedRequestFinalState.SUCCESS);
assertEquals("Should be originating DC", originatingDcName, replica.getDataNodeId().getDatacenterName());
}
assertEquals("Should have 0 replica in flight.", 0, inflightReplicas.size());
assertTrue("Operation should have succeeded", ot.hasSucceeded());
assertTrue("Operation should be done", ot.isDone());
}
use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class OperationTrackerTest method blobNotFoundInOriginDcAndCrossColoDisabledTest.
/**
* Test the case when NotFound Error should be disabled since the cross colo is disabled.
*/
@Test
public void blobNotFoundInOriginDcAndCrossColoDisabledTest() {
initialize();
originatingDcName = datanodes.get(datanodes.size() - 1).getDatacenterName();
OperationTracker ot = getOperationTracker(false, 1, 3, RouterOperation.GetBlobOperation, true);
sendRequests(ot, 3, false);
assertEquals("Should have 3 replicas", 3, inflightReplicas.size());
for (int i = 0; i < 3; i++) {
ReplicaId replica = inflightReplicas.poll();
// fail first 3 requests to local replicas
ot.onResponse(replica, TrackedRequestFinalState.NOT_FOUND);
assertEquals("Should be local DC", localDcName, replica.getDataNodeId().getDatacenterName());
}
assertFalse("Operation should have not succeeded", ot.hasSucceeded());
assertFalse("Operation should have not failed on NOT_FOUND", ot.hasFailedOnNotFound());
assertTrue("Operation should be done", ot.isDone());
}
use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class OperationTrackerTest method replicasOrderingTestOriginatingIsLocal.
/**
* Test to ensure that replicas in originating DC are first priority when originating DC is local DC.
*/
@Test
public void replicasOrderingTestOriginatingIsLocal() {
initialize();
originatingDcName = localDcName;
OperationTracker ot = getOperationTracker(true, 3, 3, RouterOperation.GetBlobOperation, true);
sendRequests(ot, 3, false);
for (int i = 0; i < 3; i++) {
ReplicaId replica = inflightReplicas.poll();
ot.onResponse(replica, TrackedRequestFinalState.SUCCESS);
assertEquals("Should be originating DC", originatingDcName, replica.getDataNodeId().getDatacenterName());
}
assertEquals("Should have 0 replica in flight.", 0, inflightReplicas.size());
assertTrue("Operation should have succeeded", ot.hasSucceeded());
assertTrue("Operation should be done", ot.isDone());
}
use of com.github.ambry.clustermap.ReplicaId in project ambry by linkedin.
the class OperationTrackerTest method testReplicaDown.
/**
* Test replica down scenario
* @param totalReplicaCount total replicas for the partition.
* @param downReplicaCount partitions to be marked down.
*/
private void testReplicaDown(int totalReplicaCount, int downReplicaCount) {
List<Boolean> downStatus = new ArrayList<>(totalReplicaCount);
for (int i = 0; i < downReplicaCount; i++) {
downStatus.add(true);
}
for (int i = downReplicaCount; i < totalReplicaCount; i++) {
downStatus.add(false);
}
Collections.shuffle(downStatus);
List<ReplicaId> mockReplicaIds = mockPartition.getReplicaIds();
for (int i = 0; i < totalReplicaCount; i++) {
((MockReplicaId) mockReplicaIds.get(i)).markReplicaDownStatus(downStatus.get(i));
}
localDcName = datanodes.get(0).getDatacenterName();
OperationTracker ot = getOperationTracker(true, 2, 3, RouterOperation.GetBlobOperation, true);
// The iterator should return all replicas, with the first half being the up replicas
// and the last half being the down replicas.
Iterator<ReplicaId> itr = ot.getReplicaIterator();
int count = 0;
while (itr.hasNext()) {
ReplicaId nextReplica = itr.next();
if (count < totalReplicaCount - downReplicaCount) {
assertFalse(nextReplica.isDown());
} else {
assertTrue(nextReplica.isDown());
}
count++;
}
assertEquals("Total replica count did not match expected", totalReplicaCount, count);
}
Aggregations