|
@@ -563,13 +563,17 @@ public class DistributedFileSystem extends FileSystem
|
|
* replication policy from its ancestor (the default).
|
|
* replication policy from its ancestor (the default).
|
|
* ecPolicyName and SHOULD_REPLICATE CreateFlag are mutually exclusive. It's
|
|
* ecPolicyName and SHOULD_REPLICATE CreateFlag are mutually exclusive. It's
|
|
* invalid to set both SHOULD_REPLICATE and a non-null ecPolicyName.
|
|
* invalid to set both SHOULD_REPLICATE and a non-null ecPolicyName.
|
|
|
|
+ * The third addition is storagePolicyName. A non-null storage Policy
|
|
|
|
+ * specifies an explicit storage policy for this file, overriding the
|
|
|
|
+ * inherited policy.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
private HdfsDataOutputStream create(final Path f,
|
|
private HdfsDataOutputStream create(final Path f,
|
|
final FsPermission permission, final EnumSet<CreateFlag> flag,
|
|
final FsPermission permission, final EnumSet<CreateFlag> flag,
|
|
final int bufferSize, final short replication, final long blockSize,
|
|
final int bufferSize, final short replication, final long blockSize,
|
|
final Progressable progress, final ChecksumOpt checksumOpt,
|
|
final Progressable progress, final ChecksumOpt checksumOpt,
|
|
- final InetSocketAddress[] favoredNodes, final String ecPolicyName)
|
|
|
|
|
|
+ final InetSocketAddress[] favoredNodes, final String ecPolicyName,
|
|
|
|
+ final String storagePolicy)
|
|
throws IOException {
|
|
throws IOException {
|
|
statistics.incrementWriteOps(1);
|
|
statistics.incrementWriteOps(1);
|
|
storageStatistics.incrementOpCounter(OpType.CREATE);
|
|
storageStatistics.incrementOpCounter(OpType.CREATE);
|
|
@@ -579,7 +583,7 @@ public class DistributedFileSystem extends FileSystem
|
|
public HdfsDataOutputStream doCall(final Path p) throws IOException {
|
|
public HdfsDataOutputStream doCall(final Path p) throws IOException {
|
|
final DFSOutputStream out = dfs.create(getPathName(f), permission,
|
|
final DFSOutputStream out = dfs.create(getPathName(f), permission,
|
|
flag, true, replication, blockSize, progress, bufferSize,
|
|
flag, true, replication, blockSize, progress, bufferSize,
|
|
- checksumOpt, favoredNodes, ecPolicyName);
|
|
|
|
|
|
+ checksumOpt, favoredNodes, ecPolicyName, storagePolicy);
|
|
return dfs.createWrappedOutputStream(out, statistics);
|
|
return dfs.createWrappedOutputStream(out, statistics);
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
@@ -588,7 +592,8 @@ public class DistributedFileSystem extends FileSystem
|
|
if (fs instanceof DistributedFileSystem) {
|
|
if (fs instanceof DistributedFileSystem) {
|
|
DistributedFileSystem myDfs = (DistributedFileSystem)fs;
|
|
DistributedFileSystem myDfs = (DistributedFileSystem)fs;
|
|
return myDfs.create(p, permission, flag, bufferSize, replication,
|
|
return myDfs.create(p, permission, flag, bufferSize, replication,
|
|
- blockSize, progress, checksumOpt, favoredNodes, ecPolicyName);
|
|
|
|
|
|
+ blockSize, progress, checksumOpt, favoredNodes, ecPolicyName,
|
|
|
|
+ storagePolicy);
|
|
}
|
|
}
|
|
throw new UnsupportedOperationException("Cannot create with" +
|
|
throw new UnsupportedOperationException("Cannot create with" +
|
|
" favoredNodes through a symlink to a non-DistributedFileSystem: "
|
|
" favoredNodes through a symlink to a non-DistributedFileSystem: "
|
|
@@ -619,14 +624,15 @@ public class DistributedFileSystem extends FileSystem
|
|
*
|
|
*
|
|
* @see #create(Path, FsPermission, EnumSet, int, short, long, Progressable,
|
|
* @see #create(Path, FsPermission, EnumSet, int, short, long, Progressable,
|
|
* ChecksumOpt, InetSocketAddress[], String) for the descriptions of
|
|
* ChecksumOpt, InetSocketAddress[], String) for the descriptions of
|
|
- * additional parameters, i.e., favoredNodes and ecPolicyName.
|
|
|
|
|
|
+ * additional parameters, i.e., favoredNodes, ecPolicyName and
|
|
|
|
+ * storagePolicyName.
|
|
*/
|
|
*/
|
|
private HdfsDataOutputStream createNonRecursive(final Path f,
|
|
private HdfsDataOutputStream createNonRecursive(final Path f,
|
|
final FsPermission permission, final EnumSet<CreateFlag> flag,
|
|
final FsPermission permission, final EnumSet<CreateFlag> flag,
|
|
final int bufferSize, final short replication, final long blockSize,
|
|
final int bufferSize, final short replication, final long blockSize,
|
|
final Progressable progress, final ChecksumOpt checksumOpt,
|
|
final Progressable progress, final ChecksumOpt checksumOpt,
|
|
- final InetSocketAddress[] favoredNodes, final String ecPolicyName)
|
|
|
|
- throws IOException {
|
|
|
|
|
|
+ final InetSocketAddress[] favoredNodes, final String ecPolicyName,
|
|
|
|
+ final String storagePolicyName) throws IOException {
|
|
statistics.incrementWriteOps(1);
|
|
statistics.incrementWriteOps(1);
|
|
storageStatistics.incrementOpCounter(OpType.CREATE);
|
|
storageStatistics.incrementOpCounter(OpType.CREATE);
|
|
Path absF = fixRelativePart(f);
|
|
Path absF = fixRelativePart(f);
|
|
@@ -635,7 +641,7 @@ public class DistributedFileSystem extends FileSystem
|
|
public HdfsDataOutputStream doCall(final Path p) throws IOException {
|
|
public HdfsDataOutputStream doCall(final Path p) throws IOException {
|
|
final DFSOutputStream out = dfs.create(getPathName(f), permission,
|
|
final DFSOutputStream out = dfs.create(getPathName(f), permission,
|
|
flag, false, replication, blockSize, progress, bufferSize,
|
|
flag, false, replication, blockSize, progress, bufferSize,
|
|
- checksumOpt, favoredNodes, ecPolicyName);
|
|
|
|
|
|
+ checksumOpt, favoredNodes, ecPolicyName, storagePolicyName);
|
|
return dfs.createWrappedOutputStream(out, statistics);
|
|
return dfs.createWrappedOutputStream(out, statistics);
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
@@ -645,7 +651,7 @@ public class DistributedFileSystem extends FileSystem
|
|
DistributedFileSystem myDfs = (DistributedFileSystem)fs;
|
|
DistributedFileSystem myDfs = (DistributedFileSystem)fs;
|
|
return myDfs.createNonRecursive(p, permission, flag, bufferSize,
|
|
return myDfs.createNonRecursive(p, permission, flag, bufferSize,
|
|
replication, blockSize, progress, checksumOpt, favoredNodes,
|
|
replication, blockSize, progress, checksumOpt, favoredNodes,
|
|
- ecPolicyName);
|
|
|
|
|
|
+ ecPolicyName, storagePolicyName);
|
|
}
|
|
}
|
|
throw new UnsupportedOperationException("Cannot create with" +
|
|
throw new UnsupportedOperationException("Cannot create with" +
|
|
" favoredNodes through a symlink to a non-DistributedFileSystem: "
|
|
" favoredNodes through a symlink to a non-DistributedFileSystem: "
|
|
@@ -3183,6 +3189,7 @@ public class DistributedFileSystem extends FileSystem
|
|
private final DistributedFileSystem dfs;
|
|
private final DistributedFileSystem dfs;
|
|
private InetSocketAddress[] favoredNodes = null;
|
|
private InetSocketAddress[] favoredNodes = null;
|
|
private String ecPolicyName = null;
|
|
private String ecPolicyName = null;
|
|
|
|
+ private String storagePolicyName = null;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Construct a HdfsDataOutputStream builder for a file.
|
|
* Construct a HdfsDataOutputStream builder for a file.
|
|
@@ -3254,6 +3261,22 @@ public class DistributedFileSystem extends FileSystem
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ String getStoragePolicyName() {
|
|
|
|
+ return storagePolicyName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Enforce a file to follow the specified storage policy irrespective of the
|
|
|
|
+ * storage policy of its parent directory.
|
|
|
|
+ */
|
|
|
|
+ public HdfsDataOutputStreamBuilder storagePolicyName(
|
|
|
|
+ @Nonnull final String policyName) {
|
|
|
|
+ Preconditions.checkNotNull(policyName);
|
|
|
|
+ storagePolicyName = policyName;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
String getEcPolicyName() {
|
|
String getEcPolicyName() {
|
|
return ecPolicyName;
|
|
return ecPolicyName;
|
|
@@ -3320,11 +3343,12 @@ public class DistributedFileSystem extends FileSystem
|
|
return dfs.create(getPath(), getPermission(), getFlags(),
|
|
return dfs.create(getPath(), getPermission(), getFlags(),
|
|
getBufferSize(), getReplication(), getBlockSize(),
|
|
getBufferSize(), getReplication(), getBlockSize(),
|
|
getProgress(), getChecksumOpt(), getFavoredNodes(),
|
|
getProgress(), getChecksumOpt(), getFavoredNodes(),
|
|
- getEcPolicyName());
|
|
|
|
|
|
+ getEcPolicyName(), getStoragePolicyName());
|
|
} else {
|
|
} else {
|
|
return dfs.createNonRecursive(getPath(), getPermission(), getFlags(),
|
|
return dfs.createNonRecursive(getPath(), getPermission(), getFlags(),
|
|
getBufferSize(), getReplication(), getBlockSize(), getProgress(),
|
|
getBufferSize(), getReplication(), getBlockSize(), getProgress(),
|
|
- getChecksumOpt(), getFavoredNodes(), getEcPolicyName());
|
|
|
|
|
|
+ getChecksumOpt(), getFavoredNodes(), getEcPolicyName(),
|
|
|
|
+ getStoragePolicyName());
|
|
}
|
|
}
|
|
} else if (getFlags().contains(CreateFlag.APPEND)) {
|
|
} else if (getFlags().contains(CreateFlag.APPEND)) {
|
|
return dfs.append(getPath(), getFlags(), getBufferSize(), getProgress(),
|
|
return dfs.append(getPath(), getFlags(), getBufferSize(), getProgress(),
|