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

This commit is contained in:
Vinayakumar B 2018-08-21 09:33:19 +05:30
parent 95fcdc0435
commit 8df2eb8119
6 changed files with 47 additions and 28 deletions

View File

@ -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); return false;
LOG.info("Disable the erasure coding policy " + name);
} }
/** /**
* 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;
} }
/** /**

View File

@ -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); boolean success =
fsn.getEditLog().logEnableErasureCodingPolicy(ecPolicyName, logRetryCache); 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); boolean success =
fsn.getEditLog().logDisableErasureCodingPolicy(ecPolicyName, logRetryCache); fsn.getErasureCodingPolicyManager().disablePolicy(ecPolicyName);
if (success) {
fsn.getEditLog().logDisableErasureCodingPolicy(ecPolicyName,
logRetryCache);
}
return success;
} }
private static List<XAttr> removeErasureCodingPolicyXAttr( private static List<XAttr> removeErasureCodingPolicyXAttr(

View File

@ -7541,29 +7541,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, success = FSDirErasureCodingOp.enableErasureCodingPolicy(this,
logRetryCache); ecPolicyName, logRetryCache);
success = true; } 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;
} }
/** /**
@ -7573,7 +7575,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);
@ -7584,16 +7586,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, success = FSDirErasureCodingOp.disableErasureCodingPolicy(this,
logRetryCache); ecPolicyName, logRetryCache);
success = true; } 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;
} }
/** /**

View File

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

View File

@ -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();

View File

@ -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();