use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class UndeleteOperationTrackerTest method failureWithIneligibleNodesTest.
/**
* Tests when there are ineligible hosts.
*/
@Test
public void failureWithIneligibleNodesTest() {
assumeTrue(replicasStateEnabled);
List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
List<String> mountPaths = Collections.singletonList("mockMountPath");
datanodes = new ArrayList<>(Arrays.asList(new MockDataNodeId(portList, mountPaths, "dc-0"), new MockDataNodeId(portList, mountPaths, "dc-1"), new MockDataNodeId(portList, mountPaths, "dc-2"), new MockDataNodeId(portList, mountPaths, "dc-3")));
mockPartition = new MockPartitionId();
populateReplicaList(8, ReplicaState.STANDBY);
populateReplicaList(4, ReplicaState.INACTIVE);
localDcName = datanodes.get(0).getDatacenterName();
mockClusterMap = new MockClusterMap(false, datanodes, 1, Collections.singletonList(mockPartition), localDcName);
// Now any of the failure would fail the operation
UndeleteOperationTracker tracker = getOperationTracker(2);
sendRequests(tracker, 2);
tracker.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.SUCCESS);
assertFalse("Operation should not have failed", tracker.hasFailed());
assertFalse("Operation should not have succeeded", tracker.hasSucceeded());
assertFalse("Operation should not be done", tracker.isDone());
tracker.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.FAILURE);
assertTrue("Operation should have failed", tracker.hasFailed());
assertFalse("Operation should not have succeeded", tracker.hasSucceeded());
assertTrue("Operation should be done", tracker.isDone());
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class CloudAndStoreReplicationTest method setup.
/**
* Create a cluster with one vcr node and two ambry server data nodes.
* @throws Exception on {@link Exception}
*/
@Before
public void setup() throws Exception {
String vcrMountPath = ClusterMapSnapshotConstants.CLOUD_REPLICA_MOUNT + "/1";
recoveryProperties = new Properties();
recoveryProperties.setProperty("replication.metadata.request.version", "2");
recoveryProperties.setProperty("replication.enabled.with.vcr.cluster", "true");
recoveryProperties.setProperty("clustermap.vcr.datacenter.name", cloudDc);
if (!vcrRecoveryPartitionConfig.isEmpty()) {
recoveryProperties.setProperty("vcr.recovery.partitions", vcrRecoveryPartitionConfig);
}
TestSSLUtils.addHttp2Properties(recoveryProperties, SSLFactory.Mode.SERVER, true);
// create vcr node
List<Port> vcrPortList = Arrays.asList(new Port(12310, PortType.PLAINTEXT), new Port(12410, PortType.SSL));
MockDataNodeId vcrNode = new MockDataNodeId("localhost", vcrPortList, Collections.singletonList(vcrMountPath), cloudDc);
// create ambry server recovery cluster
MockClusterMap serverClusterMap = new MockClusterMap(false, true, 2, 1, 1, true, false, null);
recoveryCluster = new MockCluster(serverClusterMap, Collections.singletonList(vcrNode), recoveryProperties);
partitionId = recoveryCluster.getClusterMap().getWritablePartitionIds(null).get(0);
allRecoveryNodes = serverClusterMap.getDataNodes();
// record ambry server node which will get partition leadership notification.
partitionLeaderRecoveryNode = allRecoveryNodes.get(0);
MockClusterAgentsFactory leaderMockClusterAgentsFactory = new MockClusterAgentsFactory(serverClusterMap, serverClusterMap.getAllPartitionIds(null).stream().map(PartitionId::toPathString).collect(Collectors.toList()));
// Start Helix Controller and ZK Server.
if (!zkInfo.isZkServerStarted()) {
zkInfo.startZkServer();
}
helixControllerManager = VcrTestUtil.populateZkInfoAndStartController(zkConnectString, vcrClusterName, recoveryCluster.getClusterMap());
Properties vcrProperties = VcrTestUtil.createVcrProperties(vcrNode.getDatacenterName(), vcrClusterName, zkConnectString, 12310, 12410, 12510, null);
vcrProperties.putAll(recoveryProperties);
MockNotificationSystem notificationSystem = new MockNotificationSystem(recoveryCluster.getClusterMap());
// Create blobs and data for upload to vcr.
int blobCount = 10;
cloudBlobIds = ServerTestUtil.createBlobIds(blobCount, recoveryCluster.getClusterMap(), accountId, containerId, partitionId);
serverBlobIds = ServerTestUtil.createBlobIds(blobCount, recoveryCluster.getClusterMap(), accountId, containerId, partitionId);
// Create cloud destination and start vcr server.
latchBasedInMemoryCloudDestination = new LatchBasedInMemoryCloudDestination(cloudBlobIds, recoveryCluster.getClusterMap());
CloudDestinationFactory cloudDestinationFactory = new LatchBasedInMemoryCloudDestinationFactory(latchBasedInMemoryCloudDestination);
vcrServer = VcrTestUtil.createVcrServer(new VerifiableProperties(vcrProperties), recoveryCluster.getClusterAgentsFactory(), notificationSystem, cloudDestinationFactory);
vcrServer.startup();
// initialize and start ambry servers
for (MockDataNodeId serverNode : allRecoveryNodes) {
AmbryServer server = recoveryCluster.initializeServer(serverNode, recoveryProperties, false, notificationSystem, SystemTime.getInstance(), serverNode.equals(partitionLeaderRecoveryNode) ? leaderMockClusterAgentsFactory : null);
recoveryCluster.addServer(server);
}
recoveryCluster.startServers();
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class BlobStoreCompactorTest method generateLocalAndPeerReplicas.
// helpers
// general
/**
* Generate local replica and two peer replicas.
* @return a list of replicas (first one is local replica, others are remote peer replicas)
*/
private List<MockReplicaId> generateLocalAndPeerReplicas() {
Port port = new Port(6667, PortType.PLAINTEXT);
List<String> mountPaths = Arrays.asList("/mnt/u001", "/mnt/u002", "/mnt/u003");
// generate two peer replicas
MockDataNodeId peerNode1 = new MockDataNodeId("node1_host", Collections.singletonList(port), mountPaths, null);
MockDataNodeId peerNode2 = new MockDataNodeId("node2_host", Collections.singletonList(port), mountPaths, null);
MockDataNodeId localNode = new MockDataNodeId("local_host", Collections.singletonList(port), mountPaths, null);
MockPartitionId mockPartitionId = new MockPartitionId(101L, MockClusterMap.DEFAULT_PARTITION_CLASS);
MockReplicaId peerReplica1 = new MockReplicaId(port.getPort(), mockPartitionId, peerNode1, 0);
MockReplicaId peerReplica2 = new MockReplicaId(port.getPort(), mockPartitionId, peerNode2, 1);
MockReplicaId localReplica = new MockReplicaId(port.getPort(), mockPartitionId, localNode, 2);
localReplica.setPeerReplicas(Arrays.asList(peerReplica1, peerReplica2));
return Arrays.asList(localReplica, peerReplica1, peerReplica2);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method setBlobStoreStoppedStateWithMultiDelegatesTest.
/**
* Test setting blob stop state in two clusters (if server participates into two Helix clusters)
* @throws Exception
*/
@Test
public void setBlobStoreStoppedStateWithMultiDelegatesTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
MockClusterParticipant mockClusterParticipant1 = new MockClusterParticipant();
MockClusterParticipant mockClusterParticipant2 = new MockClusterParticipant(null, false);
List<ClusterParticipant> participants = Arrays.asList(mockClusterParticipant1, mockClusterParticipant2);
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, participants);
storageManager.start();
PartitionId id = replicas.get(0).getPartitionId();
// test that any delegate fails to update stop state, then the whole operation fails
List<PartitionId> failToUpdateList = storageManager.setBlobStoreStoppedState(Collections.singletonList(id), true);
assertEquals("Set store stopped state should fail because one of delegates returns false", id, failToUpdateList.get(0));
// test the success case, both delegates succeed in updating stop state of replica
mockClusterParticipant2.setStopStateReturnVal = null;
failToUpdateList = storageManager.setBlobStoreStoppedState(Collections.singletonList(id), true);
assertTrue("Set store stopped state should succeed", failToUpdateList.isEmpty());
// verify both delegates have the correct stopped replica list.
List<String> expectedStoppedReplicas = Collections.singletonList(id.toPathString());
assertEquals("Stopped replica list from participant 1 is not expected", expectedStoppedReplicas, mockClusterParticipant1.getStoppedReplicas());
assertEquals("Stopped replica list from participant 2 is not expected", expectedStoppedReplicas, mockClusterParticipant2.getStoppedReplicas());
shutdownAndAssertStoresInaccessible(storageManager, replicas);
}
use of com.github.ambry.clustermap.MockDataNodeId in project ambry by linkedin.
the class StorageManagerTest method storeStartFailureTest.
/**
* Tests that {@link StorageManager} can start even when certain stores cannot be started. Checks that these stores
* are not accessible. We can make the replica path non-readable to induce a store starting failure.
* @throws Exception
*/
@Test
public void storeStartFailureTest() throws Exception {
MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
List<ReplicaId> replicas = clusterMap.getReplicaIds(dataNode);
Set<Integer> badReplicaIndexes = new HashSet<>(Arrays.asList(2, 7));
for (Integer badReplicaIndex : badReplicaIndexes) {
new File(replicas.get(badReplicaIndex).getReplicaPath()).setReadable(false);
}
StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
storageManager.start();
assertEquals("There should be no unexpected partitions reported", 0, getNumUnrecognizedPartitionsReported());
Map<String, Counter> counters = metricRegistry.getCounters();
assertEquals(0, getCounterValue(counters, DiskSpaceAllocator.class.getName(), "DiskSpaceAllocatorInitFailureCount"));
assertEquals(badReplicaIndexes.size(), getCounterValue(counters, DiskManager.class.getName(), "TotalStoreStartFailures"));
assertEquals(0, getCounterValue(counters, DiskManager.class.getName(), "DiskMountPathFailures"));
for (int i = 0; i < replicas.size(); i++) {
ReplicaId replica = replicas.get(i);
PartitionId id = replica.getPartitionId();
if (badReplicaIndexes.contains(i)) {
assertNull("This store should not be accessible.", 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));
}
}
assertEquals("Compaction thread count is incorrect", dataNode.getMountPaths().size(), TestUtils.numThreadsByThisName(CompactionManager.THREAD_NAME_PREFIX));
verifyCompactionThreadCount(storageManager, dataNode.getMountPaths().size());
shutdownAndAssertStoresInaccessible(storageManager, replicas);
assertEquals("Compaction thread count is incorrect", 0, storageManager.getCompactionThreadCount());
}
Aggregations