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

chihsuan 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 b4bfca73b0f HDDS-16120. A single MiniOzoneCluster build timeout 
cascades into whole-suite failures in MiniOzoneClusterProvider (#10989)
b4bfca73b0f is described below

commit b4bfca73b0fa397a9369aed4b5e8f5c47eb38a62
Author: Eric C. Ho <[email protected]>
AuthorDate: Thu Oct 22 18:28:15 2026 +0800

    HDDS-16120. A single MiniOzoneCluster build timeout cascades into 
whole-suite failures in MiniOzoneClusterProvider (#10989)
    
    Co-authored-by: Siyao Meng <[email protected]>
---
 .../hadoop/ozone/MiniOzoneClusterProvider.java     |  71 ++++++++-
 .../hadoop/ozone/TestMiniOzoneClusterProvider.java | 169 +++++++++++++++++++++
 2 files changed, 232 insertions(+), 8 deletions(-)

diff --git 
a/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
 
b/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
index a7373e5322c..54e1c12e792 100644
--- 
a/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
+++ 
b/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
@@ -117,6 +117,7 @@ public class MiniOzoneClusterProvider {
   private static final int PRE_CREATE_LIMIT = 1;
   private static final int EXPIRED_LIMIT = 4;
   private volatile boolean shutdown = false;
+  private volatile boolean shutdownRequested = false;
   private final int clusterLimit;
   private int consumedClusterCount = 0;
 
@@ -125,7 +126,7 @@ public class MiniOzoneClusterProvider {
   private final Thread reapThread;
 
   private final Set<MiniOzoneCluster> createdClusters = new HashSet<>();
-  private final BlockingQueue<MiniOzoneCluster> clusters
+  private final BlockingQueue<ClusterCreationResult> clusterResults
       = new ArrayBlockingQueue<>(PRE_CREATE_LIMIT);
   private final BlockingQueue<MiniOzoneCluster> expiredClusters
       = new ArrayBlockingQueue<>(EXPIRED_LIMIT);
@@ -152,10 +153,14 @@ public synchronized MiniOzoneCluster provide()
           + "been reached for this provider. Please increase the value set "
           + "in the constructor");
     }
-    MiniOzoneCluster cluster = clusters.poll(100, SECONDS);
-    if (cluster == null) {
+    ClusterCreationResult result = clusterResults.poll(100, SECONDS);
+    if (result == null) {
       throw new IOException("Failed to obtain available cluster in time");
     }
+    if (result.getFailure() != null) {
+      throw result.getFailure();
+    }
+    MiniOzoneCluster cluster = result.getCluster();
     createdClusters.add(cluster);
     consumedClusterCount++;
     return cluster;
@@ -169,6 +174,7 @@ public synchronized void destroy(MiniOzoneCluster c)
   }
 
   public synchronized void shutdown() throws InterruptedException {
+    shutdownRequested = true;
     createThread.interrupt();
     createThread.join();
     destroyRemainingClusters();
@@ -215,14 +221,27 @@ private Thread createClusters() {
           cluster = builder.build();
           cluster.waitForClusterToBeReady();
           createdCount++;
-          clusters.put(cluster);
+          if (!addClusterResult(ClusterCreationResult.success(cluster))) {
+            cluster.shutdown();
+            break;
+          }
         } catch (InterruptedException e) {
           if (cluster != null) {
             cluster.shutdown();
           }
           break;
-        } catch (IOException | TimeoutException e) {
-          throw new RuntimeException("Unable to build cluster", e);
+        } catch (IOException | TimeoutException | RuntimeException e) {
+          LOG.warn("Unable to build cluster: {}", e.toString());
+          if (cluster != null) {
+            cluster.shutdown();
+          }
+          try {
+            if (!addClusterResult(ClusterCreationResult.failure(e))) {
+              break;
+            }
+          } catch (InterruptedException interrupted) {
+            break;
+          }
         }
       }
     });
@@ -231,10 +250,20 @@ private Thread createClusters() {
     return t;
   }
 
