From d1ec1c52e5a8567526ac1ab6d8ab95010c49fddb Mon Sep 17 00:00:00 2001 From: Shweta Yakkali Date: Tue, 28 May 2019 11:14:24 -0700 Subject: [PATCH] HDDS-1580. Obtain Handler reference in ContainerScrubber (#842) --- .../ozoneimpl/ContainerController.java | 7 ++++++- .../container/ozoneimpl/ContainerScrubber.java | 17 ++++++++--------- .../container/ozoneimpl/OzoneContainer.java | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerController.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerController.java index 3c0f251649..11cb8eeadd 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerController.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerController.java @@ -30,6 +30,7 @@ import java.io.FileInputStream; import java.io.IOException; +import java.util.Iterator; import java.util.Map; /** @@ -132,7 +133,11 @@ public void deleteContainer(final long containerId, boolean force) * @param container Container * @return handler of the container */ - private Handler getHandler(final Container container) { + Handler getHandler(final Container container) { return handlers.get(container.getContainerType()); } + + Iterator getContainerSetIterator() { + return containerSet.getContainerIterator(); + } } diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerScrubber.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerScrubber.java index dea7323d75..d6f8b273d1 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerScrubber.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerScrubber.java @@ -18,12 +18,11 @@ package org.apache.hadoop.ozone.container.ozoneimpl; -import com.google.common.base.Preconditions; import org.apache.commons.net.ntp.TimeStamp; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; -import org.apache.hadoop.ozone.container.common.impl.ContainerSet; import org.apache.hadoop.ozone.container.common.interfaces.Container; +import org.apache.hadoop.ozone.container.common.interfaces.Handler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,20 +35,19 @@ public class ContainerScrubber implements Runnable { private static final Logger LOG = LoggerFactory.getLogger(ContainerScrubber.class); - private final ContainerSet containerSet; private final OzoneConfiguration config; private final long timePerContainer = 10000; // 10 sec in millis private boolean halt; private Thread scrubThread; + private ContainerController controller; - public ContainerScrubber(ContainerSet cSet, OzoneConfiguration conf) { - Preconditions.checkNotNull(cSet, - "ContainerScrubber received a null ContainerSet"); - Preconditions.checkNotNull(conf); - this.containerSet = cSet; + + public ContainerScrubber(OzoneConfiguration conf, + ContainerController controller) { this.config = conf; this.halt = false; this.scrubThread = null; + this.controller = controller; } @Override public void run() { @@ -130,12 +128,13 @@ private void throttleScrubber(TimeStamp startTime) { private void scrub() { - Iterator containerIt = containerSet.getContainerIterator(); + Iterator containerIt = controller.getContainerSetIterator(); long count = 0; while (containerIt.hasNext()) { TimeStamp startTime = new TimeStamp(System.currentTimeMillis()); Container container = containerIt.next(); + Handler containerHandler = controller.getHandler(container); if (this.halt) { break; // stop if requested diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/OzoneContainer.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/OzoneContainer.java index f34334d103..2254ec052d 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/OzoneContainer.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/OzoneContainer.java @@ -161,7 +161,7 @@ private void startContainerScrub() { HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED); } else { if (this.scrubber == null) { - this.scrubber = new ContainerScrubber(containerSet, config); + this.scrubber = new ContainerScrubber(config, controller); } scrubber.up(); }