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

validate diskUsageThreshold and diskUsageLwmThreshold #3285

Merged
merged 7 commits into from
Jul 26, 2022
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 @@ -59,6 +59,7 @@ class LedgerDirsMonitor {
public LedgerDirsMonitor(final ServerConfiguration conf,
final DiskChecker diskChecker,
final List<LedgerDirsManager> dirsManagers) {
validateThreshold(conf.getDiskUsageThreshold(), conf.getDiskLowWaterMarkUsageThreshold());
this.interval = conf.getDiskCheckInterval();
this.minUsableSizeForHighPriorityWrites = conf.getMinUsableSizeForHighPriorityWrites();
this.conf = conf;
Expand Down Expand Up @@ -229,5 +230,13 @@ private void checkDirs(final LedgerDirsManager ldm)
}
ldm.getWritableLedgerDirs();
}

private void validateThreshold(float diskSpaceThreshold, float diskSpaceLwmThreshold) {
if (diskSpaceThreshold <= 0 || diskSpaceThreshold >= 1 || diskSpaceLwmThreshold - diskSpaceThreshold > 1e-6) {
throw new IllegalArgumentException("Disk space threashold: "
+ diskSpaceThreshold + " and lwm threshold: " + diskSpaceLwmThreshold
+ " are not valid. Should be > 0 and < 1 and diskSpaceThreshold >= diskSpaceLwmThreshold");
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,35 @@ public void testLedgerDirsMonitorStartReadOnly() throws Exception {
verifyUsage(curDir1, nospace + 0.05f, curDir2, nospace + 0.05f, mockLedgerDirsListener, true);
}

@Test
public void testValidateLwmThreshold() {
final ServerConfiguration configuration = TestBKConfiguration.newServerConfiguration();
// check failed because diskSpaceThreshold < diskSpaceLwmThreshold
configuration.setDiskUsageThreshold(0.65f);
configuration.setDiskLowWaterMarkUsageThreshold(0.90f);
try {
new LedgerDirsMonitor(configuration, mockDiskChecker, Collections.singletonList(dirsManager));
fail("diskSpaceThreshold < diskSpaceLwmThreshold, should be failed.");
} catch (Exception e) {
assertTrue(e.getMessage().contains("diskSpaceThreshold >= diskSpaceLwmThreshold"));
}

// check failed because diskSpaceThreshold = 0 and diskUsageLwmThreshold = 1
configuration.setDiskUsageThreshold(0f);
configuration.setDiskLowWaterMarkUsageThreshold(1f);
try {
new LedgerDirsMonitor(configuration, mockDiskChecker, Collections.singletonList(dirsManager));
fail("diskSpaceThreshold = 0 and diskUsageLwmThreshold = 1, should be failed.");
} catch (Exception e) {
assertTrue(e.getMessage().contains("Should be > 0 and < 1"));
}

// check succeeded
configuration.setDiskUsageThreshold(0.95f);
configuration.setDiskLowWaterMarkUsageThreshold(0.90f);
new LedgerDirsMonitor(configuration, mockDiskChecker, Collections.singletonList(dirsManager));
}

private void setUsageAndThenVerify(File dir1, float dir1Usage, File dir2, float dir2Usage,
MockDiskChecker mockDiskChecker, MockLedgerDirsListener mockLedgerDirsListener, boolean verifyReadOnly)
throws InterruptedException {
Expand Down