kunwp1 commented on code in PR #9508:
URL: https://github.com/apache/texera/pull/9508#discussion_r4595688167
##########
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:
Is this pin needed? It seems to be here because `containsOperator`, which is
public in bytecode, changes `Region`'s computed UID. Java serialization is off
in `cluster.conf`, though: `allow-java-serialization = off`, and
`java.io.Serializable` is bound to Kryo, which ignores `serialVersionUID`.
Since `containsOperator` has one caller, keeping the lookup in
`CostBasedScheduleGenerator` (`val regionOpIds =
existingRegion.getOperators.map(_.id)`) would leave `Region` unchanged and
remove the only `@SerialVersionUID` in amber.
##########
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:
`getAllLinkExecutions` already pairs each link execution with its
`PhysicalLink`, and a link's channels always run between the workers of its two
operators, since they come from that link's `channelConfigs`. Filtering on the
link removes the worker-name regex, so neither the memo map parameter nor the
`lazy val physicalOpByWorker` in `ReconfigurationHandler` is needed:
```scala
val channelScope =
cp.workflowExecution.getRunningRegionExecutions.iterator
.flatMap(_.getAllLinkExecutions.iterator)
.collect {
case (link, linkExecution)
if scopeOps.contains(link.fromOpId) &&
scopeOps.contains(link.toOpId) =>
linkExecution
}
.flatMap(_.getAllChannelExecutions.iterator.map(_._1))
```
##########
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:
Could this stay one `map`? An empty list already maps to `Nil` and a single
component maps to one entry, so the two extra branches and the index map don't
change the result, and there are only ever a few components and
reconfigurations here. `mcsPlan.getSourceOperatorIds` also already does what
`getComponentSources` re-implements:
```scala
val mcsSources = mcsPlan.getSourceOperatorIds
connectedSets.asScala.toList.map { component =>
val operators = component.asScala.toSet
FriesComponent(
operators.intersect(mcsSources),
operators,
reconfigurations.iterator.filter(req =>
operators.contains(req.targetOpId)).toSet
)
}
```
--
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]