diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/ContainerChillModeRule.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/ContainerChillModeRule.java index 95785323e33..17dd4969155 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/ContainerChillModeRule.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/ContainerChillModeRule.java @@ -29,12 +29,15 @@ import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer.NodeRegistrationContainerReport; import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.hdds.server.events.EventHandler; +import org.apache.hadoop.hdds.server.events.EventPublisher; /** * Class defining Chill mode exit criteria for Containers. */ public class ContainerChillModeRule implements - ChillModeExitRule { + ChillModeExitRule, + EventHandler { // Required cutoff % for containers with at least 1 reported replica. private double chillModeCutoff; @@ -68,9 +71,6 @@ public class ContainerChillModeRule implements @Override public boolean validate() { - if (maxContainer == 0) { - return true; - } return getCurrentContainerThreshold() >= chillModeCutoff; } @@ -84,10 +84,6 @@ public class ContainerChillModeRule implements @Override public void process(NodeRegistrationContainerReport reportsProto) { - if (maxContainer == 0) { - // No container to check. - return; - } reportsProto.getReport().getReportsList().forEach(c -> { if (containerMap.containsKey(c.getContainerID())) { @@ -96,12 +92,33 @@ public class ContainerChillModeRule implements } } }); - if(chillModeManager.getInChillMode()) { - SCMChillModeManager.getLogger().info( - "SCM in chill mode. {} % containers have at least one" - + " reported replica.", - (containerWithMinReplicas.get() / maxContainer) * 100); + } + + @Override + public void onMessage(NodeRegistrationContainerReport + nodeRegistrationContainerReport, EventPublisher publisher) { + + // TODO: when we have remove handlers, we can remove getInChillmode check + + if (chillModeManager.getInChillMode()) { + if (validate()) { + return; + } + + process(nodeRegistrationContainerReport); + if (chillModeManager.getInChillMode()) { + SCMChillModeManager.getLogger().info( + "SCM in chill mode. {} % containers have at least one" + + " reported replica.", + (containerWithMinReplicas.get() / maxContainer) * 100); + } + + if (validate()) { + chillModeManager.validateChillModeExitRules(publisher); + } + } + } @Override diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/DataNodeChillModeRule.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/DataNodeChillModeRule.java index 39505056c89..be99962908c 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/DataNodeChillModeRule.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/DataNodeChillModeRule.java @@ -25,13 +25,16 @@ import org.apache.hadoop.hdds.HddsConfigKeys; import org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer.NodeRegistrationContainerReport; import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.hdds.server.events.EventHandler; +import org.apache.hadoop.hdds.server.events.EventPublisher; /** * Class defining Chill mode exit criteria according to number of DataNodes * registered with SCM. */ public class DataNodeChillModeRule implements - ChillModeExitRule { + ChillModeExitRule, + EventHandler { // Min DataNodes required to exit chill mode. private int requiredDns; @@ -62,17 +65,33 @@ public class DataNodeChillModeRule implements @Override public void process(NodeRegistrationContainerReport reportsProto) { - if (requiredDns == 0) { - // No dn check required. - return; - } - if(chillModeManager.getInChillMode()) { - registeredDnSet.add(reportsProto.getDatanodeDetails().getUuid()); - registeredDns = registeredDnSet.size(); - SCMChillModeManager.getLogger().info( - "SCM in chill mode. {} DataNodes registered, {} required.", - registeredDns, requiredDns); + registeredDnSet.add(reportsProto.getDatanodeDetails().getUuid()); + registeredDns = registeredDnSet.size(); + + } + + @Override + public void onMessage(NodeRegistrationContainerReport + nodeRegistrationContainerReport, EventPublisher publisher) { + // TODO: when we have remove handlers, we can remove getInChillmode check + + if (chillModeManager.getInChillMode()) { + if (validate()) { + return; + } + + process(nodeRegistrationContainerReport); + + if (chillModeManager.getInChillMode()) { + SCMChillModeManager.getLogger().info( + "SCM in chill mode. {} DataNodes registered, {} required.", + registeredDns, requiredDns); + } + + if (validate()) { + chillModeManager.validateChillModeExitRules(publisher); + } } } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/SCMChillModeManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/SCMChillModeManager.java index 1d97a579c8b..8ced6d5a95b 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/SCMChillModeManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/chillmode/SCMChillModeManager.java @@ -28,9 +28,6 @@ import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.events.SCMEvents; import org.apache.hadoop.hdds.scm.pipeline.PipelineManager; import org.apache.hadoop.hdds.scm.pipeline.RatisPipelineUtils; -import org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer - .NodeRegistrationContainerReport; -import org.apache.hadoop.hdds.server.events.EventHandler; import org.apache.hadoop.hdds.server.events.EventPublisher; import org.apache.hadoop.hdds.server.events.EventQueue; import org.slf4j.Logger; @@ -48,8 +45,7 @@ import org.slf4j.LoggerFactory; * for reported containers and validates if cutoff threshold for * containers is meet. */ -public class SCMChillModeManager implements - EventHandler { +public class SCMChillModeManager { private static final Logger LOG = LoggerFactory.getLogger(SCMChillModeManager.class); @@ -78,9 +74,16 @@ public class SCMChillModeManager implements HddsConfigKeys.HDDS_SCM_CHILLMODE_ENABLED, HddsConfigKeys.HDDS_SCM_CHILLMODE_ENABLED_DEFAULT); if (isChillModeEnabled) { - exitRules.put(CONT_EXIT_RULE, - new ContainerChillModeRule(config, allContainers, this)); - exitRules.put(DN_EXIT_RULE, new DataNodeChillModeRule(config, this)); + ContainerChillModeRule containerChillModeRule = + new ContainerChillModeRule(config, allContainers, this); + DataNodeChillModeRule dataNodeChillModeRule = + new DataNodeChillModeRule(config, this); + exitRules.put(CONT_EXIT_RULE, containerChillModeRule); + exitRules.put(DN_EXIT_RULE, dataNodeChillModeRule); + eventPublisher.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, + containerChillModeRule); + eventPublisher.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, + dataNodeChillModeRule); if (conf.getBoolean( HddsConfigKeys.HDDS_SCM_CHILLMODE_PIPELINE_AVAILABILITY_CHECK, @@ -146,17 +149,6 @@ public class SCMChillModeManager implements .scheduleFixedIntervalPipelineCreator(pipelineManager, config); } - @Override - public void onMessage( - NodeRegistrationContainerReport nodeRegistrationContainerReport, - EventPublisher publisher) { - if (getInChillMode()) { - exitRules.get(CONT_EXIT_RULE).process(nodeRegistrationContainerReport); - exitRules.get(DN_EXIT_RULE).process(nodeRegistrationContainerReport); - validateChillModeExitRules(publisher); - } - } - public boolean getInChillMode() { if (!isChillModeEnabled) { return false; diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java index fc93235b7b0..c9446a506a8 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java @@ -364,8 +364,6 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl replicationStatus.getChillModeStatusListener()); eventQueue.addHandler(SCMEvents.CHILL_MODE_STATUS, (BlockManagerImpl) scmBlockManager); - eventQueue.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, - scmChillModeManager); registerMXBean(); } diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/chillmode/TestSCMChillModeManager.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/chillmode/TestSCMChillModeManager.java index faf8fee8e6b..957fe708249 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/chillmode/TestSCMChillModeManager.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/chillmode/TestSCMChillModeManager.java @@ -90,8 +90,7 @@ public class TestSCMChillModeManager { } scmChillModeManager = new SCMChillModeManager( config, containers, null, queue); - queue.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, - scmChillModeManager); + assertTrue(scmChillModeManager.getInChillMode()); queue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT, HddsTestUtils.createNodeRegistrationContainerReport(containers)); @@ -111,8 +110,7 @@ public class TestSCMChillModeManager { } scmChillModeManager = new SCMChillModeManager( config, containers, null, queue); - queue.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, - scmChillModeManager); + assertTrue(scmChillModeManager.getInChillMode()); testContainerThreshold(containers.subList(0, 25), 0.25); @@ -167,8 +165,7 @@ public class TestSCMChillModeManager { scmChillModeManager = new SCMChillModeManager( config, containers, null, queue); - queue.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, - scmChillModeManager); + assertTrue(scmChillModeManager.getInChillMode()); // When 10 CLOSED containers are reported by DNs, the computed container @@ -192,8 +189,7 @@ public class TestSCMChillModeManager { conf.setInt(HddsConfigKeys.HDDS_SCM_CHILLMODE_MIN_DATANODE, numOfDns); scmChillModeManager = new SCMChillModeManager( conf, containers, null, queue); - queue.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, - scmChillModeManager); + // Assert SCM is in Chill mode. assertTrue(scmChillModeManager.getInChillMode()); @@ -256,8 +252,6 @@ public class TestSCMChillModeManager { scmChillModeManager = new SCMChillModeManager( config, containers, pipelineManager, queue); - queue.addHandler(SCMEvents.NODE_REGISTRATION_CONT_REPORT, - scmChillModeManager); queue.fireEvent(SCMEvents.NODE_REGISTRATION_CONT_REPORT, HddsTestUtils.createNodeRegistrationContainerReport(containers));