Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11388. Fix unnecessary call to the DB for ContainerBalancer#getBalancerStatusInfo #7224

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,19 @@ public ContainerBalancerTask.Status getBalancerStatus() {
* @return balancer status info if balancer started
*/
public ContainerBalancerStatusInfo getBalancerStatusInfo() throws IOException {
if (isBalancerRunning()) {
ContainerBalancerConfigurationProto configProto = readConfiguration(ContainerBalancerConfigurationProto.class);
return new ContainerBalancerStatusInfo(
this.startedAt,
configProto,
task.getCurrentIterationsStatistic()
);
} else {
lock.lock();
try {
if (isBalancerRunning()) {
return new ContainerBalancerStatusInfo(
this.startedAt,
config.toProtobufBuilder().setShouldRun(true).build(),
task.getCurrentIterationsStatistic()
);
}
return null;
} finally {
lock.unlock();
}

}
/**
* Checks if ContainerBalancer is in valid state to call stop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_NODE_REPORT_INTERVAL;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertSame;
Expand Down Expand Up @@ -257,6 +258,22 @@ public void testDelayedStartOnSCMStatusChange()
stopBalancer();
}

@Test
public void testGetBalancerStatusInfo() throws Exception {
startBalancer(balancerConfiguration);
assertSame(ContainerBalancerTask.Status.RUNNING, containerBalancer.getBalancerStatus());

// Assert the configuration fields that were explicitly set
ContainerBalancerStatusInfo status = containerBalancer.getBalancerStatusInfo();
assertEquals(balancerConfiguration.getThreshold(),
Double.parseDouble(status.getConfiguration().getUtilizationThreshold()));
assertEquals(balancerConfiguration.getIterations(), status.getConfiguration().getIterations());
assertEquals(balancerConfiguration.getTriggerDuEnable(), status.getConfiguration().getTriggerDuBeforeMoveEnable());

stopBalancer();
assertSame(ContainerBalancerTask.Status.STOPPED, containerBalancer.getBalancerStatus());
}

private void startBalancer(ContainerBalancerConfiguration config)
throws IllegalContainerBalancerStateException, IOException,
InvalidContainerBalancerConfigurationException, TimeoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Run Container Balancer

Wait Finish Of Balancing
${result} = Execute ozone admin containerbalancer status
Should Contain ${result} ContainerBalancer is Running.
Wait Until Keyword Succeeds 6min 10sec ContainerBalancer is Not Running
Sleep 60000ms

Expand Down