Search in sources :

Example 6 with ClusterParticipant

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

the class ParticipantsConsistencyChecker method run.

@Override
public void run() {
    logger.debug("Participant consistency checker is initiated. Participants count = {}", participants.size());
    try {
        // when code reaches here, it means there are at least two participants.
        ClusterParticipant clusterParticipant = participants.get(0);
        Set<String> sealedReplicas1 = new HashSet<>(clusterParticipant.getSealedReplicas());
        Set<String> stoppedReplicas1 = new HashSet<>(clusterParticipant.getStoppedReplicas());
        for (int i = 1; i < participants.size(); ++i) {
            logger.debug("Checking sealed replica list");
            Set<String> sealedReplicas2 = new HashSet<>(participants.get(i).getSealedReplicas());
            if (!sealedReplicas1.equals(sealedReplicas2)) {
                logger.warn("Mismatch in sealed replicas. Set {} is different from set {}", sealedReplicas1, sealedReplicas2);
                metrics.sealedReplicasMismatchCount.inc();
            }
            logger.debug("Checking stopped replica list");
            Set<String> stoppedReplicas2 = new HashSet<>(participants.get(i).getStoppedReplicas());
            if (!stoppedReplicas1.equals(stoppedReplicas2)) {
                logger.warn("Mismatch in stopped replicas. Set {} is different from set {}", stoppedReplicas1, stoppedReplicas2);
                metrics.stoppedReplicasMismatchCount.inc();
            }
        }
    } catch (Throwable t) {
        logger.error("Exception occurs when running consistency checker ", t);
    }
}
Also used : ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) HashSet(java.util.HashSet)

Example 7 with ClusterParticipant

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

the class ParticipantsConsistencyTest method participantsWithMismatchTest.

/**
 * Test that there is a mismatch between two participants.
 * @throws Exception
 */
@Test
public void participantsWithMismatchTest() throws Exception {
    List<ClusterParticipant> participants = new ArrayList<>();
    // create a latch with init value = 2 and add it to second participant. This latch will count down under certain condition
    CountDownLatch invocationLatch = new CountDownLatch(2);
    MockClusterParticipant participant1 = new MockClusterParticipant(new ArrayList<>(), new ArrayList<>(), null, null);
    MockClusterParticipant participant2 = new MockClusterParticipant(new ArrayList<>(), new ArrayList<>(), null, invocationLatch);
    participants.add(participant1);
    participants.add(participant2);
    clusterAgentsFactory.setClusterParticipants(participants);
    AmbryServer server = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, notificationSystem, time);
    server.startup();
    // initially, two participants have consistent sealed/stopped replicas. Verify that:
    // 1. checker is instantiated 2. no mismatch event is emitted.
    assertNotNull("The mismatch metric should be created", server.getServerMetrics().sealedReplicasMismatchCount);
    assertEquals("Sealed replicas mismatch count should be 0", 0, server.getServerMetrics().sealedReplicasMismatchCount.getCount());
    assertEquals("Stopped replicas mismatch count should be 0", 0, server.getServerMetrics().stoppedReplicasMismatchCount.getCount());
    // induce mismatch for sealed and stopped replica list
    // add 1 sealed replica to participant1
    ReplicaId mockReplica1 = Mockito.mock(ReplicaId.class);
    when(mockReplica1.getReplicaPath()).thenReturn("12");
    participant1.setReplicaSealedState(mockReplica1, true);
    // add 1 stopped replica to participant2
    ReplicaId mockReplica2 = Mockito.mock(ReplicaId.class);
    when(mockReplica2.getReplicaPath()).thenReturn("4");
    participant2.setReplicaStoppedState(Collections.singletonList(mockReplica2), true);
    assertTrue("The latch didn't count to zero within 5 secs", invocationLatch.await(5, TimeUnit.SECONDS));
    assertTrue("Sealed replicas mismatch count should be non-zero", server.getServerMetrics().sealedReplicasMismatchCount.getCount() > 0);
    assertTrue("Stopped replicas mismatch count should be non-zero", server.getServerMetrics().stoppedReplicasMismatchCount.getCount() > 0);
    server.shutdown();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) ReplicaId(com.github.ambry.clustermap.ReplicaId) Test(org.junit.Test)

Example 8 with ClusterParticipant

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

the class ParticipantsConsistencyTest method consistencyCheckerDisabledTest.

/**
 * Test that consistency checker should be disabled in some scenarios.
 */
@Test
public void consistencyCheckerDisabledTest() throws Exception {
    // 1. only one participant, consistency checker should be disabled
    AmbryServer server = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, notificationSystem, time);
    server.startup();
    assertNull("The mismatch metric should not be created", server.getServerMetrics().stoppedReplicasMismatchCount);
    server.shutdown();
    // 2. there are two participants but period of checker is zero, consistency checker should be disabled.
    props.setProperty("server.participants.consistency.checker.period.sec", Long.toString(0L));
    List<ClusterParticipant> participants = new ArrayList<>();
    for (int i = 0; i < 2; ++i) {
        participants.add(new MockClusterParticipant(Collections.emptyList(), Collections.emptyList(), null, null));
    }
    clusterAgentsFactory.setClusterParticipants(participants);
    server = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, notificationSystem, time);
    server.startup();
    assertNull("The mismatch metric should not be created", server.getServerMetrics().stoppedReplicasMismatchCount);
    server.shutdown();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ArrayList(java.util.ArrayList) ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) Test(org.junit.Test)

