Search in sources :

Example 1 with InvalidStateTransitionException

use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.

the class TestScmSafeMode method testSCMSafeMode.

@Test(timeout = 300_000)
public void testSCMSafeMode() throws Exception {
    // Test1: Test safe mode  when there are no containers in system.
    cluster.stop();
    try {
        cluster = builder.build();
    } catch (IOException e) {
        Assert.fail("Cluster startup failed.");
    }
    assertTrue(cluster.getStorageContainerManager().isInSafeMode());
    cluster.startHddsDatanodes();
    cluster.waitForClusterToBeReady();
    cluster.waitTobeOutOfSafeMode();
    assertFalse(cluster.getStorageContainerManager().isInSafeMode());
    // Test2: Test safe mode  when containers are there in system.
    // Create {numKeys} random names keys.
    TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
    Map<String, OmKeyInfo> keyLocations = helper.createKeys(100 * 2, 4096);
    final List<ContainerInfo> containers = cluster.getStorageContainerManager().getContainerManager().getContainers();
    GenericTestUtils.waitFor(() -> containers.size() >= 3, 100, 1000 * 30);
    // Removing some container to keep them open.
    containers.remove(0);
    containers.remove(0);
    // Close remaining containers
    ContainerManager mapping = cluster.getStorageContainerManager().getContainerManager();
    containers.forEach(c -> {
        try {
            mapping.updateContainerState(c.containerID(), HddsProtos.LifeCycleEvent.FINALIZE);
            mapping.updateContainerState(c.containerID(), LifeCycleEvent.CLOSE);
        } catch (IOException | InvalidStateTransitionException e) {
            LOG.info("Failed to change state of open containers.", e);
        }
    });
    cluster.stop();
    GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer.captureLogs(SCMSafeModeManager.getLogger());
    logCapturer.clearOutput();
    try {
        cluster = builder.build();
    } catch (IOException ex) {
        fail("failed");
    }
    StorageContainerManager scm;
    scm = cluster.getStorageContainerManager();
    assertTrue(scm.isInSafeMode());
    assertFalse(logCapturer.getOutput().contains("SCM exiting safe mode."));
    assertTrue(scm.getCurrentContainerThreshold() == 0);
    for (HddsDatanodeService dn : cluster.getHddsDatanodes()) {
        dn.start();
    }
    GenericTestUtils.waitFor(() -> scm.getCurrentContainerThreshold() == 1.0, 100, 20000);
    EventQueue eventQueue = (EventQueue) cluster.getStorageContainerManager().getEventQueue();
    eventQueue.processAll(5000L);
    double safeModeCutoff = conf.getDouble(HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT, HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT_DEFAULT);
    assertTrue(scm.getCurrentContainerThreshold() >= safeModeCutoff);
    assertTrue(logCapturer.getOutput().contains("SCM exiting safe mode."));
    assertFalse(scm.isInSafeMode());
}
Also used : ContainerManager(org.apache.hadoop.hdds.scm.container.ContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) HddsDatanodeService(org.apache.hadoop.ozone.HddsDatanodeService) IOException(java.io.IOException) TestStorageContainerManagerHelper(org.apache.hadoop.ozone.TestStorageContainerManagerHelper) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) Test(org.junit.Test)

Example 2 with InvalidStateTransitionException

use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.

the class PipelineManagerImpl method closeContainersForPipeline.

/**
 * Fire events to close all containers related to the input pipeline.
 * @param pipelineId - ID of the pipeline.
 * @throws IOException
 */
protected void closeContainersForPipeline(final PipelineID pipelineId) throws IOException {
    Set<ContainerID> containerIDs = stateManager.getContainers(pipelineId);
    ContainerManager containerManager = scmContext.getScm().getContainerManager();
    for (ContainerID containerID : containerIDs) {
        if (containerManager.getContainer(containerID).getState() == HddsProtos.LifeCycleState.OPEN) {
            try {
                containerManager.updateContainerState(containerID, HddsProtos.LifeCycleEvent.FINALIZE);
            } catch (InvalidStateTransitionException ex) {
                throw new IOException(ex);
            }
        }
        eventPublisher.fireEvent(SCMEvents.CLOSE_CONTAINER, containerID);
        LOG.info("Container {} closed for pipeline={}", containerID, pipelineId);
    }
}
Also used : ContainerManager(org.apache.hadoop.hdds.scm.container.ContainerManager) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) IOException(java.io.IOException)

