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