This is an automated email from the ASF dual-hosted git repository.
rexxiong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git
The following commit(s) were added to refs/heads/main by this push:
new 62d60de8c [CELEBORN-537] Improve blacklist compute & minor fix for
Flink (#1441)
62d60de8c is described below
commit 62d60de8c51e380232bd8400ccd624b9ada04594
Author: Shuang <[email protected]>
AuthorDate: Thu Apr 20 18:30:10 2023 +0800
[CELEBORN-537] Improve blacklist compute & minor fix for Flink (#1441)
[CELEBORN-537] improve blacklist compute & minor fix for flink
---
.../plugin/flink/ShuffleResourceTracker.java | 4 +-
.../plugin/flink/ShuffleResourceTrackerTest.java | 39 +++++----
.../apache/celeborn/client/LifecycleManager.scala | 9 ++
.../celeborn/client/WorkerStatusTracker.scala | 52 +++++++-----
.../celeborn/client/WorkerStatusTrackerSuite.scala | 99 ++++++++++++++++++++++
.../common/meta/ShufflePartitionLocationInfo.scala | 12 +--
.../meta/ShufflePartitionLocationInfoSuite.scala | 7 +-
7 files changed, 176 insertions(+), 46 deletions(-)
diff --git
a/client-flink/flink-1.14/src/main/java/org/apache/celeborn/plugin/flink/ShuffleResourceTracker.java
b/client-flink/flink-1.14/src/main/java/org/apache/celeborn/plugin/flink/ShuffleResourceTracker.java
index a64afe019..0baae5e9c 100644
---
a/client-flink/flink-1.14/src/main/java/org/apache/celeborn/plugin/flink/ShuffleResourceTracker.java
+++
b/client-flink/flink-1.14/src/main/java/org/apache/celeborn/plugin/flink/ShuffleResourceTracker.java
@@ -101,12 +101,12 @@ public class ShuffleResourceTracker implements
WorkerStatusListener {
// shuffleResourceListener may release when the shuffle is
ended
if (shuffleAllocateInfo != null) {
ShufflePartitionLocationInfo shufflePartitionLocationInfo =
- shuffleAllocateInfo.remove(unknownWorker);
+ shuffleAllocateInfo.get(unknownWorker);
if (shufflePartitionLocationInfo != null) {
// TODO if we support partition replica for map partition
we need refactor this
// Currently we only untrack master partitions for map
partition
shufflePartitionLocationInfo
- .getMasterPartitionIds()
+ .removeAndGetAllMasterPartitionIds()
.forEach(
id -> {
ResultPartitionID resultPartitionId =
diff --git
a/client-flink/flink-1.14/src/test/java/org/apache/celeborn/plugin/flink/ShuffleResourceTrackerTest.java
b/client-flink/flink-1.14/src/test/java/org/apache/celeborn/plugin/flink/ShuffleResourceTrackerTest.java
index a8498e44e..1912cec15 100644
---
a/client-flink/flink-1.14/src/test/java/org/apache/celeborn/plugin/flink/ShuffleResourceTrackerTest.java
+++
b/client-flink/flink-1.14/src/test/java/org/apache/celeborn/plugin/flink/ShuffleResourceTrackerTest.java
@@ -19,7 +19,6 @@ package org.apache.celeborn.plugin.flink;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
@@ -48,22 +47,15 @@ public class ShuffleResourceTrackerTest {
ConcurrentHashMap<WorkerInfo, ShufflePartitionLocationInfo> map = new
ConcurrentHashMap<>();
WorkerInfo workerInfo = new WorkerInfo("mock", -1, -1, -1, -1);
- ShufflePartitionLocationInfo shufflePartitionLocationInfo = new
ShufflePartitionLocationInfo();
+ map.put(workerInfo, mockShufflePartitionLocationInfo());
- List<PartitionLocation> masterLocations = new ArrayList<>();
- masterLocations.add(mock(1));
- masterLocations.add(mock(2));
+ ConcurrentHashMap<WorkerInfo, ShufflePartitionLocationInfo> map2 = new
ConcurrentHashMap<>();
+ map2.put(workerInfo, mockShufflePartitionLocationInfo());
- List<PartitionLocation> slaveLocations = new ArrayList<>();
- slaveLocations.add(mock(3));
- slaveLocations.add(mock(4));
+ ConcurrentHashMap<WorkerInfo, ShufflePartitionLocationInfo> map3 = new
ConcurrentHashMap<>();
+ map3.put(workerInfo, mockShufflePartitionLocationInfo());
- shufflePartitionLocationInfo.addMasterPartitions(masterLocations);
- shufflePartitionLocationInfo.addSlavePartitions(slaveLocations);
-
- map.put(workerInfo, shufflePartitionLocationInfo);
- Mockito.when(lifecycleManager.workerSnapshots(Mockito.anyInt()))
- .thenReturn(map, new HashMap<>(map), new HashMap<>(map));
+
Mockito.when(lifecycleManager.workerSnapshots(Mockito.anyInt())).thenReturn(map,
map2, map3);
ShuffleResourceTracker shuffleResourceTracker =
new ShuffleResourceTracker(executor, lifecycleManager);
@@ -97,6 +89,7 @@ public class ShuffleResourceTrackerTest {
.getResultPartitionMap()
.get(2)
.keySet());
+
Assert.assertTrue(
shuffleResourceTracker
.getJobResourceListener(jobID2)
@@ -105,6 +98,22 @@ public class ShuffleResourceTrackerTest {
.isEmpty());
}
+ public ShufflePartitionLocationInfo mockShufflePartitionLocationInfo() {
+ ShufflePartitionLocationInfo shufflePartitionLocationInfo = new
ShufflePartitionLocationInfo();
+
+ List<PartitionLocation> masterLocations = new ArrayList<>();
+ masterLocations.add(mockShufflePartitionLocationInfo(1));
+ masterLocations.add(mockShufflePartitionLocationInfo(2));
+
+ List<PartitionLocation> slaveLocations = new ArrayList<>();
+ slaveLocations.add(mockShufflePartitionLocationInfo(3));
+ slaveLocations.add(mockShufflePartitionLocationInfo(4));
+
+ shufflePartitionLocationInfo.addMasterPartitions(masterLocations);
+ shufflePartitionLocationInfo.addSlavePartitions(slaveLocations);
+ return shufflePartitionLocationInfo;
+ }
+
public JobShuffleContext createJobShuffleContext(JobID jobId) {
return new JobShuffleContext() {
@Override
@@ -120,7 +129,7 @@ public class ShuffleResourceTrackerTest {
};
}
- private PartitionLocation mock(int partitionId) {
+ private PartitionLocation mockShufflePartitionLocationInfo(int partitionId) {
return new PartitionLocation(
partitionId, -1, "mock", -1, -1, -1, -1,
PartitionLocation.Mode.MASTER);
}
diff --git
a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
index 3b14eff29..6f18356e6 100644
--- a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
+++ b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
@@ -442,6 +442,9 @@ class LifecycleManager(appId: String, val conf:
CelebornConf) extends RpcEndpoin
candidatesWorkers.removeAll(connectFailedWorkers.asScala.keys.toList.asJava)
workerStatusTracker.recordWorkerFailure(connectFailedWorkers)
+ // If newly allocated from master and can setup endpoint success,
LifecycleManager should remove worker from
+ // the blacklist to improve the accuracy of the blacklist
+ workerStatusTracker.removeFromBlacklist(candidatesWorkers)
// Third, for each slot, LifecycleManager should ask Worker to reserve the
slot
// and prepare the pushing data env.
@@ -502,6 +505,12 @@ class LifecycleManager(appId: String, val conf:
CelebornConf) extends RpcEndpoin
return
}
+ if (getPartitionType(shuffleId) == PartitionType.MAP) {
+ logError(s"[handleRevive] shuffle $shuffleId revived filed, because map
partition don't support revive!")
+ context.reply(ChangeLocationResponse(StatusCode.REVIVE_FAILED, None))
+ return
+ }
+
if (commitManager.isMapperEnded(shuffleId, mapId)) {
logWarning(s"[handleRevive] Mapper ended, mapId $mapId, current
attemptId $attemptId, " +
s"ended attemptId
${commitManager.getMapperAttempts(shuffleId)(mapId)}, shuffleId $shuffleId.")
diff --git
a/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
b/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
index fef28cb3c..49595dc5e 100644
--- a/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
+++ b/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
@@ -123,17 +123,21 @@ class WorkerStatusTracker(
}
}
+ def removeFromBlacklist(workers: JHashSet[WorkerInfo]): Unit = {
+ blacklist.keySet.removeAll(workers)
+ }
+
def handleHeartbeatResponse(res: HeartbeatFromApplicationResponse): Unit = {
if (res.statusCode == StatusCode.SUCCESS) {
- logInfo(s"Received Blacklist from Master, blacklist: ${res.blacklist} " +
+ logDebug(s"Received Blacklist from Master, blacklist: ${res.blacklist} "
+
s"unknown workers: ${res.unknownWorkers}, shutdown workers:
${res.shuttingWorkers}")
val newShutdownWorkers = resolveShutdownWorkers(res.shuttingWorkers)
val current = System.currentTimeMillis()
- val reserved = blacklist.asScala
- .filter { case (_, entry) =>
- val (statusCode, registerTime) = entry
+
+ blacklist.asScala.foreach {
+ case (workerInfo: WorkerInfo, (statusCode, registerTime)) =>
statusCode match {
- case StatusCode.WORKER_SHUTDOWN |
+ case StatusCode.UNKNOWN_WORKER |
StatusCode.NO_AVAILABLE_WORKING_DIR |
StatusCode.RESERVE_SLOTS_FAILED |
StatusCode.PUSH_DATA_CREATE_CONNECTION_FAIL_MASTER |
@@ -142,32 +146,34 @@ class WorkerStatusTracker(
StatusCode.PUSH_DATA_CONNECTION_EXCEPTION_SLAVE |
StatusCode.PUSH_DATA_TIMEOUT_MASTER |
StatusCode.PUSH_DATA_TIMEOUT_SLAVE
- if current - registerTime < workerExcludedExpireTimeout =>
- true
- case StatusCode.UNKNOWN_WORKER => true
- case _ => false
+ if current - registerTime < workerExcludedExpireTimeout => //
reserve
+ case _ => blacklist.remove(workerInfo)
}
- }.asJava
- val reservedBlackList = new ShuffleFailedWorkers()
- reservedBlackList.putAll(reserved)
- blacklist.clear()
- blacklist.putAll(
- res.blacklist.asScala.map(_ -> (StatusCode.WORKER_IN_BLACKLIST ->
current)).toMap.asJava)
- blacklist.putAll(
- res.unknownWorkers.asScala.map(_ -> (StatusCode.UNKNOWN_WORKER ->
current)).toMap.asJava)
- // put reserved blacklist at last to cover blacklist's local status.
- blacklist.putAll(reservedBlackList)
-
- val workerStatus = new WorkersStatus(res.unknownWorkers,
newShutdownWorkers)
- workerStatusListeners.asScala.foreach {
- listener =>
+ }
+
+ if (!res.blacklist.isEmpty) {
+ blacklist.putAll(res.blacklist.asScala.filterNot(blacklist.containsKey)
+ .map(_ -> (StatusCode.WORKER_IN_BLACKLIST -> current)).toMap.asJava)
+ }
+
+ if (!res.unknownWorkers.isEmpty || !newShutdownWorkers.isEmpty) {
+
blacklist.putAll(res.unknownWorkers.asScala.filterNot(blacklist.containsKey)
+ .map(_ -> (StatusCode.UNKNOWN_WORKER -> current)).toMap.asJava)
+
blacklist.putAll(res.shuttingWorkers.asScala.filterNot(blacklist.containsKey)
+ .map(_ -> (StatusCode.WORKER_SHUTDOWN -> current)).toMap.asJava)
+
+ val workerStatus = new WorkersStatus(res.unknownWorkers,
newShutdownWorkers)
+ workerStatusListeners.asScala.foreach { listener =>
try {
listener.notifyChangedWorkersStatus(workerStatus)
} catch {
case t: Throwable =>
logError("Error while notify listener", t)
}
+ }
}
+
+ logDebug(s"Current blacklist $blacklist")
}
}
diff --git
a/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
b/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
new file mode 100644
index 000000000..9120a4936
--- /dev/null
+++
b/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.celeborn.client
+
+import java.util
+
+import org.junit.Assert
+
+import org.apache.celeborn.CelebornFunSuite
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.CelebornConf.WORKER_EXCLUDED_EXPIRE_TIMEOUT
+import org.apache.celeborn.common.meta.WorkerInfo
+import
org.apache.celeborn.common.protocol.message.ControlMessages.HeartbeatFromApplicationResponse
+import org.apache.celeborn.common.protocol.message.StatusCode
+
+class WorkerStatusTrackerSuite extends CelebornFunSuite {
+
+ test("handleHeartbeatResponse") {
+ val celebornConf = new CelebornConf()
+ celebornConf.set(WORKER_EXCLUDED_EXPIRE_TIMEOUT, 2000L);
+ val statusTracker = new WorkerStatusTracker(celebornConf, null)
+
+ val registerTime = System.currentTimeMillis()
+ statusTracker.blacklist.put(mock("host1"), (StatusCode.UNKNOWN_WORKER,
registerTime));
+ statusTracker.blacklist.put(mock("host2"), (StatusCode.WORKER_SHUTDOWN,
registerTime));
+
+ // test reserve (only statusCode list in handleHeartbeatResponse)
+ val empty = buildResponse(Array.empty, Array.empty, Array.empty)
+ statusTracker.handleHeartbeatResponse(empty)
+
+ // only reserve host1
+ Assert.assertEquals(
+ statusTracker.blacklist.get(mock("host1")),
+ (StatusCode.UNKNOWN_WORKER, registerTime))
+ Assert.assertFalse(statusTracker.blacklist.containsKey(mock("host2")))
+
+ // add shutdown/blacklist
+ val response1 = buildResponse(Array("host0"), Array("host1", "host3"),
Array("host4"))
+ statusTracker.handleHeartbeatResponse(response1)
+
+ // test keep Unknown register time
+ Assert.assertEquals(
+ statusTracker.blacklist.get(mock("host1")),
+ (StatusCode.UNKNOWN_WORKER, registerTime))
+
+ // test new added workers
+ Assert.assertTrue(statusTracker.blacklist.containsKey(mock("host0")))
+ Assert.assertTrue(statusTracker.blacklist.containsKey(mock("host3")))
+ Assert.assertTrue(statusTracker.blacklist.containsKey(mock("host4")))
+
+ // test remove
+ val workers = new util.HashSet[WorkerInfo]
+ workers.add(mock("host4"))
+ statusTracker.removeFromBlacklist(workers)
+ Assert.assertFalse(statusTracker.blacklist.containsKey(mock("host4")))
+
+ // test register time elapsed
+ Thread.sleep(3000)
+ val response2 = buildResponse(Array.empty, Array("host5", "host6"),
Array.empty)
+ statusTracker.handleHeartbeatResponse(response2)
+ Assert.assertEquals(statusTracker.blacklist.size(), 2)
+ Assert.assertFalse(statusTracker.blacklist.containsKey(mock("host1")))
+ }
+
+ private def buildResponse(
+ blackWorkerHosts: Array[String],
+ unknownWorkerHosts: Array[String],
+ shuttingWorkerHosts: Array[String]): HeartbeatFromApplicationResponse = {
+ val blacklist = mockWorkers(blackWorkerHosts)
+ val unknownWorkers = mockWorkers(unknownWorkerHosts)
+ val shuttingWorkers = mockWorkers(shuttingWorkerHosts)
+ HeartbeatFromApplicationResponse(StatusCode.SUCCESS, blacklist,
unknownWorkers, shuttingWorkers)
+ }
+
+ private def mockWorkers(workerHosts: Array[String]):
util.ArrayList[WorkerInfo] = {
+ val workers = new util.ArrayList[WorkerInfo]
+ workerHosts.foreach(h => workers.add(mock(h)))
+ workers
+ }
+
+ private def mock(host: String): WorkerInfo = {
+ new WorkerInfo(host, -1, -1, -1, -1);
+ }
+}
diff --git
a/common/src/main/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfo.scala
b/common/src/main/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfo.scala
index 3255c184e..9b92e0705 100644
---
a/common/src/main/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfo.scala
+++
b/common/src/main/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfo.scala
@@ -19,6 +19,7 @@ package org.apache.celeborn.common.meta
import java.util
import java.util.concurrent.ConcurrentHashMap
+import java.util.stream.Collectors
import scala.collection.JavaConverters._
@@ -47,11 +48,6 @@ class ShufflePartitionLocationInfo {
getPartitions(slavePartitionLocations, partitionIdOpt)
}
- def getMasterPartitionIds(): util.Set[Integer] = {
- val value = masterPartitionLocations.keySet().asScala
- value.asJava.asInstanceOf[util.Set[Integer]]
- }
-
def containsPartition(partitionId: Int): Boolean = {
masterPartitionLocations.containsKey(partitionId) ||
slavePartitionLocations.containsKey(partitionId)
@@ -65,6 +61,12 @@ class ShufflePartitionLocationInfo {
removePartitions(slavePartitionLocations, partitionId)
}
+ def removeAndGetAllMasterPartitionIds(): util.Set[Integer] = {
+ masterPartitionLocations.entrySet().asScala
+ .filter(e => masterPartitionLocations.remove(e.getKey, e.getValue))
+ .map(e => e.getKey).toSet.asJava.asInstanceOf[util.Set[Integer]]
+ }
+
private def removePartitions(
partitionInfo: PartitionInfo,
partitionId: Int): util.Set[PartitionLocation] = {
diff --git
a/common/src/test/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfoSuite.scala
b/common/src/test/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfoSuite.scala
index 3c62ed93c..05e4f5d15 100644
---
a/common/src/test/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfoSuite.scala
+++
b/common/src/test/scala/org/apache/celeborn/common/meta/ShufflePartitionLocationInfoSuite.scala
@@ -61,7 +61,6 @@ class ShufflePartitionLocationInfoSuite extends
CelebornFunSuite {
// test get min epoch
val locations =
shufflePartitionLocationInfo.getAllMasterLocationsWithMinEpoch()
- println(locations)
assertTrue(locations.contains(partitionLocation00) &&
locations.contains(partitionLocation11))
// test remove
@@ -72,6 +71,12 @@ class ShufflePartitionLocationInfoSuite extends
CelebornFunSuite {
assertEquals(shufflePartitionLocationInfo.removeSlavePartitions(0).size(),
1)
assertEquals(shufflePartitionLocationInfo.getSlavePartitions().size(), 1)
assertEquals(shufflePartitionLocationInfo.getSlavePartitions(Some(1)).size(), 1)
+
+ // test remove all
+ assertEquals(
+ shufflePartitionLocationInfo.removeAndGetAllMasterPartitionIds(),
+ new util.HashSet[Integer] { add(1) })
+ assertEquals(shufflePartitionLocationInfo.getMasterPartitions().size(), 0)
}
private def mockPartition(partitionId: Int, epoch: Int): PartitionLocation =
{