use of org.apache.bookkeeper.util.DiskChecker.DiskOutOfSpaceException in project bookkeeper by apache.
the class LedgerDirsMonitor method check.
private void check() {
try {
List<File> writableDirs = ldm.getWritableLedgerDirs();
// Check all writable dirs disk space usage.
for (File dir : writableDirs) {
try {
diskUsages.put(dir, diskChecker.checkDir(dir));
} catch (DiskErrorException e) {
LOG.error("Ledger directory {} failed on disk checking : ", dir, e);
// Notify disk failure to all listeners
for (LedgerDirsListener listener : ldm.getListeners()) {
listener.diskFailed(dir);
}
} catch (DiskWarnThresholdException e) {
LOG.warn("Ledger directory {} is almost full.", dir);
diskUsages.put(dir, e.getUsage());
for (LedgerDirsListener listener : ldm.getListeners()) {
listener.diskAlmostFull(dir);
}
} catch (DiskOutOfSpaceException e) {
LOG.error("Ledger directory {} is out-of-space.", dir);
diskUsages.put(dir, e.getUsage());
// Notify disk full to all listeners
ldm.addToFilledDirs(dir);
}
}
// Let's get NoWritableLedgerDirException without waiting for the next iteration
// in case we are out of writable dirs
// otherwise for the duration of {interval} we end up in the state where
// bookie cannot get writable dir but considered to be writable
ldm.getWritableLedgerDirs();
} catch (NoWritableLedgerDirException e) {
for (LedgerDirsListener listener : ldm.getListeners()) {
listener.allDisksFull();
}
}
List<File> fullfilledDirs = new ArrayList<File>(ldm.getFullFilledLedgerDirs());
boolean hasWritableLedgerDirs = ldm.hasWritableLedgerDirs();
float totalDiskUsage = 0;
// their usage is < conf.getDiskUsageThreshold.
try {
if (hasWritableLedgerDirs || (totalDiskUsage = diskChecker.getTotalDiskUsage(ldm.getAllLedgerDirs())) < conf.getDiskLowWaterMarkUsageThreshold()) {
// Check all full-filled disk space usage
for (File dir : fullfilledDirs) {
try {
diskUsages.put(dir, diskChecker.checkDir(dir));
ldm.addToWritableDirs(dir, true);
} catch (DiskErrorException e) {
// Notify disk failure to all the listeners
for (LedgerDirsListener listener : ldm.getListeners()) {
listener.diskFailed(dir);
}
} catch (DiskWarnThresholdException e) {
diskUsages.put(dir, e.getUsage());
// the full-filled dir become writable but still
// above
// warn threshold
ldm.addToWritableDirs(dir, false);
} catch (DiskOutOfSpaceException e) {
// the full-filled dir is still full-filled
diskUsages.put(dir, e.getUsage());
}
}
} else {
LOG.debug("Current TotalDiskUsage: {} is greater than LWMThreshold: {}." + " So not adding any filledDir to WritableDirsList", totalDiskUsage, conf.getDiskLowWaterMarkUsageThreshold());
}
} catch (IOException ioe) {
LOG.error("Got IOException while monitoring Dirs", ioe);
for (LedgerDirsListener listener : ldm.getListeners()) {
listener.fatalError();
}
}
}
Aggregations