Skip to content

Commit

Permalink
HDFS-13281 Namenode#createFile should be /.reserved/raw/ aware.. Cont…
Browse files Browse the repository at this point in the history
…ributed by Rushabh S Shah

(cherry picked from commit e2289c8)
(cherry picked from commit 4ecb7aa)
  • Loading branch information
shahrs87 committed Jun 4, 2018
1 parent 065e9c7 commit ca713e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,7 @@ private HdfsFileStatus startFileInt(String src,
dir, pc, src, flag, createParent);

FileEncryptionInfo feInfo = null;
if (provider != null) {
if (!iip.isRaw() && provider != null) {
EncryptionKeyInfo ezInfo = FSDirEncryptionZoneOp.getEncryptionKeyInfo(
this, iip, supportedVersions);
// if the path has an encryption zone, the lock was released while
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.io.StringReader;
Expand Down Expand Up @@ -77,6 +78,7 @@
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.namenode.EncryptionFaultInjector;
import org.apache.hadoop.hdfs.server.namenode.EncryptionZoneManager;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
Expand Down Expand Up @@ -2200,4 +2202,31 @@ public void testPread() throws Exception {
Assert.assertEquals((data[i] & 0XFF), in.read());
}
}

/**
* Tests that namenode doesn't generate edek if we are writing to
* /.reserved/raw directory.
* @throws Exception
*/
@Test
public void testWriteToEZReservedRaw() throws Exception {
String unEncryptedBytes = "hello world";
// Create an Encryption Zone.
final Path zonePath = new Path("/zone");
fsWrapper.mkdir(zonePath, FsPermission.getDirDefault(), false);
dfsAdmin.createEncryptionZone(zonePath, TEST_KEY, NO_TRASH);
Path p1 = new Path(zonePath, "p1");
Path reservedRawPath = new Path("/.reserved/raw/" + p1.toString());
// Create an empty file with /.reserved/raw/ path.
OutputStream os = fs.create(reservedRawPath);
os.close();
try {
fs.getXAttr(reservedRawPath, HdfsServerConstants
.CRYPTO_XATTR_FILE_ENCRYPTION_INFO);
fail("getXAttr should have thrown an exception");
} catch (IOException ioe) {
assertExceptionContains("At least one of the attributes provided was " +
"not found.", ioe);
}
}
}

0 comments on commit ca713e8

Please sign in to comment.