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-10614. Avoid decreasing cached space usage below zero #6508

Merged
merged 13 commits into from
Apr 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.slf4j.LoggerFactory;

import jakarta.annotation.Nullable;

import java.io.UncheckedIOException;
import java.time.Duration;
import java.util.OptionalLong;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -137,9 +139,24 @@ private void refresh() {
//only one `refresh` can be running at a certain moment
if (isRefreshRunning.compareAndSet(false, true)) {
try {
cachedValue.set(source.getUsedSpace());
long newUsedSpace = source.getUsedSpace();
ArafatKhan2198 marked this conversation as resolved.
Show resolved Hide resolved
// Check for negative value before setting it to the cache
if (newUsedSpace >= 0) {
cachedValue.set(newUsedSpace);
} else {
LOG.error(
"Received negative used space value: {}. Keeping the last known good value: {}.",
newUsedSpace, cachedValue.get());
}
} catch (UncheckedIOException e) {
// Log the error and do not update the cached value
LOG.error(
"Error refreshing space usage for {}. Keeping the last known good value: {}",
source, cachedValue.get(), e);
ArafatKhan2198 marked this conversation as resolved.
Show resolved Hide resolved
} catch (RuntimeException e) {
LOG.warn("Error refreshing space usage for {}", source, e);
LOG.error(
"Error refreshing space usage for {}. Keeping the last known good value: {}",
source, cachedValue.get(), e);
} finally {
isRefreshRunning.set(false);
}
Expand Down