Example 9 with ClusterParticipant

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

the class ParticipantsConsistencyTest method participantsWithNoMismatchTest.

/**
 * Test that two participants are consistent in terms of sealed/stopped replicas.
 * @throws Exception
 */
@Test
public void participantsWithNoMismatchTest() throws Exception {
    List<String> sealedReplicas = new ArrayList<>(Arrays.asList("10", "1", "4"));
    List<String> stoppedReplicas = new ArrayList<>();
    List<ClusterParticipant> participants = new ArrayList<>();
    // create a latch with init value = 2 to ensure both getSealedReplicas and getStoppedReplicas get called at least once
    CountDownLatch invocationLatch = new CountDownLatch(2);
    MockClusterParticipant participant1 = new MockClusterParticipant(sealedReplicas, stoppedReplicas, invocationLatch, null);
    MockClusterParticipant participant2 = new MockClusterParticipant(sealedReplicas, stoppedReplicas, null, null);
    participants.add(participant1);
    participants.add(participant2);
    clusterAgentsFactory.setClusterParticipants(participants);
    AmbryServer server = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, notificationSystem, time);
    server.startup();
    assertTrue("The latch didn't count to zero within 5 secs", invocationLatch.await(5, TimeUnit.SECONDS));
    // verify that: 1. checker is instantiated 2.no mismatch event is emitted.
    assertNotNull("The mismatch metric should be created", server.getServerMetrics().sealedReplicasMismatchCount);
    assertEquals("Sealed replicas mismatch count should be 0", 0, server.getServerMetrics().sealedReplicasMismatchCount.getCount());
    assertEquals("Stopped replicas mismatch count should be 0", 0, server.getServerMetrics().stoppedReplicasMismatchCount.getCount());
    server.shutdown();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) Test(org.junit.Test)

Example 10 with ClusterParticipant

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

the class StorageManagerTest method skipStoppedStoresTest.

/**
 * Test the stopped stores are correctly skipped and not started during StorageManager's startup.
 */
@Test
public void skipStoppedStoresTest() throws Exception {
    MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
    List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
    ClusterParticipant mockParticipant = new MockClusterParticipant();
    mockParticipant.setReplicaStoppedState(Collections.singletonList(replicas.get(0)), true);
    StorageManager storageManager = createStorageManager(dataNode, metricRegistry, Collections.singletonList(mockParticipant));
    storageManager.start();
    assertEquals("There should be no unexpected partitions reported", 0, getNumUnrecognizedPartitionsReported());
    for (int i = 0; i < replicas.size(); ++i) {
        PartitionId id = replicas.get(i).getPartitionId();
        if (i == 0) {
            assertNull("Store should be null because stopped stores will be skipped and will not be started", storageManager.getStore(id, false));
            assertFalse("Compaction should not be scheduled", storageManager.scheduleNextForCompaction(id));
        } else {
            Store store = storageManager.getStore(id, false);
            assertTrue("Store should be started", store.isStarted());
            assertTrue("Compaction should be scheduled", storageManager.scheduleNextForCompaction(id));
        }
    }
    shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
Also used : MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) AccountStatsStore(com.github.ambry.accountstats.AccountStatsStore) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) ReplicaId(com.github.ambry.clustermap.ReplicaId) ClusterParticipant(com.github.ambry.clustermap.ClusterParticipant) BlobStoreTest(com.github.ambry.store.BlobStoreTest) Test(org.junit.Test)

Aggregations

ClusterParticipant (com.github.ambry.clustermap.ClusterParticipant)10 Test (org.junit.Test)8 ReplicaId (com.github.ambry.clustermap.ReplicaId)5 VerifiableProperties (com.github.ambry.config.VerifiableProperties)5 ArrayList (java.util.ArrayList)5 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)4 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)4 PartitionId (com.github.ambry.clustermap.PartitionId)4 BlobStoreTest (com.github.ambry.store.BlobStoreTest)4 StoreConfig (com.github.ambry.config.StoreConfig)3 HashSet (java.util.HashSet)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 InMemAccountService (com.github.ambry.account.InMemAccountService)2 AccountStatsStore (com.github.ambry.accountstats.AccountStatsStore)2 DataNodeId (com.github.ambry.clustermap.DataNodeId)2 StateTransitionException (com.github.ambry.clustermap.StateTransitionException)2 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)2 DiskManagerConfig (com.github.ambry.config.DiskManagerConfig)2 File (java.io.File)2 IOException (java.io.IOException)2