Search in sources :

Example 1 with NetworkTopology

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);
}
Also used : ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) ReplicationConfig(org.apache.hadoop.hdds.client.ReplicationConfig) RatisReplicationConfig(org.apache.hadoop.hdds.client.RatisReplicationConfig) StandaloneReplicationConfig(org.apache.hadoop.hdds.client.StandaloneReplicationConfig) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) MockNodeManager(org.apache.hadoop.hdds.scm.container.MockNodeManager) ScmBlockLocationProtocol(org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol) NetworkTopologyImpl(org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl) NodeSchemaManager(org.apache.hadoop.hdds.scm.net.NodeSchemaManager) StorageContainerLocationProtocol(org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol) NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) SCMConfigurator(org.apache.hadoop.hdds.scm.server.SCMConfigurator) NodeSchema(org.apache.hadoop.hdds.scm.net.NodeSchema) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException) BeforeClass(org.junit.BeforeClass)

Example 2 with NetworkTopology

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());
    }
}
Also used : NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) PipelineID(org.apache.hadoop.hdds.scm.pipeline.PipelineID) IOException(java.io.IOException)

Example 3 with NetworkTopology

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);
    }
}
Also used : NodeNotFoundException(org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException) NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology)

Example 4 with NetworkTopology

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);
}
Also used : NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) ContainerPlacementStatusDefault(org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault)

Example 5 with NetworkTopology

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());
}
Also used : NetworkTopologyImpl(org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl) ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) UUID(java.util.UUID) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) Test(org.junit.Test)

Aggregations

NetworkTopology (org.apache.hadoop.hdds.scm.net.NetworkTopology)20 NetworkTopologyImpl (org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl)13 Test (org.junit.Test)11 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)10 EventQueue (org.apache.hadoop.hdds.server.events.EventQueue)9 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)8 MockDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails)6 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)6 HDDSLayoutVersionManager (org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager)6 NodeManager (org.apache.hadoop.hdds.scm.node.NodeManager)5 SCMNodeManager (org.apache.hadoop.hdds.scm.node.SCMNodeManager)5 ReconUtils (org.apache.hadoop.ozone.recon.ReconUtils)4 UUID (java.util.UUID)3 SCMStorageConfig (org.apache.hadoop.hdds.scm.server.SCMStorageConfig)3 Before (org.junit.Before)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 MockDatanodeDetails.createDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.createDatanodeDetails)2 HddsProtos (org.apache.hadoop.hdds.protocol.proto.HddsProtos)2 SCMException (org.apache.hadoop.hdds.scm.exceptions.SCMException)2