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

adoroszlai 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 39482738d90 HDDS-17634. Intermittent failure in 
TestXceiverClientManagerCloseContention#evictionDrivenCloseDoesNotSerializeAcquisition
 (#11876)
39482738d90 is described below

commit 39482738d9002e05016ba0952473aca51a4353f4
Author: Andrey Yarovoy <[email protected]>
AuthorDate: Tue Nov 3 03:58:21 2026 -0500

    HDDS-17634. Intermittent failure in 
TestXceiverClientManagerCloseContention#evictionDrivenCloseDoesNotSerializeAcquisition
 (#11876)
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../TestXceiverClientManagerCloseContention.java   | 89 ++++++++++++++++------
 1 file changed, 65 insertions(+), 24 deletions(-)

diff --git 
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerCloseContention.java
 
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerCloseContention.java
index 42de6365617..f286c34531a 100644
--- 
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerCloseContention.java
+++ 
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/TestXceiverClientManagerCloseContention.java
@@ -23,6 +23,9 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.withSettings;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
@@ -83,11 +86,12 @@
  * evicted and closed on essentially every acquisition — mirroring the per-file
  * client churn of EC checksum collection.
  *
- * <p>Run it against the pre-fix {@code close()} and the wall-clock is 
dominated
- * by serialized 100ms sleeps ({@code ~ evictions * 100ms}); run it against the
- * fix (immediate {@code shutdownNow()}) and per-close cost collapses. The
- * assertion below encodes the fixed expectation, so this test FAILS on the
- * regression and PASSES once HDDS-15849 restores immediate termination.
+ * <p>Each eviction-driven {@code close()} is timed on its own. Against the
+ * pre-fix {@code close()} every one of them takes at least 100ms; with the fix
+ * (immediate {@code shutdownNow()}) they take a few milliseconds. Timing the
+ * closes themselves keeps client creation and the queueing of closes on the
+ * manager's single close thread out of the measurement, so a slow machine does
+ * not push the result towards the regression (HDDS-17634).
  */
 class TestXceiverClientManagerCloseContention {
 
@@ -98,13 +102,12 @@ class TestXceiverClientManagerCloseContention {
   private static final int CYCLES_PER_THREAD = 8;
 
   /**
-   * Upper bound on acceptable average wall-clock cost per eviction-driven
-   * close(). The pre-fix code has a hard &ge;100ms floor per close (the
-   * mandatory Thread.sleep in the termination polling loop); immediate
-   * shutdownNow() is well under a millisecond. 40ms sits safely between the
-   * two so the assertion is not timing-flaky.
+   * Upper bound on the median duration of one eviction-driven close(). The
+   * pre-fix code has a hard &ge;100ms floor on every close (the mandatory
+   * Thread.sleep in the termination polling loop), so its median is above it;
+   * immediate shutdownNow() takes a few milliseconds.
    */
-  private static final long MAX_MILLIS_PER_CLOSE = 40;
+  private static final long MAX_MEDIAN_MILLIS_PER_CLOSE = 50;
 
   @Test
   void evictionDrivenCloseDoesNotSerializeAcquisition() throws Exception {
@@ -115,9 +118,10 @@ void evictionDrivenCloseDoesNotSerializeAcquisition() 
throws Exception {
         .setMaxCacheSize(1)
         .setStaleThresholdMs(TimeUnit.SECONDS.toMillis(30))
         .build();
+    // duration of each close() that actually closed a client
+    List<Long> closeNanos = Collections.synchronizedList(new ArrayList<>());
 
-    try (XceiverClientManager manager =
-             new XceiverClientManager(conf, clientConf, (ClientTrustManager) 
null)) {
+    try (XceiverClientManager manager = newManagerTimingCloses(conf, 
clientConf, closeNanos)) {
 
       ExecutorService pool = Executors.newFixedThreadPool(THREADS);
       CountDownLatch start = new CountDownLatch(1);
@@ -145,32 +149,69 @@ void evictionDrivenCloseDoesNotSerializeAcquisition() 
throws Exception {
       } finally {
         pool.shutdownNow();
       }
-      // closing the manager waits for the closes still queued, so that their 
cost is measured
+      // closing the manager waits for the closes still queued, so that all of 
them are timed
       manager.close();
       long wallMillis =
           TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - wallStartNanos);
 
       // recordStats() is enabled on the cache; each eviction drives one 
close().
       long evictions = manager.getClientCache().stats().evictionCount();
-      long millisPerClose = evictions == 0 ? 0 : wallMillis / evictions;
+      List<Long> sortedMillis;
+      synchronized (closeNanos) {
+        sortedMillis = 
closeNanos.stream().map(TimeUnit.NANOSECONDS::toMillis).sorted().collect(Collectors.toList());
+      }
+      long medianMillisPerClose = sortedMillis.isEmpty() ? 0 : 
sortedMillis.get(sortedMillis.size() / 2);
 
-      LOG.info("threads={} cyclesPerThread={} acquisitions={} 
evictions(closes)={}",
-          THREADS, CYCLES_PER_THREAD, THREADS * CYCLES_PER_THREAD, evictions);
-      LOG.info("wall={}ms  ms-per-close={}ms  (regression floor is 
~100ms/close)",
-          wallMillis, millisPerClose);
+      LOG.info("threads={} cyclesPerThread={} acquisitions={} evictions={} 
closes={}",
+          THREADS, CYCLES_PER_THREAD, THREADS * CYCLES_PER_THREAD, evictions, 
sortedMillis.size());
+      LOG.info("wall={}ms  close median={}ms max={}ms  (regression floor is 
~100ms/close)",
+          wallMillis, medianMillisPerClose, sortedMillis.isEmpty() ? 0 : 
sortedMillis.get(sortedMillis.size() - 1));
 
       assertThat(evictions)
           .as("cache eviction should have driven close() calls")
           .isPositive();
+      assertThat((long) sortedMillis.size())
+          .as("every evicted client should have been closed")
+          .isGreaterThanOrEqualTo(evictions);
 
-      assertThat(millisPerClose)
-          .as("HDDS-15849: eviction-driven close() must not serialize "
-              + "acquisition under the clientCache monitor; the pre-fix "
-              + "graceful-shutdown wait forces a ~100ms floor per close")
-          .isLessThan(MAX_MILLIS_PER_CLOSE);
+      assertThat(medianMillisPerClose)
+          .as("HDDS-15849: eviction-driven close() must terminate the channel "
+              + "immediately; the pre-fix graceful-shutdown wait forces a 
~100ms "
+              + "floor per close")
+          .isLessThan(MAX_MEDIAN_MILLIS_PER_CLOSE);
     }
   }
 
+  /**
+   * A manager that creates the same real {@link XceiverClientGrpc} it would 
otherwise, but adds the duration of each
+   * close() that actually closes a client to {@code closeNanos}.
+   */
+  private static XceiverClientManager 
newManagerTimingCloses(ConfigurationSource conf, ScmClientConfig clientConf,
+      List<Long> closeNanos) throws IOException {
+    return new XceiverClientManager(conf, clientConf, (ClientTrustManager) 
null) {
+      @Override
+      protected XceiverClientSpi newClient(Pipeline pipeline, DatanodeDetails 
dn) throws IOException {
+        XceiverClientGrpc client = new XceiverClientGrpc(pipeline, conf) {
+          @Override
+          public void close() {
+            final boolean open = !isClosed();
+            final long startNanos = System.nanoTime();
+            super.close();
+            if (open) {
+              closeNanos.add(System.nanoTime() - startNanos);
+            }
+          }
+        };
+        try {
+          client.connect();
+        } catch (Exception e) {
+          throw new IOException(e);
+        }
+        return client;
+      }
+    };
+  }
+
   /**
    * A client whose close() is slow, like XceiverClientRatis waiting for 
channel termination, must be closed
    * off the caller thread and outside the clientCache lock.


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

Reply via email to