You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by we...@apache.org on 2026/04/23 22:52:01 UTC

(ozone) branch master updated: HDDS-14871. DataNode: tolerate per-volume health-check latch timeouts before marking volumes failed. (#9954)

This is an automated email from the ASF dual-hosted git repository.

jojochuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 7eaf46fba46 HDDS-14871. DataNode: tolerate per-volume health-check latch timeouts before marking volumes failed. (#9954)
7eaf46fba46 is described below

commit 7eaf46fba4610b44ceb8426cfd0db6194cf19798
Author: Devesh Kumar Singh <de...@hotmail.com>
AuthorDate: Fri Apr 24 04:21:55 2026 +0530

    HDDS-14871. DataNode: tolerate per-volume health-check latch timeouts before marking volumes failed. (#9954)
---
 .../common/statemachine/DatanodeConfiguration.java | 101 +++++++++++
 .../container/common/volume/StorageVolume.java     |  44 +++++
 .../common/volume/StorageVolumeChecker.java        | 114 ++++++++++---
 .../common/volume/TestStorageVolumeChecker.java    | 185 +++++++++++++++++++++
 .../volume/TestStorageVolumeHealthChecks.java      |  94 +++++++++++
 5 files changed, 514 insertions(+), 24 deletions(-)

diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeConfiguration.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeConfiguration.java
index a9242355aac..919777f3519 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeConfiguration.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeConfiguration.java
@@ -63,6 +63,12 @@ public class DatanodeConfiguration extends ReconfigurableConfig {
   public static final String DISK_CHECK_MIN_GAP_KEY = "hdds.datanode.disk.check.min.gap";
   public static final String DISK_CHECK_TIMEOUT_KEY = "hdds.datanode.disk.check.timeout";
   public static final String DISK_CHECK_SLIDING_WINDOW_TIMEOUT_KEY = "hdds.datanode.disk.check.sliding.window.timeout";
+  public static final String DISK_CHECK_TIMEOUT_TEST_ENABLED_KEY =
+      "hdds.datanode.disk.check.timeout.test.enabled";
+  public static final String DISK_CHECK_TIMEOUT_FAILURES_TOLERATED_KEY =
+      "hdds.datanode.disk.check.timeout.failures.tolerated";
+  public static final String DISK_CHECK_TIMEOUT_SLIDING_WINDOW_TIMEOUT_KEY =
+      "hdds.datanode.disk.check.timeout.sliding.window.timeout";
 
   // Minimum space should be left on volume.
   // Ex: If volume has 1000GB and minFreeSpace is configured as 10GB,
@@ -103,6 +109,11 @@ public class DatanodeConfiguration extends ReconfigurableConfig {
 
   static final Duration DISK_CHECK_SLIDING_WINDOW_TIMEOUT_DEFAULT =
       Duration.ofMinutes(PERIODIC_DISK_CHECK_INTERVAL_MINUTES_DEFAULT).plus(DISK_CHECK_TIMEOUT_DEFAULT);
+  static final boolean DISK_CHECK_TIMEOUT_TEST_ENABLED_DEFAULT = true;
+  static final int DISK_CHECK_TIMEOUT_FAILURES_TOLERATED_DEFAULT = 1;
+  static final Duration DISK_CHECK_TIMEOUT_SLIDING_WINDOW_TIMEOUT_DEFAULT =
+      Duration.ofMinutes(PERIODIC_DISK_CHECK_INTERVAL_MINUTES_DEFAULT)
+          .plus(DISK_CHECK_TIMEOUT_DEFAULT);
 
   static final boolean CONTAINER_SCHEMA_V3_ENABLED_DEFAULT = true;
   static final long ROCKSDB_LOG_MAX_FILE_SIZE_BYTES_DEFAULT = 32 * 1024 * 1024;
@@ -430,6 +441,39 @@ public class DatanodeConfiguration extends ReconfigurableConfig {
   )
   private Duration diskCheckSlidingWindowTimeout = DISK_CHECK_SLIDING_WINDOW_TIMEOUT_DEFAULT;
 
+  @Config(key = "hdds.datanode.disk.check.timeout.test.enabled",
+      defaultValue = "true",
+      type = ConfigType.BOOLEAN,
+      tags = { DATANODE },
+      description = "Enable or disable timeout-based volume failure tracking "
+          + "independently of the disk IO health checks."
+  )
+  private boolean isDiskCheckTimeoutTestEnabled =
+      DISK_CHECK_TIMEOUT_TEST_ENABLED_DEFAULT;
+
+  @Config(key = "hdds.datanode.disk.check.timeout.failures.tolerated",
+      defaultValue = "1",
+      type = ConfigType.INT,
+      tags = { DATANODE },
+      description = "The number of volume check timeouts allowed within the "
+          + "timeout sliding window before the volume is marked as failed."
+  )
+  private int diskCheckTimeoutFailureTolerance =
+      DISK_CHECK_TIMEOUT_FAILURES_TOLERATED_DEFAULT;
+
+  @Config(key = "hdds.datanode.disk.check.timeout.sliding.window.timeout",
+      defaultValue = "90m",
+      type = ConfigType.TIME,
+      tags = { DATANODE },
+      description = "Time interval after which a timed out volume check "
+          + "event stored in the timeout sliding window will expire. "
+          + "Do not set this below the periodic disk check interval or "
+          + "timeout events may not accumulate across sparse checks. "
+          + "Unit could be defined with postfix (ns,ms,s,m,h,d)."
+  )
+  private Duration diskCheckTimeoutSlidingWindowTimeout =
+      DISK_CHECK_TIMEOUT_SLIDING_WINDOW_TIMEOUT_DEFAULT;
+
   @Config(key = "hdds.datanode.chunk.data.validation.check",
       defaultValue = "false",
       type = ConfigType.BOOLEAN,
@@ -676,6 +720,17 @@ public void validate() {
       }
     }
 
+    if (!isDiskCheckTimeoutTestEnabled) {
+      LOG.info("Disk check timeout tracking has been disabled.");
+    } else if (diskCheckTimeoutFailureTolerance < 0) {
+      LOG.warn("{} must be greater than or equal to 0 but was set to {}. Defaulting to {}",
+          DISK_CHECK_TIMEOUT_FAILURES_TOLERATED_KEY,
+          diskCheckTimeoutFailureTolerance,
+          DISK_CHECK_TIMEOUT_FAILURES_TOLERATED_DEFAULT);
+      diskCheckTimeoutFailureTolerance =
+          DISK_CHECK_TIMEOUT_FAILURES_TOLERATED_DEFAULT;
+    }
+
     if (diskCheckMinGap.isNegative()) {
       LOG.warn(DISK_CHECK_MIN_GAP_KEY +
               " must be greater than zero and was set to {}. Defaulting to {}",
@@ -709,6 +764,28 @@ public void validate() {
       diskCheckSlidingWindowTimeout = defaultTimeout;
     }
 
+    if (diskCheckTimeoutSlidingWindowTimeout.isNegative()) {
+      Duration defaultTimeout =
+          Duration.ofMinutes(periodicDiskCheckIntervalMinutes).plus(diskCheckTimeout);
+      LOG.warn("{} must be greater than zero and was set to {}. Defaulting to {}",
+          DISK_CHECK_TIMEOUT_SLIDING_WINDOW_TIMEOUT_KEY,
+          diskCheckTimeoutSlidingWindowTimeout,
+          defaultTimeout);
+      diskCheckTimeoutSlidingWindowTimeout = defaultTimeout;
+    }
+
+    if (diskCheckTimeoutSlidingWindowTimeout
+        .compareTo(Duration.ofMinutes(periodicDiskCheckIntervalMinutes)) < 0) {
+      Duration defaultTimeout =
+          Duration.ofMinutes(periodicDiskCheckIntervalMinutes).plus(diskCheckTimeout);
+      LOG.warn("{} must be greater than or equal to {} minutes and was set to {} minutes. Defaulting to {}",
+          DISK_CHECK_TIMEOUT_SLIDING_WINDOW_TIMEOUT_KEY,
+          periodicDiskCheckIntervalMinutes,
+          diskCheckTimeoutSlidingWindowTimeout.toMinutes(),
+          DurationFormatUtils.formatDurationHMS(defaultTimeout.toMillis()));
+      diskCheckTimeoutSlidingWindowTimeout = defaultTimeout;
+    }
+
     if (blockDeleteCommandWorkerInterval.isNegative()) {
       LOG.warn(BLOCK_DELETE_COMMAND_WORKER_INTERVAL +
           " must be greater than zero and was set to {}. Defaulting to {}",
@@ -944,6 +1021,30 @@ public void setDiskCheckSlidingWindowTimeout(Duration duration) {
     diskCheckSlidingWindowTimeout = duration;
   }
 
+  public boolean isDiskCheckTimeoutTestEnabled() {
+    return isDiskCheckTimeoutTestEnabled;
+  }
+
+  public void setDiskCheckTimeoutTestEnabled(boolean enabled) {
+    isDiskCheckTimeoutTestEnabled = enabled;
+  }
+
+  public int getDiskCheckTimeoutFailureTolerance() {
+    return diskCheckTimeoutFailureTolerance;
+  }
+
+  public void setDiskCheckTimeoutFailureTolerance(int tolerance) {
+    diskCheckTimeoutFailureTolerance = tolerance;
+  }
+
+  public Duration getDiskCheckTimeoutSlidingWindowTimeout() {
+    return diskCheckTimeoutSlidingWindowTimeout;
+  }
+
+  public void setDiskCheckTimeoutSlidingWindowTimeout(Duration duration) {
+    diskCheckTimeoutSlidingWindowTimeout = duration;
+  }
+
   public int getBlockDeleteThreads() {
     return blockDeleteThreads;
   }
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolume.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolume.java
index 8f6553c4ec7..d9424b76a13 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolume.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolume.java
@@ -110,7 +110,9 @@ public abstract class StorageVolume implements Checkable<Boolean, VolumeCheckRes
   tests run, then the volume is considered failed.
    */
   private final boolean isDiskCheckEnabled;
+  private final boolean isTimeoutCheckEnabled;
   private SlidingWindow ioTestSlidingWindow;
+  private SlidingWindow timeoutFailureSlidingWindow;
   private int healthCheckFileSize;
 
   /**
@@ -160,8 +162,12 @@ protected StorageVolume(Builder<?> b) throws IOException {
       this.conf = b.conf;
       this.dnConf = conf.getObject(DatanodeConfiguration.class);
       this.isDiskCheckEnabled = dnConf.isDiskCheckEnabled();
+      this.isTimeoutCheckEnabled = dnConf.isDiskCheckTimeoutTestEnabled();
       this.ioTestSlidingWindow = new SlidingWindow(dnConf.getVolumeIOFailureTolerance(),
           dnConf.getDiskCheckSlidingWindowTimeout(), b.getClock());
+      this.timeoutFailureSlidingWindow = new SlidingWindow(
+          dnConf.getDiskCheckTimeoutFailureTolerance(),
+          dnConf.getDiskCheckTimeoutSlidingWindowTimeout(), b.getClock());
       this.healthCheckFileSize = dnConf.getVolumeHealthCheckFileSize();
     } else {
       storageDir = new File(b.volumeRootStr);
@@ -170,6 +176,7 @@ protected StorageVolume(Builder<?> b) throws IOException {
       this.storageID = UUID.randomUUID().toString();
       this.state = VolumeState.FAILED;
       this.isDiskCheckEnabled = false;
+      this.isTimeoutCheckEnabled = false;
       this.conf = null;
       this.dnConf = null;
     }
@@ -567,6 +574,11 @@ public SlidingWindow getIoTestSlidingWindow() {
     return ioTestSlidingWindow;
   }
 
+  @VisibleForTesting
+  public SlidingWindow getTimeoutFailureSlidingWindow() {
+    return timeoutFailureSlidingWindow;
+  }
+
   public StorageType getStorageType() {
     return storageType;
   }
@@ -752,6 +764,38 @@ public synchronized VolumeCheckResult check(@Nullable Boolean unused)
     return VolumeCheckResult.HEALTHY;
   }
 
+  /**
+   * Records a volume-check timeout in the timeout failure window.
+   *
+   * <p>This is intentionally separate from the normal IO failure window.
+   * Timeouts are tracked as "more than N timeout events within the timeout
+   * window" rather than as a consecutive counter. The time-based expiry
+   * automatically removes old timeout events.
+   *
+   * @return {@code true} if the number of timeout events in the timeout window
+   *         now exceeds the tolerated threshold and the volume should be
+   *         marked failed; {@code false} otherwise.
+   */
+  public boolean recordTimeoutAndCheckFailure() {
+    if (!isTimeoutCheckEnabled) {
+      return false;
+    }
+    timeoutFailureSlidingWindow.add();
+    if (timeoutFailureSlidingWindow.isExceeded()) {
+      LOG.error("Volume {} check timed out more than the {} tolerated times "
+              + "within the past {} ms. Marking FAILED.",
+          this, timeoutFailureSlidingWindow.getWindowSize(),
+          timeoutFailureSlidingWindow.getExpiryDurationMillis());
+      return true;
+    }
+    LOG.warn("Volume {} check timed out. Encountered {} out of {} tolerated "
+            + "timeouts within the past {} ms.",
+        this, timeoutFailureSlidingWindow.getNumEventsInWindow(),
+        timeoutFailureSlidingWindow.getWindowSize(),
+        timeoutFailureSlidingWindow.getExpiryDurationMillis());
+    return false;
+  }
+
   @Override
   public int hashCode() {
     return Objects.hash(storageDir);
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolumeChecker.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolumeChecker.java
index b48b0dac118..aa47f70d57a 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolumeChecker.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/StorageVolumeChecker.java
@@ -42,6 +42,7 @@
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 import org.apache.hadoop.hdds.conf.ConfigurationSource;
@@ -86,6 +87,7 @@ public class StorageVolumeChecker {
   private final Timer timer;
 
   private final ExecutorService checkVolumeResultHandlerExecutorService;
+  private final Object resultLock = new Object();
 
   private final DatanodeConfiguration dnConf;
 
@@ -232,7 +234,8 @@ public Set<? extends StorageVolume> checkAllVolumes(
         allVolumes.add(v);
         Futures.addCallback(olf.get(),
             new ResultHandler(v, healthyVolumes, failedVolumes,
-                numVolumes, (ignored1, ignored2) -> latch.countDown()),
+                numVolumes, (ignored1, ignored2) -> latch.countDown(),
+                true, resultLock),
             MoreExecutors.directExecutor());
       } else {
         if (v instanceof HddsVolume) {
@@ -246,18 +249,41 @@ public Set<? extends StorageVolume> checkAllVolumes(
 
     // Wait until our timeout elapses, after which we give up on
     // the remaining volumes.
-    if (!latch.await(maxAllowedTimeForCheckMs, TimeUnit.MILLISECONDS)) {
-      LOG.warn("checkAllVolumes timed out after {} ms",
-          maxAllowedTimeForCheckMs);
-    }
+    boolean completedOnTime =
+        latch.await(maxAllowedTimeForCheckMs, TimeUnit.MILLISECONDS);
+
+    synchronized (resultLock) {
+      if (!completedOnTime) {
+        LOG.warn("checkAllVolumes timed out after {} ms."
+            + " Evaluating per-volume latch-timeout tolerance.",
+            maxAllowedTimeForCheckMs);
+      }
+
+      final Set<StorageVolume> failedSnapshot = new HashSet<>(failedVolumes);
+      final Set<StorageVolume> healthySnapshot = new HashSet<>(healthyVolumes);
+
+      // Volumes that explicitly reported FAILED via check() are always
+      // returned — the IO-failure sliding window in StorageVolume.check()
+      // already applied its own tolerance.
+      final Set<StorageVolume> result = new HashSet<>(failedSnapshot);
+
+      // Volumes still pending (neither healthy nor explicitly failed) at
+      // latch-timeout time. Timeout accounting for batch checks happens here
+      // in one place, regardless of whether the per-check timeout callback
+      // has already fired.
+      final Set<StorageVolume> pendingVolumes =
+          new HashSet<>(Sets.difference(allVolumes,
+              Sets.union(healthySnapshot, failedSnapshot)));
+
+      for (StorageVolume v : pendingVolumes) {
+        if (v.recordTimeoutAndCheckFailure()) {
+          // Tolerance exceeded — mark as failed.
+          result.add(v);
+        }
+        // else: within tolerance this round — omit from failed set.
+      }
 
-    synchronized (this) {
-      // All volumes that have not been detected as healthy should be
-      // considered failed. This is a superset of 'failedVolumes'.
-      //
-      // Make a copy under the mutex as Sets.difference() returns a view
-      // of a potentially changing set.
-      return new HashSet<>(Sets.difference(allVolumes, healthyVolumes));
+      return result;
     }
   }
 
@@ -298,7 +324,7 @@ public boolean checkVolume(final StorageVolume volume, Callback callback) {
       Futures.addCallback(olf.get(),
           new ResultHandler(volume,
               ConcurrentHashMap.newKeySet(), ConcurrentHashMap.newKeySet(),
-              new AtomicLong(1), callback),
+              new AtomicLong(1), callback, false, resultLock),
           checkVolumeResultHandlerExecutorService
       );
       return true;
@@ -320,23 +346,37 @@ private static class ResultHandler
     private final Callback callback;
 
     /**
-     * @param healthyVolumes set of healthy volumes. If the disk check is
-     *                       successful, add the volume here.
-     * @param failedVolumes  set of failed volumes. If the disk check fails,
-     *                       add the volume here.
-     * @param volumeCounter  volumeCounter used to trigger callback invocation.
-     * @param callback       invoked when the volumeCounter reaches 0.
+     * For batch checks, timeout accounting is deferred to
+     * {@link StorageVolumeChecker#checkAllVolumes(Collection)} so all pending
+     * volumes are processed in one place. For single-volume checks,
+     * {@link #onFailure(Throwable)} handles timeout accounting directly.
+     */
+    private final boolean timeoutHandledInCheckAllVolumes;
+    private final Object resultLock;
+
+    /**
+     * @param healthyVolumes    set of healthy volumes.
+     * @param failedVolumes     set of failed volumes.
+     * @param volumeCounter     triggers callback when it reaches 0.
+     * @param callback          invoked when volumeCounter reaches 0.
+     * @param timeoutHandledInCheckAllVolumes true when timeout accounting is
+     *                                        deferred to checkAllVolumes.
+     * @param resultLock lock shared with checkAllVolumes result snapshotting.
      */
     ResultHandler(StorageVolume volume,
         Set<StorageVolume> healthyVolumes,
         Set<StorageVolume> failedVolumes,
         AtomicLong volumeCounter,
-        @Nullable Callback callback) {
+        @Nullable Callback callback,
+        boolean timeoutHandledInCheckAllVolumes,
+        Object resultLock) {
       this.volume = volume;
       this.healthyVolumes = healthyVolumes;
       this.failedVolumes = failedVolumes;
       this.volumeCounter = volumeCounter;
       this.callback = callback;
+      this.timeoutHandledInCheckAllVolumes = timeoutHandledInCheckAllVolumes;
+      this.resultLock = resultLock;
     }
 
     @Override
@@ -376,18 +416,44 @@ public void onFailure(@Nonnull Throwable t) {
           volume, exception);
       // If the scan was interrupted, do not count it as a volume failure.
       // This should only happen if the volume checker is being shut down.
-      if (!(t instanceof InterruptedException)) {
-        markFailed();
+      if (t instanceof InterruptedException) {
+        return;
+      }
+      // Detect a per-check timeout from ThrottledAsyncChecker.
+      // Guava 28+ (including 33.5.0-jre used here) fails the TimeoutFuture
+      // with TimeoutException on timeout.
+      boolean isTimeout = exception instanceof TimeoutException;
+      if (isTimeout) {
+        if (timeoutHandledInCheckAllVolumes) {
+          cleanup();
+          return;
+        }
+        markFailed(true);
         cleanup();
+        return;
       }
+      markFailed();
+      cleanup();
     }
 
     private void markHealthy() {
-      healthyVolumes.add(volume);
+      synchronized (resultLock) {
+        healthyVolumes.add(volume);
+      }
     }
 
     private void markFailed() {
-      failedVolumes.add(volume);
+      markFailed(false);
+    }
+
+    private void markFailed(boolean checkTimeoutFailureTolerance) {
+      synchronized (resultLock) {
+        if (checkTimeoutFailureTolerance
+            && !volume.recordTimeoutAndCheckFailure()) {
+          return;
+        }
+        failedVolumes.add(volume);
+      }
     }
 
     private void cleanup() {
diff --git a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeChecker.java b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeChecker.java
index 71cb7af04b7..f3e3a7fc2a5 100644
--- a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeChecker.java
+++ b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeChecker.java
@@ -20,6 +20,7 @@
 import static org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult.FAILED;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.isNull;
@@ -28,8 +29,11 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.SettableFuture;
 import java.io.File;
 import java.nio.file.Path;
 import java.time.Duration;
@@ -39,8 +43,13 @@
 import java.util.Optional;
 import java.util.Set;
 import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
 import org.apache.commons.io.FileUtils;
 import org.apache.hadoop.hdds.HddsConfigKeys;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
@@ -301,6 +310,182 @@ public void testNumScansSkipped() throws Exception {
     checker.shutdownAndWait(0, TimeUnit.SECONDS);
   }
 
+  /**
+   * Explicitly captures the {@link Throwable} type that
+   * {@link Futures#withTimeout} delivers to {@code onFailure()} when the
+   * deadline fires.
+   *
+   * <p>{@link ThrottledAsyncChecker} uses {@code Futures.withTimeout()}
+   * internally; this test replicates that exact call to confirm that Guava
+   * 28+ (including the 33.5.0-jre version used by Ozone) delivers a
+   * {@link TimeoutException} — NOT a {@link java.util.concurrent.CancellationException}.
+   * {@code CancellationException} in new Guava means external cancellation
+   * (e.g. executor shutdown), not a disk-check timeout, so
+   * {@link StorageVolumeChecker} {@code ResultHandler.onFailure()} only
+   * treats {@link TimeoutException} as a timeout.
+   */
+  @Test
+  public void testFuturesWithTimeoutExceptionType() throws Exception {
+    ScheduledExecutorService scheduler =
+        Executors.newSingleThreadScheduledExecutor();
+    AtomicReference<Throwable> captured = new AtomicReference<>();
+    CountDownLatch done = new CountDownLatch(1);
+
+    try {
+      // A future that never completes on its own — same situation as a
+      // check() thread blocked inside fsync().
+      SettableFuture<VolumeCheckResult> neverCompletes = SettableFuture.create();
+
+      // Wrap with a real Futures.withTimeout(), identical to what
+      // ThrottledAsyncChecker does.
+      ListenableFuture<VolumeCheckResult> timedFuture =
+          Futures.withTimeout(neverCompletes, 100, TimeUnit.MILLISECONDS,
+              scheduler);
+
+      Futures.addCallback(timedFuture, new FutureCallback<VolumeCheckResult>() {
+        @Override
+        public void onSuccess(VolumeCheckResult result) {
+          done.countDown();
+        }
+
+        @Override
+        public void onFailure(Throwable t) {
+          captured.set(t);
+          done.countDown();
+        }
+      }, MoreExecutors.directExecutor());
+
+      assertTrue(done.await(2, TimeUnit.SECONDS),
+          "Timeout should have fired within 2 seconds");
+
+      Throwable thrown = captured.get();
+      LOG.info("Futures.withTimeout() delivered to onFailure(): {}",
+          thrown.getClass().getName());
+
+      // Guava 28+ delivers TimeoutException for a timeout.
+      // CancellationException would mean external cancellation, not a timeout.
+      assertTrue(thrown instanceof TimeoutException,
+          "Expected TimeoutException from Futures.withTimeout() but got: "
+              + thrown.getClass().getName());
+    } finally {
+      scheduler.shutdownNow();
+    }
+  }
+
+  /**
+   * Verifies that when the per-check timeout inside {@link ThrottledAsyncChecker}
+   * fires on {@link StorageVolumeChecker#checkVolume}, the first timeout is
+   * tolerated (callback invoked with no failed volumes) and the second timeout
+   * within the timeout window causes the volume to be failed.
+   *
+   * <p>This test uses the real {@link ThrottledAsyncChecker} (not
+   * {@link DummyChecker}) so that the actual {@code TimeoutException}
+   * path in {@code ResultHandler.onFailure()} fires.
+   */
+  @Test
+  public void testCheckVolumeTimeoutTolerance() throws Exception {
+    setup();
+    // Use a very short check timeout so the test completes quickly.
+    OzoneConfiguration timeoutConf = new OzoneConfiguration();
+    DatanodeConfiguration dnConf = timeoutConf.getObject(DatanodeConfiguration.class);
+    dnConf.setDiskCheckTimeout(Duration.ofMillis(200));
+    dnConf.setDiskCheckMinGap(Duration.ZERO);
+    timeoutConf.setFromObject(dnConf);
+
+    // A latch-controlled mock volume: check() blocks until released.
+    HddsVolume volume = mock(HddsVolume.class);
+    CountDownLatch blockLatch = new CountDownLatch(1);
+    when(volume.check(any())).thenAnswer(inv -> {
+      blockLatch.await();
+      return VolumeCheckResult.HEALTHY;
+    });
+    // First timeout returns false (within tolerance), second returns true.
+    when(volume.recordTimeoutAndCheckFailure()).thenReturn(false).thenReturn(true);
+
+    AtomicLong callbackCount = new AtomicLong(0);
+    AtomicLong failedVolumeCount = new AtomicLong(-1);
+    CountDownLatch firstCallback = new CountDownLatch(1);
+    CountDownLatch secondCallback = new CountDownLatch(1);
+    StorageVolumeChecker checker =
+        new StorageVolumeChecker(timeoutConf, new FakeTimer(), "test-");
+
+    // First checkVolume — should time out, be tolerated, and invoke callback
+    // with no failed volumes.
+    checker.checkVolume(volume, (healthy, failed) -> {
+      failedVolumeCount.set(failed.size());
+      callbackCount.incrementAndGet();
+      firstCallback.countDown();
+    });
+
+    assertTrue(firstCallback.await(2, TimeUnit.SECONDS),
+        "Callback should fire within 2 seconds for a tolerated timeout");
+    assertEquals(1, callbackCount.get(),
+        "Callback must fire for a tolerated timeout");
+    assertEquals(0, failedVolumeCount.get(),
+        "Failed set must stay empty for a tolerated timeout");
+    verify(volume, times(1)).recordTimeoutAndCheckFailure();
+
+    // Second checkVolume — should time out and exceed tolerance (callback fired).
+    checker.checkVolume(volume, (healthy, failed) -> {
+      failedVolumeCount.set(failed.size());
+      callbackCount.incrementAndGet();
+      secondCallback.countDown();
+    });
+    assertTrue(secondCallback.await(2, TimeUnit.SECONDS),
+        "Callback should fire within 2 seconds when tolerance is exceeded");
+
+    assertEquals(2, callbackCount.get(),
+        "Callback must fire when tolerance is exceeded");
+    assertEquals(1, failedVolumeCount.get(),
+        "Failed set must contain the volume when tolerance is exceeded");
+
+    blockLatch.countDown();
+    checker.shutdownAndWait(5, TimeUnit.SECONDS);
+  }
+
+  /**
+   * Verifies that when the {@code checkAllVolumes()} latch times out and
+   * pending volumes have not yet reported a result, the timeout is recorded in
+   * the timeout window and the first timeout is tolerated.
+   *
+   * <p>This test confirms that {@code recordTimeoutAndCheckFailure()} is called on
+   * pending volumes, and that the volume is NOT in the returned failed set on
+   * the first timeout.
+   */
+  @Test
+  public void testCheckAllVolumesLatchTimeoutTolerance() throws Exception {
+    setup();
+    OzoneConfiguration timeoutConf = new OzoneConfiguration();
+    DatanodeConfiguration dnConf = timeoutConf.getObject(DatanodeConfiguration.class);
+    dnConf.setDiskCheckTimeout(Duration.ofMillis(200));
+    dnConf.setDiskCheckMinGap(Duration.ZERO);
+    timeoutConf.setFromObject(dnConf);
+
+    HddsVolume volume = mock(HddsVolume.class);
+    CountDownLatch blockLatch = new CountDownLatch(1);
+    when(volume.check(any())).thenAnswer(inv -> {
+      blockLatch.await();
+      return VolumeCheckResult.HEALTHY;
+    });
+    // Simulate: first timeout is within tolerance.
+    when(volume.recordTimeoutAndCheckFailure()).thenReturn(false);
+    when(volume.getVolumeInfoStats()).thenReturn(
+        new VolumeInfoMetrics("test-vol", volume));
+
+    StorageVolumeChecker checker =
+        new StorageVolumeChecker(timeoutConf, new FakeTimer(), "test-");
+
+    Set<? extends StorageVolume> failed =
+        checker.checkAllVolumes(Arrays.asList(volume));
+
+    assertFalse(failed.contains(volume),
+        "Volume must NOT be in failed set on first tolerated timeout");
+    verify(volume, times(1)).recordTimeoutAndCheckFailure();
+
+    blockLatch.countDown();
+    checker.shutdownAndWait(5, TimeUnit.SECONDS);
+  }
+
   /**
    * A checker to wraps the result of {@link HddsVolume#check} in
    * an ImmediateFuture.
diff --git a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeHealthChecks.java b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeHealthChecks.java
index d291916adf0..675abed1696 100644
--- a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeHealthChecks.java
+++ b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/volume/TestStorageVolumeHealthChecks.java
@@ -18,11 +18,14 @@
 package org.apache.hadoop.ozone.container.common.volume;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.time.Duration;
+import java.time.Instant;
 import java.util.UUID;
 import java.util.stream.Stream;
 import org.apache.commons.io.FileUtils;
@@ -89,6 +92,15 @@ public void setup() throws Exception {
     // needs to be cleared before each test.
     FileUtils.deleteDirectory(volumePath.toFile());
     DiskCheckUtil.clearTestImpl();
+    TEST_CLOCK.set(Instant.now());
+    DatanodeConfiguration dnConf = CONF.getObject(DatanodeConfiguration.class);
+    dnConf.setDiskCheckEnabled(true);
+    dnConf.setDiskCheckTimeoutTestEnabled(true);
+    dnConf.setVolumeIOFailureTolerance(1);
+    dnConf.setDiskCheckTimeoutFailureTolerance(1);
+    dnConf.setDiskCheckSlidingWindowTimeout(Duration.ofMinutes(70));
+    dnConf.setDiskCheckTimeoutSlidingWindowTimeout(Duration.ofMinutes(70));
+    CONF.setFromObject(dnConf);
   }
 
   @ParameterizedTest
@@ -324,6 +336,88 @@ public void testCorrectDirectoryChecked(StorageVolume.Builder<?> builder)
     volume.check(false);
   }
 
+  /**
+   * With the default settings (diskCheckTimeoutFailureTolerance=1), the first
+   * simulated timeout within the timeout window must be tolerated.
+   */
+  @ParameterizedTest
+  @MethodSource("volumeBuilders")
+  public void testFirstTimeoutWithinWindowIsTolerated(
+      StorageVolume.Builder<?> builder)
+      throws Exception {
+    StorageVolume volume = builder.build();
+    volume.format(CLUSTER_ID);
+    volume.createTmpDirs(CLUSTER_ID);
+
+    assertFalse(volume.recordTimeoutAndCheckFailure(),
+        "First timeout within the window should be tolerated");
+    assertEquals(1, volume.getTimeoutFailureSlidingWindow().getNumEventsInWindow());
+  }
+
+  /**
+   * With the default settings (diskCheckTimeoutFailureTolerance=1), the
+   * second timeout within the timeout window must fail the volume.
+   */
+  @ParameterizedTest
+  @MethodSource("volumeBuilders")
+  public void testSecondTimeoutWithinWindowFails(
+      StorageVolume.Builder<?> builder)
+      throws Exception {
+    StorageVolume volume = builder.build();
+    volume.format(CLUSTER_ID);
+    volume.createTmpDirs(CLUSTER_ID);
+
+    assertFalse(volume.recordTimeoutAndCheckFailure(),
+        "First timeout should be tolerated");
+    assertEquals(1, volume.getTimeoutFailureSlidingWindow().getNumEventsInWindow());
+
+    assertTrue(volume.recordTimeoutAndCheckFailure(),
+        "Second timeout in the window should exceed tolerance and return true");
+    assertEquals(1, volume.getTimeoutFailureSlidingWindow().getWindowSize());
+  }
+
+  /**
+   * Timeout events automatically expire from the timeout window, so an old
+   * timeout does not need an explicit reset before a later timeout is
+   * tolerated again.
+   */
+  @ParameterizedTest
+  @MethodSource("volumeBuilders")
+  public void testExpiredTimeoutDoesNotCountTowardLaterFailure(
+      StorageVolume.Builder<?> builder) throws Exception {
+    StorageVolume volume = builder.build();
+    volume.format(CLUSTER_ID);
+    volume.createTmpDirs(CLUSTER_ID);
+
+    assertFalse(volume.recordTimeoutAndCheckFailure(),
+        "First timeout should be tolerated");
+    TEST_CLOCK.fastForward(
+        volume.getTimeoutFailureSlidingWindow().getExpiryDurationMillis() + 1);
+
+    assertFalse(volume.recordTimeoutAndCheckFailure(),
+        "Timeout after the window expires should be tolerated again");
+    assertEquals(1, volume.getTimeoutFailureSlidingWindow().getNumEventsInWindow());
+  }
+
+  @ParameterizedTest
+  @MethodSource("volumeBuilders")
+  public void testTimeoutCheckDisabled(StorageVolume.Builder<?> builder)
+      throws Exception {
+    DatanodeConfiguration dnConf = CONF.getObject(DatanodeConfiguration.class);
+    dnConf.setDiskCheckTimeoutTestEnabled(false);
+    CONF.setFromObject(dnConf);
+
+    StorageVolume volume = builder.build();
+    volume.format(CLUSTER_ID);
+    volume.createTmpDirs(CLUSTER_ID);
+
+    assertFalse(volume.recordTimeoutAndCheckFailure(),
+        "Timeout tracking should be disabled");
+    assertFalse(volume.recordTimeoutAndCheckFailure(),
+        "Disabled timeout tracking should never fail the volume");
+    assertEquals(0, volume.getTimeoutFailureSlidingWindow().getNumEventsInWindow());
+  }
+
   /**
    * Asserts that the disk checks are being done on the correct directory for
    * each volume type.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org