use of org.apache.hadoop.hdds.scm.net.NetworkTopology in project ozone by apache.
the class TestKeyManagerImpl method setUp.
@BeforeClass
public static void setUp() throws Exception {
conf = new OzoneConfiguration();
dir = GenericTestUtils.getRandomizedTestDir();
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, dir.toString());
conf.set(OzoneConfigKeys.OZONE_NETWORK_TOPOLOGY_AWARE_READ_KEY, "true");
mockScmBlockLocationProtocol = mock(ScmBlockLocationProtocol.class);
nodeManager = new MockNodeManager(true, 10);
NodeSchema[] schemas = new NodeSchema[] { ROOT_SCHEMA, RACK_SCHEMA, LEAF_SCHEMA };
NodeSchemaManager schemaManager = NodeSchemaManager.getInstance();
schemaManager.init(schemas, false);
NetworkTopology clusterMap = new NetworkTopologyImpl(schemaManager);
nodeManager.getAllNodes().stream().forEach(node -> {
node.setNetworkName(node.getUuidString());
clusterMap.add(node);
});
((MockNodeManager) nodeManager).setNetworkTopology(clusterMap);
SCMConfigurator configurator = new SCMConfigurator();
configurator.setScmNodeManager(nodeManager);
configurator.setNetworkTopology(clusterMap);
configurator.setSCMHAManager(MockSCMHAManager.getInstance(true));
configurator.setScmContext(SCMContext.emptyContext());
scm = HddsTestUtils.getScm(conf, configurator);
scm.start();
scm.exitSafeMode();
scmBlockSize = (long) conf.getStorageSize(OZONE_SCM_BLOCK_SIZE, OZONE_SCM_BLOCK_SIZE_DEFAULT, StorageUnit.BYTES);
conf.setLong(OZONE_KEY_PREALLOCATION_BLOCKS_MAX, 10);
mockScmContainerClient = Mockito.mock(StorageContainerLocationProtocol.class);
OmTestManagers omTestManagers = new OmTestManagers(conf, scm.getBlockProtocolServer(), mockScmContainerClient);
om = omTestManagers.getOzoneManager();
metadataManager = omTestManagers.getMetadataManager();
keyManager = (KeyManagerImpl) omTestManagers.getKeyManager();
prefixManager = omTestManagers.getPrefixManager();
writeClient = omTestManagers.getWriteClient();
mockContainerClient();
Mockito.when(mockScmBlockLocationProtocol.allocateBlock(Mockito.anyLong(), Mockito.anyInt(), any(ReplicationConfig.class), Mockito.anyString(), any(ExcludeList.class))).thenThrow(new SCMException("SafeModePrecheck failed for allocateBlock", ResultCodes.SAFE_MODE_EXCEPTION));
createVolume(VOLUME_NAME);
createBucket(VOLUME_NAME, BUCKET_NAME, false);
createBucket(VOLUME_NAME, VERSIONED_BUCKET_NAME, true);
}
use of org.apache.hadoop.hdds.scm.net.NetworkTopology in project ozone by apache.
the class HealthyReadOnlyNodeHandler method onMessage.
@Override
public void onMessage(DatanodeDetails datanodeDetails, EventPublisher publisher) {
LOG.info("Datanode {} moved to HEALTHY READONLY state.", datanodeDetails);
Set<PipelineID> pipelineIDs = nodeManager.getPipelines(datanodeDetails);
for (PipelineID id : pipelineIDs) {
LOG.info("Closing pipeline {} which uses HEALTHY READONLY datanode {} ", id, datanodeDetails);
try {
pipelineManager.closePipeline(pipelineManager.getPipeline(id), false);
} catch (IOException ex) {
LOG.error("Failed to close pipeline {} which uses HEALTHY READONLY " + "datanode {}: ", id, datanodeDetails, ex);
}
}
// add node back if it is not present in networkTopology
NetworkTopology nt = nodeManager.getClusterNetworkTopologyMap();
if (!nt.contains(datanodeDetails)) {
nt.add(datanodeDetails);
// make sure after DN is added back into topology, DatanodeDetails
// instance returned from nodeStateManager has parent correctly set.
Preconditions.checkNotNull(nodeManager.getNodeByUuid(datanodeDetails.getUuidString()).getParent());
}
}
use of org.apache.hadoop.hdds.scm.net.NetworkTopology in project ozone by apache.
the class DeadNodeHandler method onMessage.
@Override
public void onMessage(final DatanodeDetails datanodeDetails, final EventPublisher publisher) {
try {
/*
* We should have already destroyed all the pipelines on this datanode
* when it was marked as stale. Destroy pipeline should also have closed
* all the containers on this datanode.
*
* Ideally we should not have any pipeline or OPEN containers now.
*
* To be on a safer side, we double check here and take appropriate
* action.
*/
LOG.info("A dead datanode is detected. {}", datanodeDetails);
destroyPipelines(datanodeDetails);
closeContainers(datanodeDetails, publisher);
// is IN_MAINTENANCE
if (!nodeManager.getNodeStatus(datanodeDetails).isInMaintenance()) {
removeContainerReplicas(datanodeDetails);
}
// move dead datanode out of ClusterNetworkTopology
NetworkTopology nt = nodeManager.getClusterNetworkTopologyMap();
if (nt.contains(datanodeDetails)) {
nt.remove(datanodeDetails);
// make sure after DN is removed from topology,
// DatanodeDetails instance returned from nodeStateManager has no parent.
Preconditions.checkState(nodeManager.getNodeByUuid(datanodeDetails.getUuidString()).getParent() == null);
}
} catch (NodeNotFoundException ex) {
// This should not happen, we cannot get a dead node event for an
// unregistered datanode!
LOG.error("DeadNode event for a unregistered node: {}!", datanodeDetails);
}
}
use of org.apache.hadoop.hdds.scm.net.NetworkTopology in project ozone by apache.
the class SCMCommonPlacementPolicy method validateContainerPlacement.
/**
* This default implementation handles rack aware policies and non rack
* aware policies. If a future placement policy needs to check more than racks
* to validate the policy (eg node groups, HDFS like upgrade domain) this
* method should be overridden in the sub class.
* This method requires that subclasses which implement rack aware policies
* override the default method getRequiredRackCount and getNetworkTopology.
* @param dns List of datanodes holding a replica of the container
* @param replicas The expected number of replicas
* @return ContainerPlacementStatus indicating if the placement policy is
* met or not. Not this only considers the rack count and not the
* number of replicas.
*/
@Override
public ContainerPlacementStatus validateContainerPlacement(List<DatanodeDetails> dns, int replicas) {
NetworkTopology topology = nodeManager.getClusterNetworkTopologyMap();
int requiredRacks = getRequiredRackCount(replicas);
if (topology == null || replicas == 1 || requiredRacks == 1) {
if (dns.size() > 0) {
// placement is always satisfied if there is at least one DN.
return validPlacement;
} else {
return invalidPlacement;
}
}
// We have a network topology so calculate if it is satisfied or not.
int numRacks = 1;
final int maxLevel = topology.getMaxLevel();
// The leaf nodes are all at max level, so the number of nodes at
// leafLevel - 1 is the rack count
numRacks = topology.getNumOfNodes(maxLevel - 1);
final long currentRackCount = dns.stream().map(d -> topology.getAncestor(d, 1)).distinct().count();
if (replicas < requiredRacks) {
requiredRacks = replicas;
}
return new ContainerPlacementStatusDefault((int) currentRackCount, requiredRacks, numRacks);
}
use of org.apache.hadoop.hdds.scm.net.NetworkTopology in project ozone by apache.
the class TestReconNodeManager method testUpdateNodeOperationalStateFromScm.
@Test
public void testUpdateNodeOperationalStateFromScm() throws Exception {
ReconStorageConfig scmStorageConfig = new ReconStorageConfig(conf, new ReconUtils());
EventQueue eventQueue = new EventQueue();
NetworkTopology clusterMap = new NetworkTopologyImpl(conf);
Table<UUID, DatanodeDetails> nodeTable = ReconSCMDBDefinition.NODES.getTable(store);
ReconNodeManager reconNodeManager = new ReconNodeManager(conf, scmStorageConfig, eventQueue, clusterMap, nodeTable, versionManager);
DatanodeDetails datanodeDetails = randomDatanodeDetails();
HddsProtos.Node node = mock(HddsProtos.Node.class);
LambdaTestUtils.intercept(NodeNotFoundException.class, () -> {
reconNodeManager.updateNodeOperationalStateFromScm(node, datanodeDetails);
});
reconNodeManager.register(datanodeDetails, null, null);
assertEquals(IN_SERVICE, reconNodeManager.getNodeByUuid(datanodeDetails.getUuidString()).getPersistedOpState());
when(node.getNodeOperationalStates(eq(0))).thenReturn(DECOMMISSIONING);
reconNodeManager.updateNodeOperationalStateFromScm(node, datanodeDetails);
assertEquals(DECOMMISSIONING, reconNodeManager.getNodeByUuid(datanodeDetails.getUuidString()).getPersistedOpState());
List<DatanodeDetails> nodes = reconNodeManager.getNodes(DECOMMISSIONING, null);
assertEquals(1, nodes.size());
assertEquals(datanodeDetails.getUuid(), nodes.get(0).getUuid());
}
Aggregations