hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerStateMap.java
public void updateState(ContainerInfo info, LifeCycleState currentState,
      LifeCycleState newState) throws SCMException {
    Preconditions.checkNotNull(currentState);
    Preconditions.checkNotNull(newState);

    ContainerID id = new ContainerID(info.getContainerID());
    ContainerInfo currentInfo = null;

    try (AutoCloseableLock lock = autoLock.acquire()) {
      currentInfo = containerMap.get(id);

      if (currentInfo == null) {
        throw new
            SCMException("No such container.", FAILED_TO_FIND_CONTAINER);
      }
      // We are updating two places before this update is done, these can
      // fail independently, since the code needs to handle it.

      // We update the attribute map, if that fails it will throw an exception,
      // so no issues, if we are successful, we keep track of the fact that we
      // have updated the lifecycle state in the map, and update the container
      // state. If this second update fails, we will attempt to roll back the
      // earlier change we did. If the rollback fails, we can be in an
      // inconsistent state,

      info.setState(newState);
      containerMap.put(id, info);
      lifeCycleStateMap.update(currentState, newState, id);
      LOG.trace("Updated the container {} to new state. Old = {}, new = " +
          "{}", id, currentState, newState);
    } catch (SCMException ex) {
      LOG.error("Unable to update the container state. {}", ex);
      // we need to revert the change in this attribute since we are not
      // able to update the hash table.
      LOG.info("Reverting the update to lifecycle state. Moving back to " +
              "old state. Old = {}, Attempted state = {}", currentState,
          newState);

      containerMap.put(id, currentInfo);

      // if this line throws, the state map can be in an inconsistent
      // state, since we will have modified the attribute by the
      // container state will not in sync since we were not able to put
      // that into the hash table.
      lifeCycleStateMap.update(newState, currentState, id);

      throw new SCMException("Updating the container map failed.", ex,
          FAILED_TO_CHANGE_CONTAINER_STATE);
    }
  }
/**
   * Update the State of a container.
   *
   * @param info - ContainerInfo
   * @param currentState - CurrentState
   * @param newState - NewState.
   * @throws SCMException - in case of failure.
   */
Update the State of a container.
Update the State of a container .
public void updateState(ContainerInfo info, LifeCycleState currentState,
      LifeCycleState newState) throws SCMException {
    Preconditions.checkNotNull(currentState);
    Preconditions.checkNotNull(newState);
    ContainerID id = new ContainerID(info.getContainerID());
    ContainerInfo currentInfo = null;
    try (AutoCloseableLock lock = autoLock.acquire()) {
      currentInfo = containerMap.get(id);
      if (currentInfo == null) {
        throw new
            SCMException("No such container.", FAILED_TO_FIND_CONTAINER);
      }
      info.setState(newState);
      containerMap.put(id, info);
      lifeCycleStateMap.update(currentState, newState, id);
      LOG.trace("Updated the container {} to new state. Old = {}, new = " +
          "{}", id, currentState, newState);
    } catch (SCMException ex) {
      LOG.error("Unable to update the container state. {}", ex);
      LOG.info("Reverting the update to lifecycle state. Moving back to " +
              "old state. Old = {}, Attempted state = {}", currentState,
          newState);
      containerMap.put(id, currentInfo);
      lifeCycleStateMap.update(newState, currentState, id);
      throw new SCMException("Updating the container map failed.", ex,
          FAILED_TO_CHANGE_CONTAINER_STATE);
    }
  }
public void updateState ( ContainerInfo info , LifeCycleState currentState , LifeCycleState newState ) throws SCMException { Preconditions . checkNotNull ( currentState ) ; Preconditions . checkNotNull ( newState ) ; ContainerID id = new ContainerID ( info . getContainerID ( ) ) ; ContainerInfo currentInfo = null ; try ( AutoCloseableLock lock = autoLock . acquire ( ) ) { currentInfo = containerMap . get ( id ) ; if ( currentInfo == null ) { throw new SCMException ( "No such container." , FAILED_TO_FIND_CONTAINER ) ; } info . setState ( newState ) ; containerMap . put ( id , info ) ; lifeCycleStateMap . update ( currentState , newState , id ) ; LOG . trace ( "Updated the container {} to new state. Old = {}, new = " + "{}" , id , currentState , newState ) ; } catch ( SCMException ex ) { LOG . error ( "Unable to update the container state. {}" , ex ) ; LOG . info ( "Reverting the update to lifecycle state. Moving back to " + "old state. Old = {}, Attempted state = {}" , currentState , newState ) ; containerMap . put ( id , currentInfo ) ; lifeCycleStateMap . update ( newState , currentState , id ) ; throw new SCMException ( "Updating the container map failed." , ex , FAILED_TO_CHANGE_CONTAINER_STATE ) ; } }
Update the State of a container.
Update the State of a container .
// We are updating two places before this update is done, these can // fail independently, since the code needs to handle it. // We update the attribute map, if that fails it will throw an exception, // so no issues, if we are successful, we keep track of the fact that we // have updated the lifecycle state in the map, and update the container // state. If this second update fails, we will attempt to roll back the // earlier change we did. If the rollback fails, we can be in an // inconsistent state, // we need to revert the change in this attribute since we are not // able to update the hash table. // if this line throws, the state map can be in an inconsistent // state, since we will have modified the attribute by the // container state will not in sync since we were not able to put // that into the hash table.