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 34577d2c21
commit 770d9d9bb6
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.
*/
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;
}
/**

View File

@ -253,11 +253,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;
}
/**
@ -269,11 +274,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<XAttr> removeErasureCodingPolicyXAttr(

View File

@ -7604,29 +7604,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;
}
/**
@ -7636,7 +7638,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);
@ -7647,16 +7649,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;
}
/**

View File

@ -2477,8 +2477,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);
}
@ -2495,8 +2495,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);
}

View File

@ -463,7 +463,7 @@ public class TestNamenodeRetryCache {
assertTrue(namesystem.hasRetryCache());
cacheSet = (LightWeightCache<CacheEntry, CacheEntry>) 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();

View File

@ -194,7 +194,7 @@ public class TestRetryCacheWithHA {
FSNamesystem fsn1 = cluster.getNamesystem(1);
cacheSet = (LightWeightCache<CacheEntry, CacheEntry>) 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();