Skip to content

Commit de67a94

Browse files
committed
HDFS-17577.Add Support for CreateFlag.NO_LOCAL_WRITE in File Creation to Manage Disk Space and Network Load in Labeled YARN Nodes
1 parent 12a26d8 commit de67a94

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,17 @@ public FSDataOutputStream next(final FileSystem fs, final Path p)
503503
public FSDataOutputStream create(Path f, FsPermission permission,
504504
boolean overwrite, int bufferSize, short replication, long blockSize,
505505
Progressable progress) throws IOException {
506+
boolean noLocalWrite =dfs.getConf().getNoLocalWrite();
507+
EnumSet<CreateFlag> flag = EnumSet.of(CreateFlag.CREATE);
508+
if(overwrite){
509+
flag.add(CreateFlag.OVERWRITE);
510+
}
511+
if(noLocalWrite){
512+
flag.add(CreateFlag.NO_LOCAL_WRITE);
513+
}
506514
return this.create(f, permission,
507-
overwrite ? EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE)
508-
: EnumSet.of(CreateFlag.CREATE), bufferSize, replication,
509-
blockSize, progress, null);
515+
flag, bufferSize, replication,
516+
blockSize, progress, null);
510517
}
511518

512519
/**

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsClientConfigKeys.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public interface HdfsClientConfigKeys {
167167
"dfs.client.block.reader.remote.buffer.size";
168168
int DFS_CLIENT_BLOCK_READER_REMOTE_BUFFER_SIZE_DEFAULT = 512;
169169

170+
String DFS_CLIENT_NO_LOCAL_WRITE = "dfs.client.write.no_local_write";
171+
boolean DFS_CLIENT_NO_LOCAL_WRITE_DEFAULT = false;
170172
String DFS_CLIENT_DEAD_NODE_DETECTION_ENABLED_KEY =
171173
"dfs.client.deadnode.detection.enabled";
172174
boolean DFS_CLIENT_DEAD_NODE_DETECTION_ENABLED_DEFAULT = false;

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/DfsClientConf.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public class DfsClientConf {
152152

153153
private final ShortCircuitConf shortCircuitConf;
154154
private final int clientShortCircuitNum;
155+
private final boolean noLocalWrite;
155156

156157
private final long hedgedReadThresholdMillis;
157158
private final int hedgedReadThreadpoolSize;
@@ -311,6 +312,8 @@ public DfsClientConf(Configuration conf) {
311312
Preconditions.checkArgument(clientShortCircuitNum <= 5,
312313
HdfsClientConfigKeys.DFS_CLIENT_SHORT_CIRCUIT_NUM +
313314
"can't be more then 5.");
315+
noLocalWrite = conf.getBoolean(HdfsClientConfigKeys.DFS_CLIENT_NO_LOCAL_WRITE,
316+
HdfsClientConfigKeys.DFS_CLIENT_NO_LOCAL_WRITE_DEFAULT);
314317
maxPipelineRecoveryRetries = conf.getInt(
315318
HdfsClientConfigKeys.DFS_CLIENT_PIPELINE_RECOVERY_MAX_RETRIES,
316319
HdfsClientConfigKeys.DFS_CLIENT_PIPELINE_RECOVERY_MAX_RETRIES_DEFAULT
@@ -745,6 +748,12 @@ public int getMaxPipelineRecoveryRetries() {
745748
return maxPipelineRecoveryRetries;
746749
}
747750

751+
/**
752+
*@return the noLocalWrite
753+
*/
754+
public boolean getNoLocalWrite() {
755+
return noLocalWrite;
756+
}
748757
/**
749758
* Configuration for short-circuit reads.
750759
*/

0 commit comments

Comments
 (0)