diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java index 3a310dae871..e7de05b00d0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ErasureCodingPolicyManager.java +++ b/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. */ - public synchronized void disablePolicy(String name) { + public synchronized boolean disablePolicy(String name) { ErasureCodingPolicyInfo info = policiesByName.get(name); if (info == null) { throw new HadoopIllegalArgumentException("The policy name " + @@ -367,27 +367,32 @@ public final class ErasureCodingPolicyManager { enabledPoliciesByName.remove(name); enabledPolicies = 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. */ - public synchronized void enablePolicy(String name) { + public synchronized boolean enablePolicy(String name) { final ErasureCodingPolicyInfo info = policiesByName.get(name); if (info == null) { throw new HadoopIllegalArgumentException("The policy name " + name + " does not exist"); } - + if (enabledPoliciesByName.containsKey(name)) { + return false; + } final ErasureCodingPolicy ecPolicy = info.getPolicy(); enabledPoliciesByName.put(name, ecPolicy); info.setState(ErasureCodingPolicyState.ENABLED); enabledPolicies = enabledPoliciesByName.values().toArray(new ErasureCodingPolicy[0]); LOG.info("Enable the erasure coding policy " + name); + return true; } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java index 3a32db45875..f6a40937272 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java @@ -252,11 +252,16 @@ final class FSDirErasureCodingOp { * rebuilding * @throws IOException */ - static void enableErasureCodingPolicy(final FSNamesystem fsn, + static boolean enableErasureCodingPolicy(final FSNamesystem fsn, String ecPolicyName, final boolean logRetryCache) throws IOException { 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 * @throws IOException */ - static void disableErasureCodingPolicy(final FSNamesystem fsn, + static boolean disableErasureCodingPolicy(final FSNamesystem fsn, String ecPolicyName, final boolean logRetryCache) throws IOException { 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 removeErasureCodingPolicyXAttr( diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index e21e97eb414..f71118425bf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/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 logRetryCache whether to record RPC ids in editlog for retry cache * rebuilding + * @return * @throws IOException */ - void enableErasureCodingPolicy(String ecPolicyName, + boolean enableErasureCodingPolicy(String ecPolicyName, final boolean logRetryCache) throws IOException { final String operationName = "enableErasureCodingPolicy"; checkOperation(OperationCategory.WRITE); boolean success = false; - LOG.info("Enable the erasure coding policy " + ecPolicyName); writeLock(); try { checkOperation(OperationCategory.WRITE); checkNameNodeSafeMode("Cannot enable erasure coding policy " + ecPolicyName); - FSDirErasureCodingOp.enableErasureCodingPolicy(this, ecPolicyName, - logRetryCache); - success = true; + success = FSDirErasureCodingOp.enableErasureCodingPolicy(this, + ecPolicyName, logRetryCache); + } catch (AccessControlException ace) { + logAuditEvent(false, operationName, ecPolicyName, null, null); } finally { writeUnlock(operationName); if (success) { 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 * @throws IOException */ - void disableErasureCodingPolicy(String ecPolicyName, + boolean disableErasureCodingPolicy(String ecPolicyName, final boolean logRetryCache) throws IOException { final String operationName = "disableErasureCodingPolicy"; checkOperation(OperationCategory.WRITE); @@ -7450,16 +7452,18 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, checkOperation(OperationCategory.WRITE); checkNameNodeSafeMode("Cannot disable erasure coding policy " + ecPolicyName); - FSDirErasureCodingOp.disableErasureCodingPolicy(this, ecPolicyName, - logRetryCache); - success = true; + success = FSDirErasureCodingOp.disableErasureCodingPolicy(this, + ecPolicyName, logRetryCache); + } catch (AccessControlException ace) { + logAuditEvent(false, operationName, ecPolicyName, null, null); } finally { writeUnlock(operationName); if (success) { getEditLog().logSync(); + logAuditEvent(success, operationName, ecPolicyName, null, null); } - logAuditEvent(success, operationName, ecPolicyName, null, null); } + return success; } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index 17f57b2c7e4..82ca7734c25 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/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; try { - namesystem.enableErasureCodingPolicy(ecPolicyName, cacheEntry != null); - success = true; + success = namesystem.enableErasureCodingPolicy(ecPolicyName, + cacheEntry != null); } finally { RetryCache.setState(cacheEntry, success); } @@ -2434,8 +2434,8 @@ public class NameNodeRpcServer implements NamenodeProtocols { } boolean success = false; try { - namesystem.disableErasureCodingPolicy(ecPolicyName, cacheEntry != null); - success = true; + success = namesystem.disableErasureCodingPolicy(ecPolicyName, + cacheEntry != null); } finally { RetryCache.setState(cacheEntry, success); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java index 0995f135d97..a1946c23f84 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java +++ b/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()); cacheSet = (LightWeightCache) namesystem .getRetryCache().getCacheSet(); - assertEquals("Retry cache size is wrong", 39, cacheSet.size()); + assertEquals("Retry cache size is wrong", 38, cacheSet.size()); iter = cacheSet.iterator(); while (iter.hasNext()) { CacheEntry entry = iter.next(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java index 43aaa927037..bcdf511e740 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java +++ b/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); cacheSet = (LightWeightCache) fsn1 .getRetryCache().getCacheSet(); - assertEquals("Retry cache size is wrong", 39, cacheSet.size()); + assertEquals("Retry cache size is wrong", 38, cacheSet.size()); iter = cacheSet.iterator(); while (iter.hasNext()) { CacheEntry entry = iter.next();