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 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<Container> getContainerSetIterator() {
return containerSet.getContainerIterator();
}
}

View File

@ -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<Container> containerIt = containerSet.getContainerIterator();
Iterator<Container> 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

View File

@ -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();
}