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

weichiu pushed a commit to branch HDDS-7593
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/HDDS-7593 by this push:
     new 1802c8753f HDDS-10860. Fix Intermittent failure in 
TestLeaseRecovery.testFinalizeBlockFailure (#6707)
1802c8753f is described below

commit 1802c8753fdfdd28142736460347e890479883cd
Author: Ashish Kumar <[email protected]>
AuthorDate: Fri May 24 00:13:25 2024 +0530

    HDDS-10860. Fix Intermittent failure in 
TestLeaseRecovery.testFinalizeBlockFailure (#6707)
    
    Co-authored-by: ashishk <[email protected]>
---
 .../ozone/container/keyvalue/KeyValueHandler.java  | 26 +++++++++++++---------
 .../apache/hadoop/hdds/utils/FaultInjector.java    | 10 +++++++++
 .../apache/hadoop/fs/ozone/TestLeaseRecovery.java  |  2 ++
 .../org/apache/hadoop/utils/FaultInjectorImpl.java | 12 ++++++++++
 4 files changed, 40 insertions(+), 10 deletions(-)

diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
index ed13ebc93b..05979d85fa 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java
@@ -1470,16 +1470,22 @@ public class KeyValueHandler extends Handler {
 
   private ContainerCommandResponseProto 
checkFaultInjector(ContainerCommandRequestProto request) {
     if (injector != null) {
-      Throwable ex = injector.getException();
-      if (ex != null) {
-        // reset injector
-        injector = null;
-        return ContainerUtils.logAndReturnError(LOG, 
(StorageContainerException) ex, request);
-      }
-      try {
-        injector.pause();
-      } catch (IOException e) {
-        // do nothing
+      synchronized (injector) {
+        ContainerProtos.Type type = injector.getType();
+        if (request.getCmdType().equals(type) || type == null) {
+          Throwable ex = injector.getException();
+          if (ex != null) {
+            if (type == null) {
+              injector = null;
+            }
+            return ContainerUtils.logAndReturnError(LOG, 
(StorageContainerException) ex, request);
+          }
+          try {
+            injector.pause();
+          } catch (IOException e) {
+            // do nothing
+          }
+        }
       }
     }
     return null;
diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/FaultInjector.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/FaultInjector.java
index 32076abb3f..6be333c4c9 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/FaultInjector.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/FaultInjector.java
@@ -17,6 +17,7 @@
 package org.apache.hadoop.hdds.utils;
 
 import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
 
 import java.io.IOException;
 
@@ -49,4 +50,13 @@ public abstract class FaultInjector {
   public Throwable getException() {
     return null;
   }
+
+  @VisibleForTesting
+  public void setType(ContainerProtos.Type type) {
+  }
+
+  @VisibleForTesting
+  public ContainerProtos.Type getType() {
+    return null;
+  }
 }
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
index 3eb80d03c1..494f3d5ca2 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
@@ -265,6 +265,7 @@ public class TestLeaseRecovery {
       stream.flush();
 
       FaultInjectorImpl injector = new FaultInjectorImpl();
+      injector.setType(ContainerProtos.Type.FinalizeBlock);
       KeyValueHandler.setInjector(injector);
       StorageContainerException sce = new StorageContainerException(
           "Requested operation not allowed as ContainerState is CLOSED",
@@ -357,6 +358,7 @@ public class TestLeaseRecovery {
       OzoneTestUtils.closeContainer(cluster.getStorageContainerManager(), 
container);
       // pause getCommittedBlockLength handling on all DNs to make sure all 
getCommittedBlockLength will time out
       FaultInjectorImpl injector = new FaultInjectorImpl();
+      injector.setType(ContainerProtos.Type.GetCommittedBlockLength);
       KeyValueHandler.setInjector(injector);
       GenericTestUtils.LogCapturer logs =
           
GenericTestUtils.LogCapturer.captureLogs(XceiverClientGrpc.getLogger());
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/utils/FaultInjectorImpl.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/utils/FaultInjectorImpl.java
index 8656811fa8..0be075e865 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/utils/FaultInjectorImpl.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/utils/FaultInjectorImpl.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.utils;
 
 import com.google.common.annotations.VisibleForTesting;
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
 import org.apache.hadoop.hdds.utils.FaultInjector;
 import org.assertj.core.api.Fail;
 import org.junit.jupiter.api.Assertions;
@@ -32,6 +33,7 @@ public class FaultInjectorImpl extends FaultInjector {
   private CountDownLatch ready;
   private CountDownLatch wait;
   private Throwable ex;
+  private ContainerProtos.Type type = null;
 
   public FaultInjectorImpl() {
     init();
@@ -79,5 +81,15 @@ public class FaultInjectorImpl extends FaultInjector {
   public Throwable getException() {
     return ex;
   }
+
+  @VisibleForTesting
+  public void setType(ContainerProtos.Type type) {
+    this.type = type;
+  }
+
+  @VisibleForTesting
+  public ContainerProtos.Type getType() {
+    return type;
+  }
 }
 


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

Reply via email to