Przeglądaj źródła

HDFS-13772. Erasure coding: Unnecessary NameNode Logs displaying for Enabling/Disabling Erasure coding policies which are already enabled/disabled. Contributed by Ayush Saxena

(cherry picked from commit 8df2eb8119188b8e5515295523afc23046e1db81)
Vinayakumar B 6 lat temu
rodzic
commit
76be3515bf

+ 10 - 5
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java

@@ -356,7 +356,7 @@ public final class ErasureCodingPolicyManager {
   /**
   /**
    * Disable an erasure coding policy by policyName.
    * Disable an erasure coding policy by policyName.
    */
    */
-  public synchronized void disablePolicy(String name) {
+  public synchronized boolean disablePolicy(String name) {
     ErasureCodingPolicyInfo info = policiesByName.get(name);
     ErasureCodingPolicyInfo info = policiesByName.get(name);
     if (info == null) {
     if (info == null) {
       throw new HadoopIllegalArgumentException("The policy name " +
       throw new HadoopIllegalArgumentException("The policy name " +
@@ -367,27 +367,32 @@ public final class ErasureCodingPolicyManager {
       enabledPoliciesByName.remove(name);
       enabledPoliciesByName.remove(name);
       enabledPolicies =
       enabledPolicies =
           enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]);
           enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]);
+      info.setState(ErasureCodingPolicyState.DISABLED);
+      LOG.info("Disable the erasure coding policy " + name);
+      return true;
     }
     }
-    info.setState(ErasureCodingPolicyState.DISABLED);
-    LOG.info("Disable the erasure coding policy " + name);
+    return false;
   }
   }
 
 
   /**
   /**
    * Enable an erasure coding policy by policyName.
    * Enable an erasure coding policy by policyName.
    */
    */
-  public synchronized void enablePolicy(String name) {
+  public synchronized boolean enablePolicy(String name) {
     final ErasureCodingPolicyInfo info = policiesByName.get(name);
     final ErasureCodingPolicyInfo info = policiesByName.get(name);
     if (info == null) {
     if (info == null) {
       throw new HadoopIllegalArgumentException("The policy name " +
       throw new HadoopIllegalArgumentException("The policy name " +
           name + " does not exist");
           name + " does not exist");
     }
     }
-
+    if (enabledPoliciesByName.containsKey(name)) {
+      return false;
+    }
     final ErasureCodingPolicy ecPolicy = info.getPolicy();
     final ErasureCodingPolicy ecPolicy = info.getPolicy();
     enabledPoliciesByName.put(name, ecPolicy);
     enabledPoliciesByName.put(name, ecPolicy);
     info.setState(ErasureCodingPolicyState.ENABLED);
     info.setState(ErasureCodingPolicyState.ENABLED);
     enabledPolicies =
     enabledPolicies =
         enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]);
         enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]);
     LOG.info("Enable the erasure coding policy " + name);
     LOG.info("Enable the erasure coding policy " + name);
+    return true;
   }
   }
 
 
   /**
   /**

+ 16 - 6
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java

@@ -252,11 +252,16 @@ final class FSDirErasureCodingOp {
    *                      rebuilding
    *                      rebuilding
    * @throws IOException
    * @throws IOException
    */
    */
-  static void enableErasureCodingPolicy(final FSNamesystem fsn,
+  static boolean enableErasureCodingPolicy(final FSNamesystem fsn,
       String ecPolicyName, final boolean logRetryCache) throws IOException {
       String ecPolicyName, final boolean logRetryCache) throws IOException {
     Preconditions.checkNotNull(ecPolicyName);
     Preconditions.checkNotNull(ecPolicyName);
-    fsn.getErasureCodingPolicyManager().enablePolicy(ecPolicyName);
-    fsn.getEditLog().logEnableErasureCodingPolicy(ecPolicyName, logRetryCache);
+    boolean success =
+        fsn.getErasureCodingPolicyManager().enablePolicy(ecPolicyName);
+    if (success) {
+      fsn.getEditLog().logEnableErasureCodingPolicy(ecPolicyName,
+          logRetryCache);
+    }
+    return success;
   }
   }
 
 
   /**
   /**
@@ -268,11 +273,16 @@ final class FSDirErasureCodingOp {
    *                      rebuilding
    *                      rebuilding
    * @throws IOException
    * @throws IOException
    */
    */
