This is an automated email from the ASF dual-hosted git repository.

angerszhuuuu 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 7a4f2ebd8 [CELEBORN-547] Refactor request related API (#1452)
7a4f2ebd8 is described below

commit 7a4f2ebd8add60b7bc3f1a04ac2165ce72d5e254
Author: Angerszhuuuu <[email protected]>
AuthorDate: Thu Apr 27 16:25:41 2023 +0800

    [CELEBORN-547] Refactor request related API (#1452)
---
 .../apache/celeborn/client/LifecycleManager.scala  | 54 ++++++++++------------
 .../common/protocol/message/ControlMessages.scala  |  6 +--
 .../service/deploy/worker/Controller.scala         | 21 ++++++---
 3 files changed, 42 insertions(+), 39 deletions(-)

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 54d7ed07b..05138549a 100644
--- a/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
+++ b/client/src/main/scala/org/apache/celeborn/client/LifecycleManager.scala
@@ -401,7 +401,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     // First, request to get allocated slots from Master
     val ids = new util.ArrayList[Integer](numPartitions)
     (0 until numPartitions).foreach(idx => ids.add(new Integer(idx)))
-    val res = requestSlotsWithRetry(applicationId, shuffleId, ids)
+    val res = requestMasterReleaseSlotsWithRetry(applicationId, shuffleId, ids)
 
     res.status match {
       case StatusCode.REQUEST_FAILED =>
@@ -461,8 +461,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
       logError(s"reserve buffer for $shuffleId failed, reply to all.")
       reply(RegisterShuffleResponse(StatusCode.RESERVE_SLOTS_FAILED, 
Array.empty))
       // tell Master to release slots
-      requestReleaseSlots(
-        rssHARetryClient,
+      requestMasterReleaseSlots(
         ReleaseSlots(applicationId, shuffleId, List.empty.asJava, 
List.empty.asJava))
     } else {
       logInfo(s"ReserveSlots for $shuffleId success!")
@@ -569,8 +568,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     }
 
     if (commitManager.tryFinalCommit(shuffleId)) {
-      requestReleaseSlots(
-        rssHARetryClient,
+      requestMasterReleaseSlots(
         ReleaseSlots(applicationId, shuffleId, List.empty.asJava, 
List.empty.asJava))
     }
   }
@@ -628,8 +626,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     if (shuffleResourceExists(shuffleId)) {
       logWarning(s"Partition exists for shuffle $shuffleId, " +
         "maybe caused by task rerun or speculative.")
-      requestReleaseSlots(
-        rssHARetryClient,
+      requestMasterReleaseSlots(
         ReleaseSlots(appId, shuffleId, List.empty.asJava, List.empty.asJava))
     }
 
@@ -662,7 +659,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     val parallelism = Math.min(Math.max(1, workerPartitionLocations.size), 
conf.rpcMaxParallelism)
     ThreadUtils.parmap(workerPartitionLocations.to, "ReserveSlot", 
parallelism) {
       case (workerInfo, (masterLocations, slaveLocations)) =>
-        val res = requestReserveSlots(
+        val res = requestWorkerReserveSlots(
           workerInfo.endpoint,
           ReserveSlots(
             applicationId,
@@ -765,7 +762,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
           workerSlotsPerDisk.add(slotsPerDisk)
       }
       val msg = ReleaseSlots(applicationId, shuffleId, workerIds, 
workerSlotsPerDisk)
-      requestReleaseSlots(rssHARetryClient, msg)
+      requestMasterReleaseSlots(msg)
       logInfo(s"Released slots for reserve buffer failed workers " +
         s"${workerIds.asScala.mkString(",")}" + 
s"${slots.asScala.mkString(",")}" +
         s"${Utils.makeShuffleKey(applicationId, shuffleId)}, ")
@@ -977,11 +974,11 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
         shuffleKey,
         masterLocations.asScala.map(_.getUniqueId).asJava,
         slaveLocations.asScala.map(_.getUniqueId).asJava)
-      var res = requestDestroy(workerInfo.endpoint, destroy)
+      var res = requestWorkerDestroySlots(workerInfo.endpoint, destroy)
       if (res.status != StatusCode.SUCCESS) {
         logDebug(s"Request $destroy return ${res.status} for $shuffleKey, " +
           s"will retry request destroy.")
-        res = requestDestroy(
+        res = requestWorkerDestroySlots(
           workerInfo.endpoint,
           DestroyWorkerSlots(shuffleKey, res.failedMasters, res.failedSlaves))
       }
@@ -1001,14 +998,13 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
         latestPartitionLocation.remove(shuffleId)
         commitManager.removeExpiredShuffle(shuffleId)
         changePartitionManager.removeExpiredShuffle(shuffleId)
-        requestUnregisterShuffle(
-          rssHARetryClient,
+        requestMasterUnregisterShuffle(
           UnregisterShuffle(appId, shuffleId, RssHARetryClient.genRequestId()))
       }
     }
   }
 
-  private def requestSlotsWithRetry(
+  private def requestMasterReleaseSlotsWithRetry(
       applicationId: String,
       shuffleId: Int,
       ids: util.ArrayList[Integer]): RequestSlotsResponse = {
@@ -1020,17 +1016,15 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
         lifecycleHost,
         pushReplicateEnabled,
         userIdentifier)
-    val res = requestRequestSlots(rssHARetryClient, req)
+    val res = requestMasterRequestSlots(req)
     if (res.status != StatusCode.SUCCESS) {
-      requestRequestSlots(rssHARetryClient, req)
+      requestMasterRequestSlots(req)
     } else {
       res
     }
   }
 
-  private def requestRequestSlots(
-      rssHARetryClient: RssHARetryClient,
-      message: RequestSlots): RequestSlotsResponse = {
+  private def requestMasterRequestSlots(message: RequestSlots): 
RequestSlotsResponse = {
     val shuffleKey = Utils.makeShuffleKey(message.applicationId, 
message.shuffleId)
     try {
       rssHARetryClient.askSync[RequestSlotsResponse](message, 
classOf[RequestSlotsResponse])
@@ -1041,7 +1035,7 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     }
   }
 
-  private def requestReserveSlots(
+  private def requestWorkerReserveSlots(
       endpoint: RpcEndpointRef,
       message: ReserveSlots): ReserveSlotsResponse = {
     val shuffleKey = Utils.makeShuffleKey(message.applicationId, 
message.shuffleId)
@@ -1056,21 +1050,22 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     }
   }
 
-  private def requestDestroy(
+  private def requestWorkerDestroySlots(
       endpoint: RpcEndpointRef,
-      message: DestroyWorkerSlots): DestroyResponse = {
+      message: DestroyWorkerSlots): DestroyWorkerSlotsResponse = {
     try {
-      endpoint.askSync[DestroyResponse](message)
+      endpoint.askSync[DestroyWorkerSlotsResponse](message)
     } catch {
       case e: Exception =>
         logError(s"AskSync Destroy for ${message.shuffleKey} failed.", e)
-        DestroyResponse(StatusCode.REQUEST_FAILED, message.masterLocations, 
message.slaveLocations)
+        DestroyWorkerSlotsResponse(
+          StatusCode.REQUEST_FAILED,
+          message.masterLocations,
+          message.slaveLocations)
     }
   }
 
-  private def requestReleaseSlots(
-      rssHARetryClient: RssHARetryClient,
-      message: ReleaseSlots): ReleaseSlotsResponse = {
+  private def requestMasterReleaseSlots(message: ReleaseSlots): 
ReleaseSlotsResponse = {
     try {
       rssHARetryClient.askSync[ReleaseSlotsResponse](message, 
classOf[ReleaseSlotsResponse])
     } catch {
@@ -1080,9 +1075,8 @@ class LifecycleManager(appId: String, val conf: 
CelebornConf) extends RpcEndpoin
     }
   }
 
-  private def requestUnregisterShuffle(
-      rssHARetryClient: RssHARetryClient,
-      message: PbUnregisterShuffle): PbUnregisterShuffleResponse = {
+  private def requestMasterUnregisterShuffle(message: PbUnregisterShuffle)
+      : PbUnregisterShuffleResponse = {
     try {
       rssHARetryClient.askSync[PbUnregisterShuffleResponse](
         message,
diff --git 
a/common/src/main/scala/org/apache/celeborn/common/protocol/message/ControlMessages.scala
 
b/common/src/main/scala/org/apache/celeborn/common/protocol/message/ControlMessages.scala
index e64cec03f..2a9c4ffb8 100644
--- 
a/common/src/main/scala/org/apache/celeborn/common/protocol/message/ControlMessages.scala
+++ 
b/common/src/main/scala/org/apache/celeborn/common/protocol/message/ControlMessages.scala
@@ -403,7 +403,7 @@ object ControlMessages extends Logging {
       slaveLocations: util.List[String])
     extends WorkerMessage
 
-  case class DestroyResponse(
+  case class DestroyWorkerSlotsResponse(
       status: StatusCode,
       failedMasters: util.List[String],
       failedSlaves: util.List[String])
@@ -770,7 +770,7 @@ object ControlMessages extends Logging {
         .build().toByteArray
       new TransportMessage(MessageType.DESTROY_WORKER_SLOTS, payload)
 
-    case DestroyResponse(status, failedMasters, failedSlaves) =>
+    case DestroyWorkerSlotsResponse(status, failedMasters, failedSlaves) =>
       val builder = PbDestroyWorkerSlotsResponse.newBuilder()
         .setStatus(status.getValue)
       builder.addAllFailedMasters(failedMasters)
@@ -1087,7 +1087,7 @@ object ControlMessages extends Logging {
 
       case DESTROY_WORKER_SLOTS_RESPONSE =>
         val pbDestroyResponse = 
PbDestroyWorkerSlotsResponse.parseFrom(message.getPayload)
-        DestroyResponse(
+        DestroyWorkerSlotsResponse(
           Utils.toStatusCode(pbDestroyResponse.getStatus),
           pbDestroyResponse.getFailedMastersList,
           pbDestroyResponse.getFailedSlavesList)
diff --git 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Controller.scala
 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Controller.scala
index 4bb8ae689..83fb03f49 100644
--- 
a/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Controller.scala
+++ 
b/worker/src/main/scala/org/apache/celeborn/service/deploy/worker/Controller.scala
@@ -576,10 +576,11 @@ private[deploy] class Controller(
     // check whether shuffleKey has registered
     if (!partitionLocationInfo.containsShuffle(shuffleKey)) {
       logWarning(s"Shuffle $shuffleKey not registered!")
-      context.reply(DestroyResponse(
-        StatusCode.SHUFFLE_NOT_REGISTERED,
-        masterLocations,
-        slaveLocations))
+      context.reply(
+        DestroyWorkerSlotsResponse(
+          StatusCode.SHUFFLE_NOT_REGISTERED,
+          masterLocations,
+          slaveLocations))
       return
     }
 
@@ -626,12 +627,20 @@ private[deploy] class Controller(
     if (failedMasters.isEmpty && failedSlaves.isEmpty) {
       logInfo(s"Destroy ${masterLocations.size()} master location and 
${slaveLocations.size()}" +
         s" slave locations for $shuffleKey successfully.")
-      context.reply(DestroyResponse(StatusCode.SUCCESS, List.empty.asJava, 
List.empty.asJava))
+      context.reply(
+        DestroyWorkerSlotsResponse(
+          StatusCode.SUCCESS,
+          List.empty.asJava,
+          List.empty.asJava))
     } else {
       logInfo(s"Destroy ${failedMasters.size()}/${masterLocations.size()} 
master location and" +
         s"${failedSlaves.size()}/${slaveLocations.size()} slave location for" +
         s" $shuffleKey PartialSuccess.")
-      context.reply(DestroyResponse(StatusCode.PARTIAL_SUCCESS, failedMasters, 
failedSlaves))
+      context.reply(
+        DestroyWorkerSlotsResponse(
+          StatusCode.PARTIAL_SUCCESS,
+          failedMasters,
+          failedSlaves))
     }
   }
 

Reply via email to