Search in sources :

Example 1 with ContainerController

use of org.apache.hadoop.ozone.container.ozoneimpl.ContainerController in project ozone by apache.

the class ContainerCommands method loadContainersFromVolumes.

public void loadContainersFromVolumes() throws IOException {
    OzoneConfiguration conf = parent.getOzoneConf();
    ContainerSet containerSet = new ContainerSet();
    ContainerMetrics metrics = ContainerMetrics.create(conf);
    String firstStorageDir = getFirstStorageDir(conf);
    String datanodeUuid = getDatanodeUUID(firstStorageDir, conf);
    String clusterId = getClusterId(firstStorageDir);
    volumeSet = new MutableVolumeSet(datanodeUuid, conf, null, StorageVolume.VolumeType.DATA_VOLUME, null);
    Map<ContainerProtos.ContainerType, Handler> handlers = new HashMap<>();
    for (ContainerProtos.ContainerType containerType : ContainerProtos.ContainerType.values()) {
        final Handler handler = Handler.getHandlerForContainerType(containerType, conf, datanodeUuid, containerSet, volumeSet, metrics, containerReplicaProto -> {
        });
        handler.setClusterID(clusterId);
        handlers.put(containerType, handler);
    }
    controller = new ContainerController(containerSet, handlers);
    List<HddsVolume> volumes = StorageVolumeUtil.getHddsVolumesList(volumeSet.getVolumesList());
    Iterator<HddsVolume> volumeSetIterator = volumes.iterator();
    LOG.info("Starting the read all the container metadata");
    while (volumeSetIterator.hasNext()) {
        HddsVolume volume = volumeSetIterator.next();
        LOG.info("Loading container metadata from volume " + volume.toString());
        final ContainerReader reader = new ContainerReader(volumeSet, volume, containerSet, conf);
        reader.run();
    }
    LOG.info("All the container metadata is loaded.");
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) HashMap(java.util.HashMap) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) HddsVolume(org.apache.hadoop.ozone.container.common.volume.HddsVolume) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) ContainerReader(org.apache.hadoop.ozone.container.ozoneimpl.ContainerReader)

Example 2 with ContainerController

use of org.apache.hadoop.ozone.container.ozoneimpl.ContainerController in project ozone by apache.

the class CloseContainerCommandHandler method handle.

/**
 * Handles a given SCM command.
 *
 * @param command           - SCM Command
 * @param ozoneContainer    - Ozone Container.
 * @param context           - Current Context.
 * @param connectionManager - The SCMs that we are talking to.
 */
@Override
public void handle(SCMCommand command, OzoneContainer ozoneContainer, StateContext context, SCMConnectionManager connectionManager) {
    invocationCount.incrementAndGet();
    final long startTime = Time.monotonicNow();
    final DatanodeDetails datanodeDetails = context.getParent().getDatanodeDetails();
    final CloseContainerCommandProto closeCommand = ((CloseContainerCommand) command).getProto();
    final ContainerController controller = ozoneContainer.getController();
    final long containerId = closeCommand.getContainerID();
    LOG.debug("Processing Close Container command container #{}", containerId);
    try {
        final Container container = controller.getContainer(containerId);
        if (container == null) {
            LOG.error("Container #{} does not exist in datanode. " + "Container close failed.", containerId);
            return;
        }
        // move the container to CLOSING if in OPEN state
        controller.markContainerForClose(containerId);
        switch(container.getContainerState()) {
            case OPEN:
            case CLOSING:
                // If the container is part of open pipeline, close it via write channel
                if (ozoneContainer.getWriteChannel().isExist(closeCommand.getPipelineID())) {
                    ContainerCommandRequestProto request = getContainerCommandRequestProto(datanodeDetails, closeCommand.getContainerID(), command.getEncodedToken());
                    ozoneContainer.getWriteChannel().submitRequest(request, closeCommand.getPipelineID());
                } else {
                    controller.quasiCloseContainer(containerId);
                    LOG.info("Marking Container {} quasi closed", containerId);
                }
                break;
            case QUASI_CLOSED:
                if (closeCommand.getForce()) {
                    controller.closeContainer(containerId);
                }
                break;
            case CLOSED:
                break;
            case UNHEALTHY:
            case INVALID:
                LOG.debug("Cannot close the container #{}, the container is" + " in {} state.", containerId, container.getContainerState());
                break;
            default:
                break;
        }
    } catch (NotLeaderException e) {
        LOG.debug("Follower cannot close container #{}.", containerId);
    } catch (IOException e) {
        LOG.error("Can't close container #{}", containerId, e);
    } finally {
        long endTime = Time.monotonicNow();
        totalTime += endTime - startTime;
    }
}
Also used : Container(org.apache.hadoop.ozone.container.common.interfaces.Container) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) CloseContainerCommand(org.apache.hadoop.ozone.protocol.commands.CloseContainerCommand) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) CloseContainerCommandProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CloseContainerCommandProto) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) IOException(java.io.IOException)