Example 3 with InvalidStateTransitionException

use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.

the class NodeStateManager method updateNodeLayoutVersionState.

/**
 * Updates the node state if the condition satisfies.
 *
 * @param node DatanodeInfo
 * @param condition condition to check
 * @param status current state of node
 * @param lifeCycleEvent NodeLifeCycleEvent to be applied if condition
 *                       matches
 *
 * @throws NodeNotFoundException if the node is not present
 */
private void updateNodeLayoutVersionState(DatanodeInfo node, Predicate<LayoutVersionProto> condition, NodeStatus status, NodeLifeCycleEvent lifeCycleEvent) throws NodeNotFoundException {
    try {
        if (condition.test(node.getLastKnownLayoutVersion())) {
            NodeState newHealthState = nodeHealthSM.getNextState(status.getHealth(), lifeCycleEvent);
            NodeStatus newStatus = nodeStateMap.updateNodeHealthState(node.getUuid(), newHealthState);
            fireHealthStateEvent(newStatus.getHealth(), node);
        }
    } catch (InvalidStateTransitionException e) {
        LOG.warn("Invalid state transition of node {}." + " Current state: {}, life cycle event: {}", node, status, lifeCycleEvent);
    }
}
Also used : NodeState(org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException)

Example 4 with InvalidStateTransitionException

use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.

the class ContainerStateManagerImpl method updateContainerState.

@Override
public void updateContainerState(final HddsProtos.ContainerID containerID, final LifeCycleEvent event) throws IOException, InvalidStateTransitionException {
    // TODO: Remove the protobuf conversion after fixing ContainerStateMap.
    final ContainerID id = ContainerID.getFromProtobuf(containerID);
    lock.writeLock().lock();
    try {
        if (containers.contains(id)) {
            final ContainerInfo oldInfo = containers.getContainerInfo(id);
            final LifeCycleState oldState = oldInfo.getState();
            final LifeCycleState newState = stateMachine.getNextState(oldInfo.getState(), event);
            if (newState.getNumber() > oldState.getNumber()) {
                ExecutionUtil.create(() -> {
                    containers.updateState(id, oldState, newState);
                    transactionBuffer.addToBuffer(containerStore, id, containers.getContainerInfo(id));
                }).onException(() -> {
                    transactionBuffer.addToBuffer(containerStore, id, oldInfo);
                    containers.updateState(id, newState, oldState);
                }).execute();
                containerStateChangeActions.getOrDefault(event, info -> {
                }).execute(oldInfo);
            }
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ScmConfigKeys(org.apache.hadoop.hdds.scm.ScmConfigKeys) CLOSE(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.CLOSE) SCMHAInvocationHandler(org.apache.hadoop.hdds.scm.ha.SCMHAInvocationHandler) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) Proxy(java.lang.reflect.Proxy) ContainerState(org.apache.hadoop.hdds.scm.container.states.ContainerState) LoggerFactory(org.slf4j.LoggerFactory) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ExecutionUtil(org.apache.hadoop.hdds.scm.ha.ExecutionUtil) StateMachine(org.apache.hadoop.ozone.common.statemachine.StateMachine) SCMRatisServer(org.apache.hadoop.hdds.scm.ha.SCMRatisServer) QUASI_CLOSE(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.QUASI_CLOSE) HashSet(java.util.HashSet) LifeCycleState(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState) OPEN(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.OPEN) FINALIZE(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.FINALIZE) CLEANUP(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.CLEANUP) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) PipelineNotFoundException(org.apache.hadoop.hdds.scm.pipeline.PipelineNotFoundException) FORCE_CLOSE(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.FORCE_CLOSE) CLOSING(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSING) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) DBTransactionBuffer(org.apache.hadoop.hdds.scm.metadata.DBTransactionBuffer) DELETING(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.DELETING) DELETE(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.DELETE) StorageUnit(org.apache.hadoop.conf.StorageUnit) LifeCycleEvent(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent) Logger(org.slf4j.Logger) CLOSED(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) NavigableSet(java.util.NavigableSet) RequestType(org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType) PipelineManager(org.apache.hadoop.hdds.scm.pipeline.PipelineManager) Table(org.apache.hadoop.hdds.utils.db.Table) QUASI_CLOSED(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.QUASI_CLOSED) PipelineID(org.apache.hadoop.hdds.scm.pipeline.PipelineID) Preconditions(com.google.common.base.Preconditions) ContainerInfoProto(org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerInfoProto) DELETED(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.DELETED) TableIterator(org.apache.hadoop.hdds.utils.db.TableIterator) CheckedConsumer(org.apache.hadoop.hdds.scm.ha.CheckedConsumer) ContainerStateMap(org.apache.hadoop.hdds.scm.container.states.ContainerStateMap) KeyValue(org.apache.hadoop.hdds.utils.db.Table.KeyValue) LifeCycleState(org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState)

