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.");
}
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;
}
}
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);
}
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);
}
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);
}
});
}
Aggregations