HDDS-1580. Obtain Handler reference in ContainerScrubber (#842)

This commit is contained in:
Shweta Yakkali 2019-05-28 11:14:24 -07:00 committed by Hanisha Koneru
parent 06fa4d2764
commit d1ec1c52e5
3 changed files with 15 additions and 11 deletions

View File

@ -30,6 +30,7 @@ import org.apache.hadoop.ozone.container.keyvalue.TarContainerPacker;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
/** /**
@ -132,7 +133,11 @@ public class ContainerController {
* @param container Container * @param container Container
* @return handler of the container * @return handler of the container
*/ */
private Handler getHandler(final Container container) { Handler getHandler(final Container container) {
return handlers.get(container.getContainerType()); return handlers.get(container.getContainerType());
} }
Iterator<Container> getContainerSetIterator() {
return containerSet.getContainerIterator();
}
} }

View File

@ -18,12 +18,11 @@
package org.apache.hadoop.ozone.container.ozoneimpl; package org.apache.hadoop.ozone.container.ozoneimpl;
import com.google.common.base.Preconditions;
import org.apache.commons.net.ntp.TimeStamp; import org.apache.commons.net.ntp.TimeStamp;
import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; 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.Container;
import org.apache.hadoop.ozone.container.common.interfaces.Handler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -36,20 +35,19 @@ import java.util.Iterator;
public class ContainerScrubber implements Runnable { public class ContainerScrubber implements Runnable {
private static final Logger LOG = private static final Logger LOG =
LoggerFactory.getLogger(ContainerScrubber.class); LoggerFactory.getLogger(ContainerScrubber.class);
private final ContainerSet containerSet;
private final OzoneConfiguration config; private final OzoneConfiguration config;
private final long timePerContainer = 10000; // 10 sec in millis private final long timePerContainer = 10000; // 10 sec in millis
private boolean halt; private boolean halt;
private Thread scrubThread; private Thread scrubThread;
private ContainerController controller;
public ContainerScrubber(ContainerSet cSet, OzoneConfiguration conf) {
Preconditions.checkNotNull(cSet, public ContainerScrubber(OzoneConfiguration conf,
"ContainerScrubber received a null ContainerSet"); ContainerController controller) {
Preconditions.checkNotNull(conf);
this.containerSet = cSet;
this.config = conf; this.config = conf;
this.halt = false; this.halt = false;
this.scrubThread = null; this.scrubThread = null;
this.controller = controller;
} }
@Override public void run() { @Override public void run() {
@ -130,12 +128,13 @@ public class ContainerScrubber implements Runnable {
private void scrub() { private void scrub() {
Iterator<Container> containerIt = containerSet.getContainerIterator(); Iterator<Container> containerIt = controller.getContainerSetIterator();
long count = 0; long count = 0;
while (containerIt.hasNext()) { while (containerIt.hasNext()) {
TimeStamp startTime = new TimeStamp(System.currentTimeMillis()); TimeStamp startTime = new TimeStamp(System.currentTimeMillis());
Container container = containerIt.next(); Container container = containerIt.next();
Handler containerHandler = controller.getHandler(container);
if (this.halt) { if (this.halt) {
break; // stop if requested break; // stop if requested

View File

@ -161,7 +161,7 @@ public class OzoneContainer {
HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED); HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED);
} else { } else {
if (this.scrubber == null) { if (this.scrubber == null) {
this.scrubber = new ContainerScrubber(containerSet, config); this.scrubber = new ContainerScrubber(config, controller);
} }
scrubber.up(); scrubber.up();
} }