Example 5 with InvalidStateTransitionException

use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.

the class ReconIncrementalContainerReportHandler method onMessage.

@Override
public void onMessage(final IncrementalContainerReportFromDatanode report, final EventPublisher publisher) {
    final DatanodeDetails dnFromReport = report.getDatanodeDetails();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Processing incremental container report from data node {}", dnFromReport);
    }
    DatanodeDetails dd = getNodeManager().getNodeByUuid(dnFromReport.getUuidString());
    if (dd == null) {
        LOG.warn("Received container report from unknown datanode {}", dnFromReport);
        return;
    }
    ReconContainerManager containerManager = (ReconContainerManager) getContainerManager();
    boolean success = true;
    for (ContainerReplicaProto replicaProto : report.getReport().getReportList()) {
        try {
            final ContainerID id = ContainerID.valueOf(replicaProto.getContainerID());
            try {
                containerManager.checkAndAddNewContainer(id, replicaProto.getState(), report.getDatanodeDetails());
            } catch (Exception ioEx) {
                LOG.error("Exception while checking and adding new container.", ioEx);
                return;
            }
            getNodeManager().addContainer(dd, id);
            processContainerReplica(dd, replicaProto, publisher);
        } catch (ContainerNotFoundException e) {
            success = false;
            LOG.warn("Container {} not found!", replicaProto.getContainerID());
        } catch (NodeNotFoundException ex) {
            success = false;
            LOG.error("Received ICR from unknown datanode {}.", report.getDatanodeDetails(), ex);
        } catch (IOException | InvalidStateTransitionException e) {
            success = false;
            LOG.error("Exception while processing ICR for container {}", replicaProto.getContainerID());
        }
    }
    containerManager.notifyContainerReportProcessing(false, success);
}
Also used : NodeNotFoundException(org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) IOException(java.io.IOException) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) ContainerReplicaProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) IOException(java.io.IOException) NodeNotFoundException(org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException)

Aggregations

InvalidStateTransitionException (org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException)9 IOException (java.io.IOException)7 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)4 Map (java.util.Map)3 Set (java.util.Set)3 HddsProtos (org.apache.hadoop.hdds.protocol.proto.HddsProtos)3 NodeNotFoundException (org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 List (java.util.List)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 TimeoutException (java.util.concurrent.TimeoutException)2 LifeCycleEvent (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent)2 LifeCycleState (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState)2 ContainerReplicaProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto)2 ContainerID (org.apache.hadoop.hdds.scm.container.ContainerID)2 ContainerManager (org.apache.hadoop.hdds.scm.container.ContainerManager)2 PipelineID (org.apache.hadoop.hdds.scm.pipeline.PipelineID)2