Skip to content

Commit

Permalink
validate diskUsageThreshold and diskUsageLwmThreshold (#3285)
Browse files Browse the repository at this point in the history
### Motivation

When `diskUsageThreshold < diskUsageLwmThreshold`, the bookie can be started normally. When the disk usage reaches `diskUsageThreshold` , bookie will automatically switch to `ReadOnly` mode. The `LedgerDirsMonitor` then switches the bookie back to  `read-write` mode since the disk usage is less than `diskUsageLwmThreshold`, the bookie will switch state back and forth frequently.

### Changes
When creating `LedgerDirsMonitor`, we need to validate `diskUsageThreshold` and `diskUsageLwmThreshold` first.
  • Loading branch information
wenbingshen authored Jul 26, 2022
1 parent cb70194 commit f181325
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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 @@ -251,5 +252,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 @@ -498,6 +498,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

0 comments on commit f181325

Please sign in to comment.