This is an automated email from the ASF dual-hosted git repository.
roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new dbb9890a [#1100] improvement(mr): Fail fast in SortWriteBufferManager
when failed to send shuffle data to shuffle server. (#1103)
dbb9890a is described below
commit dbb9890a20da8d013abc0b333d8e0ccbeac10c75
Author: Fantasy-Jay <[email protected]>
AuthorDate: Mon Aug 7 00:15:53 2023 +0800
[#1100] improvement(mr): Fail fast in SortWriteBufferManager when failed to
send shuffle data to shuffle server. (#1103)
### What changes were proposed in this pull request?
Currently, it only checks for blocks that failed to send after all buffer
data has been sent. This check also needs to be moved forward into the
addRecord method, allowing it to fail fast.
### Why are the changes needed?
Fix: https://github.com/apache/incubator-uniffle/issues/1100
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Add more test cases.
---
.../hadoop/mapred/SortWriteBufferManager.java | 26 +++++----
.../hadoop/mapred/SortWriteBufferManagerTest.java | 61 +++++++++++++---------
client-mr/core/src/test/resources/log4j.properties | 22 ++++++++
.../common/sort/buffer/WriteBufferManagerTest.java | 3 +-
4 files changed, 76 insertions(+), 36 deletions(-)
diff --git
a/client-mr/core/src/main/java/org/apache/hadoop/mapred/SortWriteBufferManager.java
b/client-mr/core/src/main/java/org/apache/hadoop/mapred/SortWriteBufferManager.java
index 429cb6b3..46e94f23 100644
---
a/client-mr/core/src/main/java/org/apache/hadoop/mapred/SortWriteBufferManager.java
+++
b/client-mr/core/src/main/java/org/apache/hadoop/mapred/SortWriteBufferManager.java
@@ -163,6 +163,9 @@ public class SortWriteBufferManager<K, V> {
memoryLock.unlock();
}
+ // Fail fast if there are some failed blocks.
+ checkFailedBlocks();
+
buffers.computeIfAbsent(
partitionId,
k -> {
@@ -270,16 +273,7 @@ public class SortWriteBufferManager<K, V> {
}
long start = System.currentTimeMillis();
while (true) {
- // if failed when send data to shuffle server, mark task as failed
- if (failedBlockIds.size() > 0) {
- String errorMsg =
- "Send failed: failed because "
- + failedBlockIds.size()
- + " blocks can't be sent to shuffle server.";
- LOG.error(errorMsg);
- throw new RssException(errorMsg);
- }
-
+ checkFailedBlocks();
// remove blockIds which was sent successfully, if there has none left,
all data are sent
allBlockIds.removeAll(successBlockIds);
if (allBlockIds.isEmpty()) {
@@ -323,6 +317,18 @@ public class SortWriteBufferManager<K, V> {
sortTime);
}
+ // if failed when send data to shuffle server, mark task as failed and throw
exception.
+ private void checkFailedBlocks() {
+ if (failedBlockIds.size() > 0) {
+ String errorMsg =
+ "Send failed: failed because "
+ + failedBlockIds.size()
+ + " blocks can't be sent to shuffle server.";
+ LOG.error(errorMsg);
+ throw new RssException(errorMsg);
+ }
+ }
+
// transform records to shuffleBlock
ShuffleBlockInfo createShuffleBlock(SortWriteBuffer wb) {
byte[] data = wb.getData();
diff --git
a/client-mr/core/src/test/java/org/apache/hadoop/mapred/SortWriteBufferManagerTest.java
b/client-mr/core/src/test/java/org/apache/hadoop/mapred/SortWriteBufferManagerTest.java
index cd737877..ae89231b 100644
---
a/client-mr/core/src/test/java/org/apache/hadoop/mapred/SortWriteBufferManagerTest.java
+++
b/client-mr/core/src/test/java/org/apache/hadoop/mapred/SortWriteBufferManagerTest.java
@@ -47,6 +47,7 @@ import org.apache.uniffle.common.util.JavaUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SortWriteBufferManagerTest {
@@ -61,6 +62,7 @@ public class SortWriteBufferManagerTest {
Set<Long> failedBlocks = Sets.newConcurrentHashSet();
Counters.Counter mapOutputByteCounter = new Counters.Counter();
Counters.Counter mapOutputRecordCounter = new Counters.Counter();
+ RssException rssException;
SortWriteBufferManager<BytesWritable, BytesWritable> manager;
manager =
new SortWriteBufferManager<BytesWritable, BytesWritable>(
@@ -88,6 +90,8 @@ public class SortWriteBufferManagerTest {
0.2f,
1024000L,
new RssConf());
+
+ // case 1
Random random = new Random();
for (int i = 0; i < 1000; i++) {
byte[] key = new byte[20];
@@ -96,23 +100,32 @@ public class SortWriteBufferManagerTest {
random.nextBytes(value);
manager.addRecord(1, new BytesWritable(key), new BytesWritable(value));
}
- boolean isException = false;
- try {
- manager.waitSendFinished();
- } catch (RssException re) {
- isException = true;
- }
- assertTrue(isException);
+ rssException = assertThrows(RssException.class, manager::waitSendFinished);
+ assertTrue(rssException.getMessage().contains("Timeout"));
+
+ // case 2
client.setMode(1);
- for (int i = 0; i < 1000; i++) {
- byte[] key = new byte[20];
- byte[] value = new byte[1024];
- random.nextBytes(key);
- random.nextBytes(value);
- manager.addRecord(1, new BytesWritable(key), new BytesWritable(value));
- }
+ SortWriteBufferManager<BytesWritable, BytesWritable> finalManager =
manager;
+ rssException =
+ assertThrows(
+ RssException.class,
+ () -> {
+ for (int i = 0; i < 1000; i++) {
+ byte[] key = new byte[20];
+ byte[] value = new byte[1024];
+ random.nextBytes(key);
+ random.nextBytes(value);
+ finalManager.addRecord(1, new BytesWritable(key), new
BytesWritable(value));
+ }
+ });
assertFalse(failedBlocks.isEmpty());
- isException = false;
+ assertTrue(rssException.getMessage().contains("Send failed"));
+
+ rssException = assertThrows(RssException.class,
finalManager::waitSendFinished);
+ assertTrue(rssException.getMessage().contains("Send failed"));
+
+ // case 3
+ client.setMode(0);
manager =
new SortWriteBufferManager<BytesWritable, BytesWritable>(
100,
@@ -127,8 +140,8 @@ public class SortWriteBufferManagerTest {
500,
5 * 1000,
partitionToServers,
- successBlocks,
- failedBlocks,
+ Sets.newConcurrentHashSet(),
+ Sets.newConcurrentHashSet(),
mapOutputByteCounter,
mapOutputRecordCounter,
1,
@@ -143,13 +156,13 @@ public class SortWriteBufferManagerTest {
byte[] value = new byte[1024];
random.nextBytes(key);
random.nextBytes(value);
- try {
- manager.addRecord(1, new BytesWritable(key), new BytesWritable(value));
- } catch (RssException re) {
- assertTrue(re.getMessage().contains("too big"));
- isException = true;
- }
- assertTrue(isException);
+
+ SortWriteBufferManager<BytesWritable, BytesWritable> finalManager1 =
manager;
+ rssException =
+ assertThrows(
+ RssException.class,
+ () -> finalManager1.addRecord(1, new BytesWritable(key), new
BytesWritable(value)));
+ assertTrue(rssException.getMessage().contains("too big"));
}
@Test
diff --git a/client-mr/core/src/test/resources/log4j.properties
b/client-mr/core/src/test/resources/log4j.properties
new file mode 100644
index 00000000..946ffcc2
--- /dev/null
+++ b/client-mr/core/src/test/resources/log4j.properties
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+log4j.rootLogger=info,stdout
+log4j.threshhold=ALL
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{2}
(%F:%M(%L)) - %m%n
diff --git
a/client-tez/src/test/java/org/apache/tez/runtime/library/common/sort/buffer/WriteBufferManagerTest.java
b/client-tez/src/test/java/org/apache/tez/runtime/library/common/sort/buffer/WriteBufferManagerTest.java
index 1449649c..73c625a9 100644
---
a/client-tez/src/test/java/org/apache/tez/runtime/library/common/sort/buffer/WriteBufferManagerTest.java
+++
b/client-tez/src/test/java/org/apache/tez/runtime/library/common/sort/buffer/WriteBufferManagerTest.java
@@ -378,8 +378,7 @@ public class WriteBufferManagerTest {
}
@Test
- public void testFastFailWhenSendBlocksFailed(@TempDir File tmpDir)
- throws IOException, InterruptedException {
+ public void testFailFastWhenFailedToSendBlocks(@TempDir File tmpDir) throws
IOException {
TezTaskAttemptID tezTaskAttemptID =
TezTaskAttemptID.fromString("attempt_1681717153064_3770270_1_00_000000_0");
final long maxMemSize = 10240;