Search in sources :

Example 1 with ContainerStateMap

use of org.apache.hadoop.hdds.scm.container.states.ContainerStateMap in project ozone by apache.

the class ContainerStateManagerImpl method reinitialize.

@Override
public void reinitialize(Table<ContainerID, ContainerInfo> store) throws IOException {
    lock.writeLock().lock();
    try {
        close();
        this.containerStore = store;
        this.containers = new ContainerStateMap();
        this.lastUsedMap = new ConcurrentHashMap<>();
        initialize();
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ContainerStateMap(org.apache.hadoop.hdds.scm.container.states.ContainerStateMap)

Example 2 with ContainerStateMap

use of org.apache.hadoop.hdds.scm.container.states.ContainerStateMap 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)

Aggregations

ContainerStateMap (org.apache.hadoop.hdds.scm.container.states.ContainerStateMap)2 Preconditions (com.google.common.base.Preconditions)1 IOException (java.io.IOException)1 Proxy (java.lang.reflect.Proxy)1 EnumMap (java.util.EnumMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 NavigableSet (java.util.NavigableSet)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Configuration (org.apache.hadoop.conf.Configuration)1 StorageUnit (org.apache.hadoop.conf.StorageUnit)1 HddsProtos (org.apache.hadoop.hdds.protocol.proto.HddsProtos)1 ContainerInfoProto (org.apache.hadoop.hdds.protocol.proto.HddsProtos.ContainerInfoProto)1 LifeCycleEvent (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent)1 CLEANUP (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.CLEANUP)1 CLOSE (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.CLOSE)1 DELETE (org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.DELETE)1