Skip to content

Commit 5b4ad46

Browse files
bshashikantzmolnar-inf
authored andcommitted
CDPD-34430 HOTREQ-446. HDFS-16187. SnapshotDiff behaviour with Xattrs and Acls is not consistent across NN restarts with checkpointing (apache#3340)
(cherry picked from commit 9b7be58afe41a75a85511b3d95c00519ca5071be) Change-Id: Ie1d00f7b029e3182c7a2c2d288599e3fd4088b9c
1 parent a52f6bb commit 5b4ad46

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/XAttrFeature.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.hdfs.server.namenode;
1919

2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.List;
2223

2324
import org.apache.hadoop.classification.InterfaceAudience;
@@ -84,6 +85,22 @@ public List<XAttr> getXAttrs() {
8485
}
8586
}
8687

88+
@Override
89+
public boolean equals(Object o) {
90+
if (o == null) {
91+
return false;
92+
}
93+
if (getClass() != o.getClass()) {
94+
return false;
95+
}
96+
return getXAttrs().equals(((XAttrFeature) o).getXAttrs());
97+
}
98+
99+
@Override
100+
public int hashCode() {
101+
return Arrays.hashCode(getXAttrs().toArray());
102+
}
103+
87104
/**
88105
* Get XAttr by name with prefix.
89106
* @param prefixedName xAttr name with prefix

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
import java.util.Arrays;
2525
import java.util.Comparator;
2626
import java.util.Date;
27+
import java.util.Objects;
2728

2829
import org.apache.hadoop.classification.InterfaceAudience;
2930
import org.apache.hadoop.fs.Path;
3031
import org.apache.hadoop.hdfs.DFSUtil;
3132
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
3233
import org.apache.hadoop.hdfs.server.namenode.AclFeature;
34+
import org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes;
3335
import org.apache.hadoop.hdfs.server.namenode.ContentSummaryComputationContext;
3436
import org.apache.hadoop.hdfs.server.namenode.DirectoryWithQuotaFeature;
3537
import org.apache.hadoop.hdfs.server.namenode.FSImageFormat;
@@ -200,6 +202,18 @@ public ContentSummaryComputationContext computeContentSummary(
200202
return computeDirectoryContentSummary(summary, snapshotId);
201203
}
202204

205+
@Override
206+
public boolean metadataEquals(INodeDirectoryAttributes other) {
207+
return other != null && getQuotaCounts().equals(other.getQuotaCounts())
208+
&& getPermissionLong() == other.getPermissionLong()
209+
// Acl feature maintains a reference counted map, thereby
210+
// every snapshot copy should point to the same Acl object unless
211+
// there is no change in acl values.
212+
// Reference equals is hence intentional here.
213+
&& getAclFeature() == other.getAclFeature()
214+
&& Objects.equals(getXAttrFeature(), other.getXAttrFeature());
215+
}
216+
203217
@Override
204218
public String getFullPathName() {
205219
return getSnapshotPath(getParent().getFullPathName(), getLocalName());

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
import java.util.concurrent.Executors;
4343
import java.util.concurrent.Future;
4444

45+
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
46+
import org.apache.hadoop.hdfs.protocol.EncryptionZone;
47+
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
48+
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
49+
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
4550
import com.google.common.collect.Lists;
4651

4752
import org.apache.hadoop.conf.Configuration;
@@ -71,10 +76,6 @@
7176
import org.apache.hadoop.fs.permission.FsPermission;
7277
import org.apache.hadoop.hdfs.client.CreateEncryptionZoneFlag;
7378
import org.apache.hadoop.hdfs.client.HdfsAdmin;
74-
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
75-
import org.apache.hadoop.hdfs.protocol.EncryptionZone;
76-
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
77-
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
7879
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
7980
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry;
8081
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffType;
@@ -1120,6 +1121,30 @@ private void dTIEM(Path prefix) throws Exception {
11201121
}
11211122
}
11221123

1124+
@Test
1125+
public void testEncryptionZonesWithSnapshots() throws Exception {
1126+
final Path snapshottable = new Path("/zones");
1127+
fsWrapper.mkdir(snapshottable, FsPermission.getDirDefault(),
1128+
true);
1129+
dfsAdmin.allowSnapshot(snapshottable);
1130+
dfsAdmin.createEncryptionZone(snapshottable, TEST_KEY, NO_TRASH);
1131+
fs.createSnapshot(snapshottable, "snap1");
1132+
SnapshotDiffReport report =
1133+
fs.getSnapshotDiffReport(snapshottable, "snap1", "");
1134+
Assert.assertEquals(0, report.getDiffList().size());
1135+
report =
1136+
fs.getSnapshotDiffReport(snapshottable, "snap1", "");
1137+
System.out.println(report);
1138+
Assert.assertEquals(0, report.getDiffList().size());
1139+
fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
1140+
fs.saveNamespace();
1141+
fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
1142+
cluster.restartNameNode(true);
1143+
report =
1144+
fs.getSnapshotDiffReport(snapshottable, "snap1", "");
1145+
Assert.assertEquals(0, report.getDiffList().size());
1146+
}
1147+
11231148
private class AuthorizationExceptionInjector extends EncryptionFaultInjector {
11241149
@Override
11251150
public void ensureKeyIsInitialized() throws IOException {
@@ -1666,7 +1691,6 @@ public void testEncryptionZonesOnRootPath() throws Exception {
16661691
true, fs.getFileStatus(rootDir).isEncrypted());
16671692
assertEquals("File is encrypted",
16681693
true, fs.getFileStatus(zoneFile).isEncrypted());
1669-
DFSTestUtil.verifyFilesNotEqual(fs, zoneFile, rawFile, len);
16701694
}
16711695

16721696
@Test

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestXAttrWithSnapshot.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
3737
import org.apache.hadoop.hdfs.protocol.NSQuotaExceededException;
3838
import org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException;
39+
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
3940
import org.apache.hadoop.hdfs.server.namenode.NameNode;
4041
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
4142
import org.apache.hadoop.io.IOUtils;
@@ -140,6 +141,31 @@ public void testModifyReadsCurrentState() throws Exception {
140141
assertEquals(xattrs.size(), 0);
141142
}
142143

144+
@Test
145+
public void testXattrWithSnapshotAndNNRestart() throws Exception {
146+
// Init
147+
FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0700));
148+
hdfs.setXAttr(path, name1, value1);
149+
hdfs.allowSnapshot(path);
150+
hdfs.createSnapshot(path, snapshotName);
151+
SnapshotDiffReport report =
152+
hdfs.getSnapshotDiffReport(path, snapshotName, "");
153+
System.out.println(report);
154+
Assert.assertEquals(0, report.getDiffList().size());
155+
report =
156+
hdfs.getSnapshotDiffReport(path, snapshotName, "");
157+
System.out.println(report);
158+
Assert.assertEquals(0, report.getDiffList().size());
159+
hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER);
160+
hdfs.saveNamespace();
161+
hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE);
162+
cluster.restartNameNode(true);
163+
report =
164+
hdfs.getSnapshotDiffReport(path, snapshotName, "");
165+
System.out.println(report);
166+
Assert.assertEquals(0, report.getDiffList().size());
167+
}
168+
143169
/**
144170
* Tests removing xattrs on a directory that has been snapshotted
145171
*/

0 commit comments

Comments
 (0)