Example 3 with ContainerController

use of org.apache.hadoop.ozone.container.ozoneimpl.ContainerController in project ozone by apache.

the class TestCSMMetrics method newXceiverServerRatis.

static XceiverServerRatis newXceiverServerRatis(DatanodeDetails dn, OzoneConfiguration conf) throws IOException {
    conf.setInt(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_PORT, dn.getPort(DatanodeDetails.Port.Name.RATIS).getValue());
    final String dir = TEST_DIR + dn.getUuid();
    conf.set(OzoneConfigKeys.DFS_CONTAINER_RATIS_DATANODE_STORAGE_DIR, dir);
    final ContainerDispatcher dispatcher = new TestContainerDispatcher();
    return XceiverServerRatis.newXceiverServerRatis(dn, conf, dispatcher, new ContainerController(new ContainerSet(), Maps.newHashMap()), null, null);
}
Also used : ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) ContainerDispatcher(org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController)

Example 4 with ContainerController

use of org.apache.hadoop.ozone.container.ozoneimpl.ContainerController in project ozone by apache.

the class TestCloseContainerCommandHandler method before.

@Before
public void before() throws Exception {
    context = mock(StateContext.class);
    DatanodeStateMachine dnStateMachine = mock(DatanodeStateMachine.class);
    when(dnStateMachine.getDatanodeDetails()).thenReturn(randomDatanodeDetails());
    when(context.getParent()).thenReturn(dnStateMachine);
    pipelineID = PipelineID.randomId();
    KeyValueContainerData data = new KeyValueContainerData(CONTAINER_ID, layout, GB, pipelineID.getId().toString(), null);
    container = new KeyValueContainer(data, new OzoneConfiguration());
    containerSet = new ContainerSet();
    containerSet.addContainer(container);
    containerHandler = mock(Handler.class);
    controller = new ContainerController(containerSet, singletonMap(ContainerProtos.ContainerType.KeyValueContainer, containerHandler));
    writeChannel = mock(XceiverServerSpi.class);
    ozoneContainer = mock(OzoneContainer.class);
    when(ozoneContainer.getController()).thenReturn(controller);
    when(ozoneContainer.getContainerSet()).thenReturn(containerSet);
    when(ozoneContainer.getWriteChannel()).thenReturn(writeChannel);
    when(writeChannel.isExist(pipelineID.getProtobuf())).thenReturn(true);
    when(writeChannel.isExist(nonExistentPipelineID.getProtobuf())).thenReturn(false);
}
Also used : ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) KeyValueContainerData(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData) KeyValueContainer(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer) XceiverServerSpi(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerSpi) Before(org.junit.Before)

Example 5 with ContainerController

use of org.apache.hadoop.ozone.container.ozoneimpl.ContainerController in project ozone by apache.

the class DeleteContainerCommandHandler method handle.

@Override
public void handle(final SCMCommand command, final OzoneContainer ozoneContainer, final StateContext context, final SCMConnectionManager connectionManager) {
    final DeleteContainerCommand deleteContainerCommand = (DeleteContainerCommand) command;
    final ContainerController controller = ozoneContainer.getController();
    executor.execute(() -> {
        final long startTime = Time.monotonicNow();
        invocationCount.incrementAndGet();
        try {
            controller.deleteContainer(deleteContainerCommand.getContainerID(), deleteContainerCommand.isForce());
        } catch (IOException e) {
            LOG.error("Exception occurred while deleting the container.", e);
        } finally {
            totalTime.getAndAdd(Time.monotonicNow() - startTime);
        }
    });
}
Also used : ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) IOException(java.io.IOException) DeleteContainerCommand(org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand)

Aggregations

ContainerController (org.apache.hadoop.ozone.container.ozoneimpl.ContainerController)9 ContainerSet (org.apache.hadoop.ozone.container.common.impl.ContainerSet)6 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)3 ContainerDispatcher (org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher)3 Handler (org.apache.hadoop.ozone.container.common.interfaces.Handler)3 OzoneContainer (org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)2 ContainerMetrics (org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics)2 StateContext (org.apache.hadoop.ozone.container.common.statemachine.StateContext)2 MutableVolumeSet (org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet)2 UUID (java.util.UUID)1 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)1 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)1 ContainerCommandRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto)1 ContainerType (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType)1 CloseContainerCommandProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CloseContainerCommandProto)1 HDDSLayoutVersionManager (org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager)1 Container (org.apache.hadoop.ozone.container.common.interfaces.Container)1