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

inigoiri pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-2.10 by this push:
     new b5eb08a  HDFS-15038. TestFsck testFsckListCorruptSnapshotFiles is 
failing in trunk. Contributed by hemanthboyina.
b5eb08a is described below

commit b5eb08a0d9c2c56bf83103f0c5c9288e338281f3
Author: Inigo Goiri <inigo...@apache.org>
AuthorDate: Thu May 14 11:26:31 2020 -0700

    HDFS-15038. TestFsck testFsckListCorruptSnapshotFiles is failing in trunk. 
Contributed by hemanthboyina.
---
 .../hadoop/hdfs/server/namenode/TestFsck.java      | 51 ++++++++++++----------
 1 file changed, 29 insertions(+), 22 deletions(-)

diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
index 334f38a..b05e576 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java
@@ -1034,17 +1034,7 @@ public class TestFsck {
       }
     }
 
-    // wait for the namenode to see the corruption
-    final NamenodeProtocols namenode = cluster.getNameNodeRpc();
-    CorruptFileBlocks corruptFileBlocks = namenode
-        .listCorruptFileBlocks("/corruptData", null);
-    int numCorrupt = corruptFileBlocks.getFiles().length;
-    while (numCorrupt == 0) {
-      Thread.sleep(1000);
-      corruptFileBlocks = namenode
-          .listCorruptFileBlocks("/corruptData", null);
-      numCorrupt = corruptFileBlocks.getFiles().length;
-    }
+    waitForCorruptionBlocks(3, "/corruptData");
     outStr = runFsck(conf, -1, true, "/corruptData", 
"-list-corruptfileblocks");
     System.out.println("2. bad fsck out: " + outStr);
     assertTrue(outStr.contains("has 3 CORRUPT files"));
@@ -1956,17 +1946,7 @@ public class TestFsck {
     hdfs.delete(fp, false);
     numFiles--;
 
-    // wait for the namenode to see the corruption
-    final NamenodeProtocols namenode = cluster.getNameNodeRpc();
-    CorruptFileBlocks corruptFileBlocks = namenode
-        .listCorruptFileBlocks("/corruptData", null);
-    int numCorrupt = corruptFileBlocks.getFiles().length;
-    while (numCorrupt == 0) {
-      Thread.sleep(1000);
-      corruptFileBlocks = namenode
-          .listCorruptFileBlocks("/corruptData", null);
-      numCorrupt = corruptFileBlocks.getFiles().length;
-    }
+    waitForCorruptionBlocks(numSnapshots, "/corruptData");
 
     // with -includeSnapshots all files are reported
     outStr = runFsck(conf, -1, true, "/corruptData",
@@ -1984,6 +1964,33 @@ public class TestFsck {
     assertFalse(outStr.contains("/.snapshot/"));
   }
 
+  /**
+   * Wait for the namenode to see the corruption.
+   * @param corruptBlocks The expected number of corruptfilelocks
+   * @param path The Directory Path where corruptfileblocks exists
+   * @throws IOException
+   */
+  private void waitForCorruptionBlocks(final int corruptBlocks,
+      final String path) throws Exception {
+    GenericTestUtils.waitFor(new Supplier<Boolean>() {
+      @Override
+      public Boolean get() {
+        try {
+          final NamenodeProtocols namenode = cluster.getNameNodeRpc();
+          CorruptFileBlocks corruptFileBlocks =
+              namenode.listCorruptFileBlocks(path, null);
+          int numCorrupt = corruptFileBlocks.getFiles().length;
+          if (numCorrupt == corruptBlocks) {
+            return true;
+          }
+        } catch (Exception e) {
+          LOG.error("Exception while getting Corrupt file blocks", e);
+        }
+        return false;
+      }
+    }, 100, 10000);
+  }
+
   @Test (timeout = 300000)
   public void testFsckMoveAfterCorruption() throws Exception {
     final int dfsBlockSize = 512 * 1024;


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to