-  static void disableErasureCodingPolicy(final FSNamesystem fsn,
+  static boolean disableErasureCodingPolicy(final FSNamesystem fsn,
       String ecPolicyName, final boolean logRetryCache) throws IOException {
       String ecPolicyName, final boolean logRetryCache) throws IOException {
     Preconditions.checkNotNull(ecPolicyName);
     Preconditions.checkNotNull(ecPolicyName);
-    fsn.getErasureCodingPolicyManager().disablePolicy(ecPolicyName);
-    fsn.getEditLog().logDisableErasureCodingPolicy(ecPolicyName, logRetryCache);
+    boolean success =
+        fsn.getErasureCodingPolicyManager().disablePolicy(ecPolicyName);
+    if (success) {
+      fsn.getEditLog().logDisableErasureCodingPolicy(ecPolicyName,
+          logRetryCache);
+    }
+    return success;
   }
   }
 
 
   private static List<XAttr> removeErasureCodingPolicyXAttr(
   private static List<XAttr> removeErasureCodingPolicyXAttr(

+ 15 - 11
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -7407,29 +7407,31 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
    * @param ecPolicyName the name of the policy to be enabled
    * @param ecPolicyName the name of the policy to be enabled
    * @param logRetryCache whether to record RPC ids in editlog for retry cache
    * @param logRetryCache whether to record RPC ids in editlog for retry cache
    *                      rebuilding
    *                      rebuilding
+   * @return
    * @throws IOException
    * @throws IOException
    */
    */
-  void enableErasureCodingPolicy(String ecPolicyName,
+  boolean enableErasureCodingPolicy(String ecPolicyName,
       final boolean logRetryCache) throws IOException {
       final boolean logRetryCache) throws IOException {
     final String operationName = "enableErasureCodingPolicy";
     final String operationName = "enableErasureCodingPolicy";
     checkOperation(OperationCategory.WRITE);
     checkOperation(OperationCategory.WRITE);
     boolean success = false;
     boolean success = false;
-    LOG.info("Enable the erasure coding policy " + ecPolicyName);
     writeLock();
     writeLock();
     try {
     try {
       checkOperation(OperationCategory.WRITE);
       checkOperation(OperationCategory.WRITE);
       checkNameNodeSafeMode("Cannot enable erasure coding policy "
       checkNameNodeSafeMode("Cannot enable erasure coding policy "
           + ecPolicyName);
           + ecPolicyName);
-      FSDirErasureCodingOp.enableErasureCodingPolicy(this, ecPolicyName,
-          logRetryCache);
-      success = true;
+      success = FSDirErasureCodingOp.enableErasureCodingPolicy(this,
+          ecPolicyName, logRetryCache);
+    } catch (AccessControlException ace) {
+      logAuditEvent(false, operationName, ecPolicyName, null, null);
     } finally {
     } finally {
       writeUnlock(operationName);
       writeUnlock(operationName);
       if (success) {
       if (success) {
         getEditLog().logSync();
         getEditLog().logSync();
+        logAuditEvent(success, operationName, ecPolicyName, null, null);
       }
       }
-      logAuditEvent(success, operationName, ecPolicyName, null, null);
     }
     }
+    return success;
   }
   }
 
 
   /**
   /**
@@ -7439,7 +7441,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
    *                      rebuilding
    *                      rebuilding
    * @throws IOException
    * @throws IOException
    */
    */
-  void disableErasureCodingPolicy(String ecPolicyName,
+  boolean disableErasureCodingPolicy(String ecPolicyName,
       final boolean logRetryCache) throws IOException {
       final boolean logRetryCache) throws IOException {
     final String operationName = "disableErasureCodingPolicy";
     final String operationName = "disableErasureCodingPolicy";
     checkOperation(OperationCategory.WRITE);
     checkOperation(OperationCategory.WRITE);
@@ -7450,16 +7452,18 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
       checkOperation(OperationCategory.WRITE);
       checkOperation(OperationCategory.WRITE);
       checkNameNodeSafeMode("Cannot disable erasure coding policy "
       checkNameNodeSafeMode("Cannot disable erasure coding policy "
           + ecPolicyName);
           + ecPolicyName);
-      FSDirErasureCodingOp.disableErasureCodingPolicy(this, ecPolicyName,
-          logRetryCache);
-      success = true;
+      success = FSDirErasureCodingOp.disableErasureCodingPolicy(this,
+          ecPolicyName, logRetryCache);
+    } catch (AccessControlException ace) {
+      logAuditEvent(false, operationName, ecPolicyName, null, null);
     } finally {
     } finally {
       writeUnlock(operationName);
       writeUnlock(operationName);
       if (success) {
       if (success) {
         getEditLog().logSync();
         getEditLog().logSync();
+        logAuditEvent(success, operationName, ecPolicyName, null, null);
       }
       }
-      logAuditEvent(success, operationName, ecPolicyName, null, null);
     }
     }
+    return success;
   }
   }
 
 
   /**
   /**

+ 4 - 4
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java

@@ -2416,8 +2416,8 @@ public class NameNodeRpcServer implements NamenodeProtocols {
     }
     }
     boolean success = false;
     boolean success = false;
     try {
     try {
-      namesystem.enableErasureCodingPolicy(ecPolicyName, cacheEntry != null);
-      success = true;
+      success = namesystem.enableErasureCodingPolicy(ecPolicyName,
+          cacheEntry != null);
     } finally {
     } finally {
       RetryCache.setState(cacheEntry, success);
       RetryCache.setState(cacheEntry, success);
     }
     }
@@ -2434,8 +2434,8 @@ public class NameNodeRpcServer implements NamenodeProtocols {
     }
     }
     boolean success = false;
     boolean success = false;
     try {
     try {
-      namesystem.disableErasureCodingPolicy(ecPolicyName, cacheEntry != null);
-      success = true;
+      success = namesystem.disableErasureCodingPolicy(ecPolicyName,
+          cacheEntry != null);
     } finally {
     } finally {
       RetryCache.setState(cacheEntry, success);
       RetryCache.setState(cacheEntry, success);
     }
     }

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java

@@ -463,7 +463,7 @@ public class TestNamenodeRetryCache {
     assertTrue(namesystem.hasRetryCache());
     assertTrue(namesystem.hasRetryCache());
     cacheSet = (LightWeightCache<CacheEntry, CacheEntry>) namesystem
     cacheSet = (LightWeightCache<CacheEntry, CacheEntry>) namesystem
         .getRetryCache().getCacheSet();
         .getRetryCache().getCacheSet();
-    assertEquals("Retry cache size is wrong", 39, cacheSet.size());
+    assertEquals("Retry cache size is wrong", 38, cacheSet.size());
     iter = cacheSet.iterator();
     iter = cacheSet.iterator();
     while (iter.hasNext()) {
     while (iter.hasNext()) {
       CacheEntry entry = iter.next();
       CacheEntry entry = iter.next();

+ 1 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java

@@ -194,7 +194,7 @@ public class TestRetryCacheWithHA {
     FSNamesystem fsn1 = cluster.getNamesystem(1);
     FSNamesystem fsn1 = cluster.getNamesystem(1);
     cacheSet = (LightWeightCache<CacheEntry, CacheEntry>) fsn1
     cacheSet = (LightWeightCache<CacheEntry, CacheEntry>) fsn1
         .getRetryCache().getCacheSet();
         .getRetryCache().getCacheSet();
-    assertEquals("Retry cache size is wrong", 39, cacheSet.size());
+    assertEquals("Retry cache size is wrong", 38, cacheSet.size());
     iter = cacheSet.iterator();
     iter = cacheSet.iterator();
     while (iter.hasNext()) {
     while (iter.hasNext()) {
       CacheEntry entry = iter.next();
       CacheEntry entry = iter.next();