Search in sources :

Example 46 with ReplicaId

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;
}
Also used : ArrayList(java.util.ArrayList) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Example 47 with ReplicaId

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());
}
Also used : MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Example 48 with ReplicaId

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());
}
Also used : MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Example 49 with ReplicaId

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());
}
Also used : MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Example 50 with ReplicaId

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);
}
Also used : ArrayList(java.util.ArrayList) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) MockReplicaId(com.github.ambry.clustermap.MockReplicaId) ReplicaId(com.github.ambry.clustermap.ReplicaId)

Aggregations

ReplicaId (com.github.ambry.clustermap.ReplicaId)147 Test (org.junit.Test)83 PartitionId (com.github.ambry.clustermap.PartitionId)68 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)60 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)57 ArrayList (java.util.ArrayList)55 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)43 DataNodeId (com.github.ambry.clustermap.DataNodeId)32 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)31 MetricRegistry (com.codahale.metrics.MetricRegistry)29 HashMap (java.util.HashMap)28 HashSet (java.util.HashSet)25 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)24 VerifiableProperties (com.github.ambry.config.VerifiableProperties)24 BlobStoreTest (com.github.ambry.store.BlobStoreTest)24 File (java.io.File)24 List (java.util.List)21 Map (java.util.Map)21 Port (com.github.ambry.network.Port)20 Properties (java.util.Properties)20