Skip to content

Commit 002b5fb

Browse files
HDFS-16187. SnapshotDiff behaviour with Xattrs and Acls is not consistent across NN restarts with checkpointing (#3340) (#3640)
(cherry picked from commit 356ebbb) Conflicts: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java Change-Id: If76fd0d77fafc90fe2f2c19ab1d0c43a58510f6b Co-authored-by: bshashikant <shashikant@apache.org> (cherry picked from commit 5333e87)
1 parent c95df2e commit 002b5fb

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
import java.util.Arrays;
2525
import java.util.Comparator;
2626
import java.util.Date;
27+
import java.util.Objects;
28+
2729
import org.apache.hadoop.classification.InterfaceAudience;
2830
import org.apache.hadoop.fs.Path;
2931
import org.apache.hadoop.hdfs.DFSUtil;
3032
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
3133
import org.apache.hadoop.hdfs.server.namenode.AclFeature;
34+
import org.apache.hadoop.hdfs.server.namenode.INodeDirectoryAttributes;
3235
import org.apache.hadoop.hdfs.server.namenode.ContentSummaryComputationContext;
3336
import org.apache.hadoop.hdfs.server.namenode.DirectoryWithQuotaFeature;
3437
import org.apache.hadoop.hdfs.server.namenode.FSImageFormat;
@@ -185,6 +188,18 @@ public ContentSummaryComputationContext computeContentSummary(
185188
return computeDirectoryContentSummary(summary, snapshotId);
186189
}
187190

191+
@Override
192+
public boolean metadataEquals(INodeDirectoryAttributes other) {
193+
return other != null && getQuotaCounts().equals(other.getQuotaCounts())
194+
&& getPermissionLong() == other.getPermissionLong()
195+
// Acl feature maintains a reference counted map, thereby
196+
// every snapshot copy should point to the same Acl object unless
197+
// there is no change in acl values.
198+
// Reference equals is hence intentional here.
199+
&& getAclFeature() == other.getAclFeature()
200+
&& Objects.equals(getXAttrFeature(), other.getXAttrFeature());
201+
}
202+
188203
@Override
189204
public String getFullPathName() {
190205
return getSnapshotPath(getParent().getFullPathName(), getLocalName());

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs;
1919

20+
import com.google.common.collect.Lists;
21+
2022
import java.io.ByteArrayOutputStream;
2123
import java.io.File;
2224
import java.io.IOException;
@@ -43,8 +45,6 @@
4345
import java.util.concurrent.Executors;
4446
import java.util.concurrent.Future;
4547

46-
import com.google.common.collect.Lists;
47-
4848
import org.apache.hadoop.conf.Configuration;
4949
import org.apache.hadoop.crypto.CipherSuite;
5050
import org.apache.hadoop.crypto.CryptoInputStream;
@@ -75,9 +75,10 @@
7575
import org.apache.hadoop.hdfs.client.HdfsAdmin;
7676
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
7777
import org.apache.hadoop.hdfs.protocol.EncryptionZone;
78+
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
7879
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
7980
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
80-
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
81+
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
8182
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry;
8283
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffType;
8384
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
@@ -1185,6 +1186,30 @@ private void dTIEM(Path prefix) throws Exception {
11851186
}
11861187
}
11871188

1189+
@Test
1190+
public void testEncryptionZonesWithSnapshots() throws Exception {
1191+
final Path snapshottable = new Path("/zones");
1192+
fsWrapper.mkdir(snapshottable, FsPermission.getDirDefault(),
1193+
true);
1194+
dfsAdmin.allowSnapshot(snapshottable);
1195+
dfsAdmin.createEncryptionZone(snapshottable, TEST_KEY, NO_TRASH);
1196+
fs.createSnapshot(snapshottable, "snap1");
1197+
SnapshotDiffReport report =
1198+
fs.getSnapshotDiffReport(snapshottable, "snap1", "");
1199+
Assert.assertEquals(0, report.getDiffList().size());
1200+
report =
1201+
fs.getSnapshotDiffReport(snapshottable, "snap1", "");
1202+
System.out.println(report);
1203+
Assert.assertEquals(0, report.getDiffList().size());
1204+
fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
1205+
fs.saveNamespace();
1206+
fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
1207+
cluster.restartNameNode(true);
1208+
report =
1209+
fs.getSnapshotDiffReport(snapshottable, "snap1", "");
1210+
Assert.assertEquals(0, report.getDiffList().size());
1211+
}
1212+
11881213
private class AuthorizationExceptionInjector extends EncryptionFaultInjector {
11891214
@Override
11901215
public void ensureKeyIsInitialized() throws IOException {
@@ -1731,7 +1756,6 @@ public void testEncryptionZonesOnRootPath() throws Exception {
17311756
true, fs.getFileStatus(rootDir).isEncrypted());
17321757
assertEquals("File is encrypted",
17331758
true, fs.getFileStatus(zoneFile).isEncrypted());
1734-
DFSTestUtil.verifyFilesNotEqual(fs, zoneFile, rawFile, len);
17351759
}
17361760

17371761
@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)