Skip to content

Commit

Permalink
HDDS-11350. NullPointerException thrown on checking container balance…
Browse files Browse the repository at this point in the history
…r status (#7134)
  • Loading branch information
siddhantsangwan authored Sep 4, 2024
1 parent 111b9df commit b29beb3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ public ContainerBalancerTask(StorageContainerManager scm,
this.selectedSources = new HashSet<>();
this.selectedTargets = new HashSet<>();
findSourceStrategy = new FindSourceGreedy(nodeManager);
if (config.getNetworkTopologyEnable()) {
findTargetStrategy = new FindTargetGreedyByNetworkTopology(
containerManager, placementPolicyValidateProxy,
nodeManager, networkTopology);
} else {
findTargetStrategy = new FindTargetGreedyByUsageInfo(containerManager,
placementPolicyValidateProxy, nodeManager);
}
this.iterationsStatistic = new ArrayList<>();
}

Expand Down Expand Up @@ -432,14 +440,7 @@ private boolean initializeIteration() {
this.maxDatanodesRatioToInvolvePerIteration =
config.getMaxDatanodesRatioToInvolvePerIteration();
this.maxSizeToMovePerIteration = config.getMaxSizeToMovePerIteration();
if (config.getNetworkTopologyEnable()) {
findTargetStrategy = new FindTargetGreedyByNetworkTopology(
containerManager, placementPolicyValidateProxy,
nodeManager, networkTopology);
} else {
findTargetStrategy = new FindTargetGreedyByUsageInfo(containerManager,
placementPolicyValidateProxy, nodeManager);
}

this.excludeNodes = config.getExcludeNodes();
this.includeNodes = config.getIncludeNodes();
// include/exclude nodes from balancing according to configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public MockedSCM(@Nonnull TestableCluster testableCluster) {
}
}

private void init(@Nonnull ContainerBalancerConfiguration balancerConfig, @Nonnull OzoneConfiguration ozoneCfg) {
void init(@Nonnull ContainerBalancerConfiguration balancerConfig, @Nonnull OzoneConfiguration ozoneCfg) {
ozoneCfg.setFromObject(balancerConfig);
try {
doMock(balancerConfig, ozoneCfg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.apache.hadoop.hdds.scm.container.balancer;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.ozone.OzoneConsts;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;
Expand Down Expand Up @@ -55,4 +57,30 @@ void testGetIterationStatistics() {
});

}

/**
* @see <a href="https://issues.apache.org/jira/browse/HDDS-11350">HDDS-11350</a>
*/
@Test
void testGetCurrentIterationsStatisticDoesNotThrowNullPointerExceptionWhenBalancingThreadIsSleeping() {
MockedSCM mockedScm = new MockedSCM(new TestableCluster(10, OzoneConsts.GB));
OzoneConfiguration ozoneConfig = new OzoneConfiguration();
ContainerBalancerConfiguration config = ozoneConfig.getObject(ContainerBalancerConfiguration.class);

config.setIterations(2);
// the following config makes the balancing thread go to sleep while waiting for DU to be triggered in DNs and
// updated storage reports to arrive via DN heartbeats - of course, this is a unit test and NodeManager, DNs etc.
// are all mocked
config.setTriggerDuEnable(true);
mockedScm.init(config, ozoneConfig);

// run ContainerBalancerTask in a new thread and have the current thread call getCurrentIterationsStatistic
StorageContainerManager scm = mockedScm.getStorageContainerManager();
ContainerBalancer cb = new ContainerBalancer(scm);
ContainerBalancerTask task = new ContainerBalancerTask(scm, 0, cb, cb.getMetrics(), config, false);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
Assertions.assertDoesNotThrow(task::getCurrentIterationsStatistic);
}
}

0 comments on commit b29beb3

Please sign in to comment.