HDDS-575. LoadExistingContainers should be moved to SCMContainerManager from ContainerStateManager. Contributed by Mukul Kumar Singh.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/f3620375 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/f3620375 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/f3620375 Branch: refs/heads/HDFS-12943 Commit: f3620375277254878c109933a7762248d418aab7 Parents: 273cc2d Author: Nanda kumar <na...@apache.org> Authored: Fri Oct 5 16:46:41 2018 +0530 Committer: Nanda kumar <na...@apache.org> Committed: Fri Oct 5 16:47:01 2018 +0530 ---------------------------------------------------------------------- .../scm/container/ContainerStateManager.java | 49 ++++---------------- .../hdds/scm/container/SCMContainerManager.java | 32 +++++++++++++ 2 files changed, 41 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/f3620375/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManager.java ---------------------------------------------------------------------- diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManager.java index b8e4e89..7078b8f 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerStateManager.java @@ -158,46 +158,6 @@ public class ContainerStateManager implements Closeable { lastUsedMap = new ConcurrentHashMap<>(); containerCount = new AtomicLong(0); containers = new ContainerStateMap(); - loadExistingContainers(containerManager, pipelineSelector); - } - - private void loadExistingContainers(ContainerManager containerManager, - PipelineSelector pipelineSelector) { - - List<ContainerInfo> containerList; - try { - containerList = containerManager.listContainer(0, Integer.MAX_VALUE); - - // if there are no container to load, let us return. - if (containerList == null || containerList.size() == 0) { - LOG.info("No containers to load for this cluster."); - return; - } - } catch (IOException e) { - if (!e.getMessage().equals("No container exists in current db")) { - LOG.error("Could not list the containers", e); - } - return; - } - - try { - long maxID = 0; - for (ContainerInfo container : containerList) { - containers.addContainer(container); - pipelineSelector.addContainerToPipeline( - container.getPipelineID(), container.getContainerID()); - - if (maxID < container.getContainerID()) { - maxID = container.getContainerID(); - } - - containerCount.set(maxID); - } - } catch (SCMException ex) { - LOG.error("Unable to create a container information. ", ex); - // Fix me, what is the proper shutdown procedure for SCM ?? - // System.exit(1) // Should we exit here? - } } /** @@ -284,6 +244,15 @@ public class ContainerStateManager implements Closeable { LifeCycleEvent.CLEANUP); } + public void addExistingContainer(ContainerInfo containerInfo) + throws SCMException { + containers.addContainer(containerInfo); + long containerID = containerInfo.getContainerID(); + if (containerCount.get() < containerID) { + containerCount.set(containerID); + } + } + /** * allocates a new container based on the type, replication etc. * http://git-wip-us.apache.org/repos/asf/hadoop/blob/f3620375/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java ---------------------------------------------------------------------- diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java index df26e36..9d6cadb 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java @@ -146,6 +146,38 @@ public class SCMContainerManager implements ContainerManager { containerLeaseManager = new LeaseManager<>("ContainerCreation", containerCreationLeaseTimeout); containerLeaseManager.start(); + loadExistingContainers(); + } + + private void loadExistingContainers() { + + List<ContainerInfo> containerList; + try { + containerList = listContainer(0, Integer.MAX_VALUE); + + // if there are no container to load, let us return. + if (containerList == null || containerList.size() == 0) { + LOG.info("No containers to load for this cluster."); + return; + } + } catch (IOException e) { + if (!e.getMessage().equals("No container exists in current db")) { + LOG.error("Could not list the containers", e); + } + return; + } + + try { + for (ContainerInfo container : containerList) { + containerStateManager.addExistingContainer(container); + pipelineSelector.addContainerToPipeline( + container.getPipelineID(), container.getContainerID()); + } + } catch (SCMException ex) { + LOG.error("Unable to create a container information. ", ex); + // Fix me, what is the proper shutdown procedure for SCM ?? + // System.exit(1) // Should we exit here? + } } /** --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org