aglinxinyuan commented on code in PR #9508:
URL: https://github.com/apache/texera/pull/9508#discussion_r4596005232


##########
amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/CoordinatorAsyncRPCHandlerInitializer.scala:
##########
@@ -51,4 +64,56 @@ class CoordinatorAsyncRPCHandlerInitializer(
     with RetrieveWorkflowStateHandler
     with ReconfigurationHandler {
   val actorId: ActorVirtualIdentity = cp.actorId
+
+  /**
+    * Resolves in-scope data channels and control channels across running 
regions, then
+    * injects an embedded control message to each source operator's workers.
+    */
+  private[coordinator] def sendEmbeddedControlMessageToSources(
+      ecmId: EmbeddedControlMessageIdentity,
+      ecmType: EmbeddedControlMessageType,
+      scopeOps: Set[PhysicalOpIdentity],
+      sourceOps: Iterable[PhysicalOpIdentity],
+      cmdMapping: Map[String, ControlInvocation],
+      physicalOpByWorker: mutable.Map[ActorVirtualIdentity, 
PhysicalOpIdentity] = mutable.Map.empty
+  ): Unit = {
+    if (sourceOps.isEmpty) {
+      return
+    }
+    val sourceWorkers = sourceOps.iterator
+      .flatMap(source => 
cp.workflowExecution.getLatestOperatorExecution(source).getWorkerIds)
+      .toList
+    if (sourceWorkers.isEmpty) {
+      return
+    }
+
+    def physicalOpFor(workerId: ActorVirtualIdentity): PhysicalOpIdentity =
+      physicalOpByWorker.getOrElseUpdate(workerId, 
VirtualIdentityUtils.getPhysicalOpId(workerId))
+
+    val channelScope = cp.workflowExecution.getRunningRegionExecutions.iterator
+      .flatMap(_.getAllLinkExecutions.iterator)
+      .flatMap(_._2.getAllChannelExecutions.iterator)
+      .map(_._1)
+      .filter(channelId =>
+        scopeOps.contains(physicalOpFor(channelId.fromWorkerId)) &&
+          scopeOps.contains(physicalOpFor(channelId.toWorkerId))
+      )

Review Comment:
   Done in d6e04339bd. `sendEmbeddedControlMessageToSources` now keeps the 
channels of each running link whose `fromOpId` and `toOpId` are both in scope, 
so it no longer parses worker names, and the memo map parameter and 
`physicalOpByWorker` in `ReconfigurationHandler` are gone.
   



##########
amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/Region.scala:
##########
@@ -30,6 +30,7 @@ import scala.jdk.CollectionConverters.IteratorHasAsScala
 case class RegionLink(fromRegionId: RegionIdentity, toRegionId: RegionIdentity)
 
 case class RegionIdentity(id: Long)
+@SerialVersionUID(-8249900282346857462L)

Review Comment:
   Not needed, agreed — it only kept a local Java-serialization check of 
`RegionPlan` passing, which Pekko's Kryo path never exercises. Done in 
d6e04339bd: `CostBasedScheduleGenerator` now builds `regionOpIds` from 
`getOperators`, so `containsOperator` and the `@SerialVersionUID` are gone.
   



##########
amber/src/main/scala/org/apache/texera/amber/engine/common/FriesReconfigurationAlgorithm.scala:
##########
@@ -40,88 +39,102 @@ object FriesReconfigurationAlgorithm {
       reconfigurations: Set[UpdateExecutorRequest]
   )
 
-  private def getOneToManyOperators(region: Region): Set[PhysicalOpIdentity] = 
{
-    region.getOperators.filter(op => op.isOneToManyOp).map(op => op.id)
-  }
-
   def getReconfigurations(
       workflowExecutionManager: WorkflowExecutionManager,
       reconfiguration: WorkflowReconfigureRequest
   ): Set[FriesComponent] = {
     // independently schedule reconfigurations for each region:
     workflowExecutionManager.getExecutingRegions
-      .flatMap(region => computeMCS(region, reconfiguration, 
reconfiguration.reconfigurationId))
+      .flatMap(region => computeMCS(region, reconfiguration.reconfiguration))
   }
 
   private def computeMCS(
       region: Region,
-      reconfiguration: WorkflowReconfigureRequest,
-      epochMarkerId: String
+      reconfigurations: Seq[UpdateExecutorRequest]
   ): List[FriesComponent] = {
 
     // add all reconfiguration operators to M
-    val reconfigOps = reconfiguration.reconfiguration.map(req => 
req.targetOpId).toSet
+    val reconfigOps = reconfigurations.iterator.map(_.targetOpId).toSet
     val M = mutable.Set.empty ++ reconfigOps
 
     // for each one-to-many operator, add it to M if its downstream has a 
reconfiguration operator
-    val oneToManyOperators = getOneToManyOperators(region)
-    oneToManyOperators.foreach(oneToManyOp => {
-      val intersection = 
region.dag.getDescendants(oneToManyOp).asScala.intersect(reconfigOps)
-      if (intersection.nonEmpty) {
-        M += oneToManyOp
+    region.getOperators.foreach { op =>
+      if (op.isOneToManyOp) {
+        val descendants = region.dag.getDescendants(op.id)
+        if (reconfigOps.exists(descendants.contains)) {
+          M += op.id
+        }
       }
-    })
+    }
 
     // compute MCS based on M
-    var forwardVertices: Set[PhysicalOpIdentity] = Set()
-    var backwardVertices: Set[PhysicalOpIdentity] = Set()
+    var forwardVertices = Set.empty[PhysicalOpIdentity]
+    var backwardVertices = Set.empty[PhysicalOpIdentity]
 
     val topologicalOps = region.topologicalIterator().toList
-    val reverseTopologicalOps = topologicalOps.reverse
 
-    topologicalOps.foreach(opId => {
+    topologicalOps.foreach { opId =>
       val op = region.getOperator(opId)
-      val parents = op.inputPorts.flatMap(_._2._2).map(_.fromOpId)
-      val fromParent: Boolean = parents.exists(p => 
forwardVertices.contains(p))
+      val fromParent = op.inputPorts.valuesIterator
+        .flatMap(_._2)
+        .exists(link => forwardVertices.contains(link.fromOpId))
       if (M.contains(opId) || fromParent) {
         forwardVertices += opId
       }
-    })
+    }
 
-    reverseTopologicalOps.foreach(opId => {
+    topologicalOps.reverseIterator.foreach { opId =>
       val op = region.getOperator(opId)
-      val children = op.outputPorts.flatMap(_._2._2).map(_.toOpId)
-      val fromChildren: Boolean = children.exists(p => 
backwardVertices.contains(p))
-      if (M.contains(opId) || fromChildren) {
+      val fromChild = op.outputPorts.valuesIterator
+        .flatMap(_._2)
+        .exists(link => backwardVertices.contains(link.toOpId))
+      if (M.contains(opId) || fromChild) {
         backwardVertices += opId
       }
-    })
+    }
 
     val resultMCSOpIds = forwardVertices.intersect(backwardVertices)
     val newLinks =
       region.getLinks.filter(link =>
         resultMCSOpIds.contains(link.fromOpId) && 
resultMCSOpIds.contains(link.toOpId)
       )
-    val mcsPlan = PhysicalPlan(resultMCSOpIds.map(opId => 
region.getOperator(opId)), newLinks)
-
-    // find the MCS components,
-    // for each component, send an epoch marker to each of its source operators
-    val epochMarkers = new ArrayBuffer[FriesComponent]()
+    val mcsPlan = PhysicalPlan(resultMCSOpIds.map(region.getOperator), 
newLinks)
 
     val connectedSets = new ConnectivityInspector(mcsPlan.dag).connectedSets()
-    connectedSets.forEach(component => {
-      val componentSet = component.asScala.toSet
-      val componentPlan = mcsPlan.getSubPlan(componentSet)
-      val reconfigCommands =
-        reconfiguration.reconfiguration
-          .filter(req => component.contains(req.targetOpId))
-          .toSet
-
-      // find the source operators of the component
-      val sources = componentSet.intersect(mcsPlan.getSourceOperatorIds)
-      epochMarkers += FriesComponent(sources, 
componentPlan.operators.map(_.id), reconfigCommands)
-    })
-    epochMarkers.toList
+    def getComponentSources(operators: Set[PhysicalOpIdentity]): 
Set[PhysicalOpIdentity] =
+      operators.filter(opId => mcsPlan.dag.inDegreeOf(opId) == 0)
+
+    if (connectedSets.isEmpty) {
+      Nil
+    } else if (connectedSets.size() == 1) {
+      val operators = connectedSets.get(0).asScala.toSet
+      val commands =
+        reconfigurations.iterator.filter(req => 
operators.contains(req.targetOpId)).toSet
+      List(FriesComponent(getComponentSources(operators), operators, commands))
+    } else {
+      val componentByOperator = mutable.Map.empty[PhysicalOpIdentity, Int]
+      val components = connectedSets.asScala.iterator.zipWithIndex.map {
+        case (component, index) =>
+          val operators = component.asScala.toSet
+          operators.foreach(opId => componentByOperator.update(opId, index))
+          operators
+      }.toVector
+      val commandsByComponent = 
Array.fill(components.size)(Set.newBuilder[UpdateExecutorRequest])
+      reconfigurations.foreach { request =>
+        componentByOperator.get(request.targetOpId).foreach { index =>
+          commandsByComponent(index) += request
+        }
+      }
+
+      components.iterator.zipWithIndex.map {
+        case (operators, index) =>
+          FriesComponent(
+            getComponentSources(operators),
+            operators,
+            commandsByComponent(index).result()
+          )
+      }.toList

Review Comment:
   Done in d6e04339bd — `computeMCS` now maps the connected sets once and takes 
each component's sources from `mcsPlan.getSourceOperatorIds`, so 
`getComponentSources`, the size branches and the index map are gone.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to