+  private boolean addClusterResult(ClusterCreationResult result) throws 
InterruptedException {
+    while (!shutdownRequested) {
+      if (clusterResults.offer(result, 1, SECONDS)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   private void destroyRemainingClusters() {
-    while (!clusters.isEmpty()) {
+    while (!clusterResults.isEmpty()) {
       try {
-        MiniOzoneCluster cluster = clusters.poll();
+        ClusterCreationResult result = clusterResults.poll();
+        MiniOzoneCluster cluster = result == null ? null : result.getCluster();
         if (cluster != null) {
           destroy(cluster);
         }
@@ -258,4 +287,30 @@ private void destroyRemainingClusters() {
     createdClusters.clear();
   }
 
+  private static final class ClusterCreationResult {
+    private final MiniOzoneCluster cluster;
+    private final IOException failure;
+
+    private ClusterCreationResult(MiniOzoneCluster cluster, IOException 
failure) {
+      this.cluster = cluster;
+      this.failure = failure;
+    }
+
+    private static ClusterCreationResult success(MiniOzoneCluster cluster) {
+      return new ClusterCreationResult(cluster, null);
+    }
+
+    private static ClusterCreationResult failure(Exception failure) {
+      return new ClusterCreationResult(null, new IOException("Unable to build 
cluster", failure));
+    }
+
+    private MiniOzoneCluster getCluster() {
+      return cluster;
+    }
+
+    private IOException getFailure() {
+      return failure;
+    }
+  }
+
 }
diff --git 
a/hadoop-ozone/mini-cluster/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneClusterProvider.java
 
b/hadoop-ozone/mini-cluster/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneClusterProvider.java
new file mode 100644
index 00000000000..bdc8b7cfad6
--- /dev/null
+++ 
b/hadoop-ozone/mini-cluster/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneClusterProvider.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Queue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.junit.jupiter.api.Test;
+
+class TestMiniOzoneClusterProvider {
+
+  @Test
+  void retriesAfterBuildFailure() throws Exception {
+    IOException failure = new IOException("failed");
+    MiniOzoneCluster first = mock(MiniOzoneCluster.class);
+    MiniOzoneCluster second = mock(MiniOzoneCluster.class);
+    TestBuilder builder = new TestBuilder(failure, first, second);
+    MiniOzoneClusterProvider provider = new MiniOzoneClusterProvider(builder, 
2);
+
+    try {
+      IOException exception = assertThrows(IOException.class, 
provider::provide);
+      assertSame(failure, exception.getCause());
+      assertSame(first, provider.provide());
+      assertSame(second, provider.provide());
+      assertEquals(3, builder.getBuildCount());
+    } finally {
+      provider.shutdown();
+    }
+  }
+
+  @Test
+  void retriesAfterReadinessTimeoutAndShutsDownCluster() throws Exception {
+    TimeoutException failure = new TimeoutException("failed");
+    MiniOzoneCluster failed = mock(MiniOzoneCluster.class);
+    doThrow(failure).when(failed).waitForClusterToBeReady();
+    MiniOzoneCluster first = mock(MiniOzoneCluster.class);
+    MiniOzoneCluster second = mock(MiniOzoneCluster.class);
+    TestBuilder builder = new TestBuilder(failed, first, second);
+    MiniOzoneClusterProvider provider = new MiniOzoneClusterProvider(builder, 
2);
+
+    try {
+      IOException exception = assertThrows(IOException.class, 
provider::provide);
+      assertSame(failure, exception.getCause());
+      assertSame(first, provider.provide());
+      assertSame(second, provider.provide());
+      assertEquals(3, builder.getBuildCount());
+      verify(failed).shutdown();
+    } finally {
+      provider.shutdown();
+    }
+  }
+
+  @Test
+  void retriesAfterRuntimeBuildFailure() throws Exception {
+    RuntimeException failure = new IllegalStateException("failed");
+    MiniOzoneCluster first = mock(MiniOzoneCluster.class);
+    TestBuilder builder = new TestBuilder(failure, first);
+    MiniOzoneClusterProvider provider = new MiniOzoneClusterProvider(builder, 
1);
+
+    try {
+      IOException exception = assertThrows(IOException.class, 
provider::provide);
+      assertSame(failure, exception.getCause());
+      assertSame(first, provider.provide());
+      assertEquals(2, builder.getBuildCount());
+    } finally {
+      provider.shutdown();
+    }
+  }
+
+  @Test
+  void retriesAfterRuntimeReadinessFailureAndShutsDownCluster() throws 
Exception {
+    RuntimeException failure = new IllegalStateException("failed");
+    MiniOzoneCluster failed = mock(MiniOzoneCluster.class);
+    doThrow(failure).when(failed).waitForClusterToBeReady();
+    MiniOzoneCluster first = mock(MiniOzoneCluster.class);
+    TestBuilder builder = new TestBuilder(failed, first);
+    MiniOzoneClusterProvider provider = new MiniOzoneClusterProvider(builder, 
1);
+
+    try {
+      IOException exception = assertThrows(IOException.class, 
provider::provide);
+      assertSame(failure, exception.getCause());
+      verify(failed).shutdown();
+      assertSame(first, provider.provide());
+      assertEquals(2, builder.getBuildCount());
+    } finally {
+      provider.shutdown();
+    }
+  }
+
+  @Test
+  void shutdownDoesNotBlockWhenClusterCreationConsumesInterrupt() throws 
Exception {
+    IOException failure = new IOException("failed");
+    MiniOzoneCluster cluster = mock(MiniOzoneCluster.class);
+    CountDownLatch readinessStarted = new CountDownLatch(1);
+    doAnswer(invocation -> {
+      readinessStarted.countDown();
+      try {
+        new CountDownLatch(1).await();
+      } catch (InterruptedException ignored) {
+        // Simulate cluster creation consuming the shutdown interrupt.
+      }
+      return null;
+    }).when(cluster).waitForClusterToBeReady();
+    MiniOzoneClusterProvider provider = new MiniOzoneClusterProvider(new 
TestBuilder(failure, cluster), 1);
+
+    assertTrue(readinessStarted.await(5, TimeUnit.SECONDS));
+    assertTimeoutPreemptively(Duration.ofSeconds(5), provider::shutdown);
+    verify(cluster).shutdown();
+  }
+
+  private static final class TestBuilder extends MiniOzoneCluster.Builder {
+    private final Queue<Object> results;
+    private final AtomicInteger buildCount = new AtomicInteger();
+
+    private TestBuilder(Object... results) {
+      super(new OzoneConfiguration());
+      this.results = new ArrayDeque<>(Arrays.asList(results));
+    }
+
+    @Override
+    public MiniOzoneCluster build() throws IOException {
+      buildCount.incrementAndGet();
+      Object result = results.remove();
+      if (result instanceof IOException) {
+        throw (IOException) result;
+      }
+      if (result instanceof RuntimeException) {
+        throw (RuntimeException) result;
+      }
+      return (MiniOzoneCluster) result;
+    }
+
+    private int getBuildCount() {
+      return buildCount.get();
+    }
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to