Skip to content

Commit 2b70eb4

Browse files
lwllvybwenlongwlli
andauthored
feat(server) Support config buffer size for HadoopShuffleWriteHandler (#2216)
### What changes were proposed in this pull request? Support config buffer size for HadoopShuffleWriteHandler ### Why are the changes needed? Fix: #2209 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Locally test. Co-authored-by: wenlongwlli <wenlongwlli@tencent.com>
1 parent 87f9b6f commit 2b70eb4

6 files changed

Lines changed: 97 additions & 23 deletions

File tree

common/src/main/java/org/apache/uniffle/common/config/RssBaseConf.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,29 @@ public class RssBaseConf extends RssConf {
294294
+ " first combining the username and the password with a colon (uniffle:uniffle123)"
295295
+ ", and then by encoding the resulting string in base64 (dW5pZmZsZTp1bmlmZmxlMTIz).");
296296

297-
public static final ConfigOption<String> RSS_STORAGE_WRITE_DATA_BUFFER_SIZE =
298-
ConfigOptions.key("rss.storage.write.dataBufferSize")
297+
public static final ConfigOption<String> RSS_STORAGE_LOCALFILE_WRITE_DATA_BUFFER_SIZE =
298+
ConfigOptions.key("rss.storage.localfile.write.dataBufferSize")
299299
.stringType()
300300
.defaultValue("8k")
301-
.withDescription("The buffer size to cache the write data content.");
301+
.withDescription("The buffer size to cache the write data content for LOCALFILE.");
302302

303-
public static final ConfigOption<String> RSS_STORAGE_WRITE_INDEX_BUFFER_SIZE =
304-
ConfigOptions.key("rss.storage.write.indexBufferSize")
303+
public static final ConfigOption<String> RSS_STORAGE_LOCALFILE_WRITE_INDEX_BUFFER_SIZE =
304+
ConfigOptions.key("rss.storage.localfile.write.indexBufferSize")
305305
.stringType()
306306
.defaultValue("8k")
307-
.withDescription("The buffer size to cache the write index content.");
307+
.withDescription("The buffer size to cache the write index content for LOCALFILE.");
308+
309+
public static final ConfigOption<String> RSS_STORAGE_HDFS_WRITE_DATA_BUFFER_SIZE =
310+
ConfigOptions.key("rss.storage.hdfs.write.dataBufferSize")
311+
.stringType()
312+
.defaultValue("8k")
313+
.withDescription("The buffer size to cache the write data content for HDFS.");
314+
315+
public static final ConfigOption<String> RSS_STORAGE_HDFS_WRITE_INDEX_BUFFER_SIZE =
316+
ConfigOptions.key("rss.storage.hdfs.write.indexBufferSize")
317+
.stringType()
318+
.defaultValue("8k")
319+
.withDescription("The buffer size to cache the write index content for HDFS.");
308320

309321
public boolean loadConfFromFile(String fileName, List<ConfigOption<Object>> configOptions) {
310322
Map<String, String> properties = RssUtils.getPropertiesFromFile(fileName);

storage/src/main/java/org/apache/uniffle/storage/common/HadoopStorage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ ShuffleWriteHandler newWriteHandler(CreateShuffleWriteHandlerRequest request) {
8383
String user = request.getUser();
8484
if (request.getMaxFileNumber() == 1) {
8585
return new HadoopShuffleWriteHandler(
86+
request.getRssBaseConf(),
8687
request.getAppId(),
8788
request.getShuffleId(),
8889
request.getStartPartition(),
@@ -93,6 +94,7 @@ ShuffleWriteHandler newWriteHandler(CreateShuffleWriteHandlerRequest request) {
9394
user);
9495
} else {
9596
return new PooledHadoopShuffleWriteHandler(
97+
request.getRssBaseConf(),
9698
request.getAppId(),
9799
request.getShuffleId(),
98100
request.getStartPartition(),

storage/src/main/java/org/apache/uniffle/storage/handler/impl/HadoopFileWriter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.nio.ByteBuffer;
2424

25+
import com.google.common.annotations.VisibleForTesting;
2526
import org.apache.hadoop.conf.Configuration;
2627
import org.apache.hadoop.fs.FSDataOutputStream;
2728
import org.apache.hadoop.fs.FileSystem;
@@ -44,19 +45,26 @@ public class HadoopFileWriter implements FileWriter, Closeable {
4445
private FSDataOutputStream fsDataOutputStream;
4546
private long nextOffset;
4647

48+
@VisibleForTesting
4749
public HadoopFileWriter(FileSystem fileSystem, Path path, Configuration hadoopConf)
4850
throws IOException {
51+
this(fileSystem, path, hadoopConf, 8 * 1024);
52+
}
53+
54+
public HadoopFileWriter(
55+
FileSystem fileSystem, Path path, Configuration hadoopConf, int bufferSize)
56+
throws IOException {
4957
this.path = path;
5058
this.hadoopConf = hadoopConf;
5159
this.fileSystem = fileSystem;
52-
initStream();
60+
initStream(bufferSize);
5361
}
5462

55-
private void initStream() throws IOException, IllegalStateException {
63+
private void initStream(int bufferSize) throws IOException, IllegalStateException {
5664
final FileSystem writerFs = fileSystem;
5765
if (writerFs.isFile(path)) {
5866
if (hadoopConf.getBoolean("dfs.support.append", true)) {
59-
fsDataOutputStream = writerFs.append(path);
67+
fsDataOutputStream = writerFs.append(path, bufferSize);
6068
nextOffset = fsDataOutputStream.getPos();
6169
} else {
6270
String msg = path + " exists but append mode is not support!";
@@ -68,7 +76,7 @@ private void initStream() throws IOException, IllegalStateException {
6876
LOG.error(msg);
6977
throw new IllegalStateException(msg);
7078
} else {
71-
fsDataOutputStream = writerFs.create(path);
79+
fsDataOutputStream = writerFs.create(path, true, bufferSize);
7280
nextOffset = fsDataOutputStream.getPos();
7381
}
7482
}

storage/src/main/java/org/apache/uniffle/storage/handler/impl/HadoopShuffleWriteHandler.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.slf4j.LoggerFactory;
3131

3232
import org.apache.uniffle.common.ShufflePartitionedBlock;
33+
import org.apache.uniffle.common.config.RssBaseConf;
3334
import org.apache.uniffle.common.exception.RssException;
3435
import org.apache.uniffle.common.filesystem.HadoopFilesystemProvider;
3536
import org.apache.uniffle.common.util.ByteBufUtils;
@@ -41,13 +42,16 @@ public class HadoopShuffleWriteHandler implements ShuffleWriteHandler {
4142

4243
private static final Logger LOG = LoggerFactory.getLogger(HadoopShuffleWriteHandler.class);
4344

45+
private RssBaseConf rssBaseConf;
4446
private Configuration hadoopConf;
4547
private String basePath;
4648
private String fileNamePrefix;
4749
private Lock writeLock = new ReentrantLock();
4850
private int failTimes = 0;
4951
private String user;
5052
private FileSystem fileSystem;
53+
private final int dataBufferSize;
54+
private final int indexBufferSize;
5155

5256
// Only for test cases when using non-kerberized dfs cluster.
5357
@VisibleForTesting
@@ -60,16 +64,43 @@ public HadoopShuffleWriteHandler(
6064
String fileNamePrefix,
6165
Configuration hadoopConf)
6266
throws Exception {
63-
this.hadoopConf = hadoopConf;
64-
this.fileNamePrefix = fileNamePrefix;
65-
this.basePath =
66-
ShuffleStorageUtils.getFullShuffleDataFolder(
67-
storageBasePath,
68-
ShuffleStorageUtils.getShuffleDataPath(appId, shuffleId, startPartition, endPartition));
69-
initialize();
67+
this(
68+
new RssBaseConf(),
69+
appId,
70+
shuffleId,
71+
startPartition,
72+
endPartition,
73+
storageBasePath,
74+
fileNamePrefix,
75+
hadoopConf,
76+
"");
77+
}
78+
79+
@VisibleForTesting
80+
public HadoopShuffleWriteHandler(
81+
String appId,
82+
int shuffleId,
83+
int startPartition,
84+
int endPartition,
85+
String storageBasePath,
86+
String fileNamePrefix,
87+
Configuration hadoopConf,
88+
String user)
89+
throws Exception {
90+
this(
91+
new RssBaseConf(),
92+
appId,
93+
shuffleId,
94+
startPartition,
95+
endPartition,
96+
storageBasePath,
97+
fileNamePrefix,
98+
hadoopConf,
99+
user);
70100
}
71101

72102
public HadoopShuffleWriteHandler(
103+
RssBaseConf rssBaseConf,
73104
String appId,
74105
int shuffleId,
75106
int startPartition,
@@ -79,13 +110,24 @@ public HadoopShuffleWriteHandler(
79110
Configuration hadoopConf,
80111
String user)
81112
throws Exception {
113+
this.rssBaseConf = rssBaseConf;
82114
this.hadoopConf = hadoopConf;
83115
this.fileNamePrefix = fileNamePrefix;
84116
this.basePath =
85117
ShuffleStorageUtils.getFullShuffleDataFolder(
86118
storageBasePath,
87119
ShuffleStorageUtils.getShuffleDataPath(appId, shuffleId, startPartition, endPartition));
88120
this.user = user;
121+
this.dataBufferSize =
122+
(int)
123+
this.rssBaseConf.getSizeAsBytes(
124+
RssBaseConf.RSS_STORAGE_HDFS_WRITE_DATA_BUFFER_SIZE.key(),
125+
RssBaseConf.RSS_STORAGE_HDFS_WRITE_DATA_BUFFER_SIZE.defaultValue());
126+
this.indexBufferSize =
127+
(int)
128+
this.rssBaseConf.getSizeAsBytes(
129+
RssBaseConf.RSS_STORAGE_HDFS_WRITE_INDEX_BUFFER_SIZE.key(),
130+
RssBaseConf.RSS_STORAGE_HDFS_WRITE_INDEX_BUFFER_SIZE.defaultValue());
89131
initialize();
90132
}
91133

@@ -120,8 +162,8 @@ public void write(Collection<ShufflePartitionedBlock> shuffleBlocks) throws Exce
120162
ShuffleStorageUtils.generateDataFileName(fileNamePrefix + "_" + failTimes);
121163
String indexFileName =
122164
ShuffleStorageUtils.generateIndexFileName(fileNamePrefix + "_" + failTimes);
123-
try (HadoopFileWriter dataWriter = createWriter(dataFileName);
124-
HadoopFileWriter indexWriter = createWriter(indexFileName)) {
165+
try (HadoopFileWriter dataWriter = createWriter(dataFileName, dataBufferSize);
166+
HadoopFileWriter indexWriter = createWriter(indexFileName, indexBufferSize)) {
125167
for (ShufflePartitionedBlock block : shuffleBlocks) {
126168
long blockId = block.getBlockId();
127169
long crc = block.getCrc();
@@ -175,6 +217,13 @@ public HadoopFileWriter createWriter(String fileName) throws IOException, Illega
175217
return writer;
176218
}
177219

220+
public HadoopFileWriter createWriter(String fileName, int bufferSize)
221+
throws IOException, IllegalStateException {
222+
Path path = new Path(basePath, fileName);
223+
HadoopFileWriter writer = new HadoopFileWriter(fileSystem, path, hadoopConf, bufferSize);
224+
return writer;
225+
}
226+
178227
@VisibleForTesting
179228
public void setFailTimes(int failTimes) {
180229
this.failTimes = failTimes;

storage/src/main/java/org/apache/uniffle/storage/handler/impl/LocalFileWriteHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ public LocalFileWriteHandler(
6161
this.dataBufferSize =
6262
(int)
6363
this.rssBaseConf.getSizeAsBytes(
64-
RssBaseConf.RSS_STORAGE_WRITE_DATA_BUFFER_SIZE.key(),
65-
RssBaseConf.RSS_STORAGE_WRITE_DATA_BUFFER_SIZE.defaultValue());
64+
RssBaseConf.RSS_STORAGE_LOCALFILE_WRITE_DATA_BUFFER_SIZE.key(),
65+
RssBaseConf.RSS_STORAGE_LOCALFILE_WRITE_DATA_BUFFER_SIZE.defaultValue());
6666
this.indexBufferSize =
6767
(int)
6868
this.rssBaseConf.getSizeAsBytes(
69-
RssBaseConf.RSS_STORAGE_WRITE_INDEX_BUFFER_SIZE.key(),
70-
RssBaseConf.RSS_STORAGE_WRITE_INDEX_BUFFER_SIZE.defaultValue());
69+
RssBaseConf.RSS_STORAGE_LOCALFILE_WRITE_INDEX_BUFFER_SIZE.key(),
70+
RssBaseConf.RSS_STORAGE_LOCALFILE_WRITE_INDEX_BUFFER_SIZE.defaultValue());
7171
createBasePath();
7272
}
7373

storage/src/main/java/org/apache/uniffle/storage/handler/impl/PooledHadoopShuffleWriteHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.slf4j.LoggerFactory;
2929

3030
import org.apache.uniffle.common.ShufflePartitionedBlock;
31+
import org.apache.uniffle.common.config.RssBaseConf;
3132
import org.apache.uniffle.common.exception.RssException;
3233
import org.apache.uniffle.storage.handler.api.ShuffleWriteHandler;
3334
import org.apache.uniffle.storage.util.ShuffleStorageUtils;
@@ -70,6 +71,7 @@ public PooledHadoopShuffleWriteHandler(
7071
}
7172

7273
public PooledHadoopShuffleWriteHandler(
74+
RssBaseConf rssBaseConf,
7375
String appId,
7476
int shuffleId,
7577
int startPartition,
@@ -90,6 +92,7 @@ public PooledHadoopShuffleWriteHandler(
9092
index -> {
9193
try {
9294
return new HadoopShuffleWriteHandler(
95+
rssBaseConf,
9396
appId,
9497
shuffleId,
9598
startPartition,

0 commit comments

Comments
 (0)