From 0f9af246e89e4ad3c4d7ff2c1d7ec9b397494a03 Mon Sep 17 00:00:00 2001 From: Kai Zheng Date: Mon, 18 Sep 2017 18:07:12 +0800 Subject: [PATCH] HDFS-12460. Make addErasureCodingPolicy an idempotent operation. Contributed by Sammi Chen --- .../hdfs/server/namenode/ErasureCodingPolicyManager.java | 7 ++++--- .../org/apache/hadoop/hdfs/TestErasureCodingPolicies.java | 2 +- .../hdfs/server/namenode/TestNamenodeRetryCache.java | 4 ++-- .../hdfs/server/namenode/ha/TestRetryCacheWithHA.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) 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 3a46c3049ac..90699b43a49 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 @@ -242,14 +242,15 @@ public final class ErasureCodingPolicyManager { policy.getSchema(), policy.getCellSize()); for (ErasureCodingPolicy p : getPolicies()) { if (p.getName().equals(assignedNewName)) { - throw new HadoopIllegalArgumentException("The policy name " + - assignedNewName + " already exists"); + LOG.info("The policy name " + assignedNewName + " already exists"); + return p; } if (p.getSchema().equals(policy.getSchema()) && p.getCellSize() == policy.getCellSize()) { - throw new HadoopIllegalArgumentException("A policy with same schema " + LOG.info("A policy with same schema " + policy.getSchema().toString() + " and cell size " + p.getCellSize() + " already exists"); + return p; } } policy.setName(assignedNewName); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java index 19277c447b8..4f2040b60f3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java @@ -718,7 +718,7 @@ public class TestErasureCodingPolicies { policyArray = new ErasureCodingPolicy[]{policy0}; responses = fs.addErasureCodingPolicies(policyArray); assertEquals(1, responses.length); - assertFalse(responses[0].isSucceed()); + assertTrue(responses[0].isSucceed()); // Test add policy successfully newPolicy = 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 d217813bd5f..42ff6989e1a 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 @@ -436,7 +436,7 @@ public class TestNamenodeRetryCache { LightWeightCache cacheSet = (LightWeightCache) namesystem.getRetryCache().getCacheSet(); - assertEquals("Retry cache size is wrong", 26, cacheSet.size()); + assertEquals("Retry cache size is wrong", 34, cacheSet.size()); Map oldEntries = new HashMap(); @@ -455,7 +455,7 @@ public class TestNamenodeRetryCache { assertTrue(namesystem.hasRetryCache()); cacheSet = (LightWeightCache) namesystem .getRetryCache().getCacheSet(); - assertEquals("Retry cache size is wrong", 26, cacheSet.size()); + assertEquals("Retry cache size is wrong", 34, 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 b40006be732..1d114d62e4d 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 @@ -166,7 +166,7 @@ public class TestRetryCacheWithHA { FSNamesystem fsn0 = cluster.getNamesystem(0); LightWeightCache cacheSet = (LightWeightCache) fsn0.getRetryCache().getCacheSet(); - assertEquals("Retry cache size is wrong", 26, cacheSet.size()); + assertEquals("Retry cache size is wrong", 34, cacheSet.size()); Map oldEntries = new HashMap(); @@ -187,7 +187,7 @@ public class TestRetryCacheWithHA { FSNamesystem fsn1 = cluster.getNamesystem(1); cacheSet = (LightWeightCache) fsn1 .getRetryCache().getCacheSet(); - assertEquals("Retry cache size is wrong", 26, cacheSet.size()); + assertEquals("Retry cache size is wrong", 34, cacheSet.size()); iter = cacheSet.iterator(); while (iter.hasNext()) { CacheEntry entry = iter.next();