From 27ffd43b6419c9ebe697536bcb6abb858ce791d2 Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Mon, 2 Oct 2017 15:31:20 -0700 Subject: [PATCH] HDFS-12569. Unset EC policy logs empty payload in edit log. (Lei (Eddy) Xu) --- .../hdfs/server/namenode/FSDirErasureCodingOp.java | 3 +-- .../hadoop/hdfs/server/namenode/FSDirXAttrOp.java | 4 ++++ .../hdfs/TestUnsetAndChangeDirectoryEcPolicy.java | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) 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 181b1478502..391e39255ec 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 @@ -298,8 +298,7 @@ final class FSDirErasureCodingOp { final List xattrs = Lists.newArrayListWithCapacity(1); xattrs.add(ecXAttr); - FSDirXAttrOp.unprotectedRemoveXAttrs(fsd, srcIIP, xattrs); - return xattrs; + return FSDirXAttrOp.unprotectedRemoveXAttrs(fsd, srcIIP, xattrs); } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirXAttrOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirXAttrOp.java index acdade7ca83..32234671fa4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirXAttrOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirXAttrOp.java @@ -184,6 +184,10 @@ class FSDirXAttrOp { return fsd.getAuditFileInfo(iip); } + /** + * Remove xattrs from the inode, and return the removed xattrs. + * @return the removed xattrs. + */ static List unprotectedRemoveXAttrs( FSDirectory fsd, final INodesInPath iip, final List toRemove) throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestUnsetAndChangeDirectoryEcPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestUnsetAndChangeDirectoryEcPolicy.java index 529a110c0ef..52cf163e26d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestUnsetAndChangeDirectoryEcPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestUnsetAndChangeDirectoryEcPolicy.java @@ -362,4 +362,17 @@ public class TestUnsetAndChangeDirectoryEcPolicy { + ecFilePath, e); } } + + /** + * Test unsetEcPolicy is persisted correctly in edit log. + */ + @Test + public void testUnsetEcPolicyInEditLog() throws IOException { + fs.getClient().setErasureCodingPolicy("/", ecPolicy.getName()); + Assert.assertEquals(ecPolicy, fs.getErasureCodingPolicy(new Path("/"))); + fs.getClient().unsetErasureCodingPolicy("/"); + + cluster.restartNameNode(true); + Assert.assertNull(fs.getErasureCodingPolicy(new Path("/"))); + } } \ No newline at end of file