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


##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/executor/LateBoundExecutor.scala:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.texera.amber.core.executor
+
+import com.fasterxml.jackson.core.JsonPointer
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.{ArrayNode, JsonNodeFactory, 
ObjectNode}
+import org.apache.texera.amber.core.state.State
+import org.apache.texera.amber.core.state.StateReferencing.SIDECAR_PROPERTY
+import org.apache.texera.amber.core.tuple.{Tuple, TupleLike}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+
+import java.lang.reflect.InvocationTargetException
+import scala.collection.mutable
+import scala.jdk.CollectionConverters.IteratorHasAsScala
+import scala.util.Try
+
+/**
+  * What a worker holds for an operator whose descriptor's `stateReferences` 
sidecar maps the JSON
+  * pointer of each placeholder to a loop variable.
+  *
+  * Unbound, it keeps and forwards each state message. It binds when the real 
executor is first
+  * needed, at a tuple or a finishing port: a channel carries its state 
messages ahead of its
+  * tuples, so every message has arrived by then. Their values are merged, a 
later one winning, so
+  * in a nested loop, whose inner body receives the outer loop's state first, 
an inner variable
+  * shadows an outer one of the same name. Each placeholder takes its 
variable's value, coerced to
+  * the placeholder's JSON type; the real executor is built through the normal 
factory path,
+  * opened, and shown the kept messages in order, as it would have seen them 
without references
+  * (what it returns for them is dropped: they were already forwarded as 
received). It is never
+  * rebound: workers are recreated for each iteration.
+  */
+class LateBoundExecutor private[executor] (

Review Comment:
   Good questions — I added a "Why the worker wraps the executor" section to 
the PR description. Short version:
   
   - **Why a wrapper.** It is the "placeholder in the setting, set when the 
state arrives" plan, applied where the setting lives: the descriptor. A JVM 
executor reads its setting when it is constructed — each one parses its own 
copy of the descriptor, and some compute from it right away 
(`ReservoirSamplingOpExec` splits `k` across its workers in its constructor). 
Once an executor exists, there is no common hook to change a setting inside it 
without editing every executor, so the wrapper writes the value into the 
descriptor and only then builds the executor.
   - **Why the first tuple, not the state message.** An operator can get 
several state messages in one iteration — one per upstream worker and input, 
and in a nested loop the outer loop's before the inner loop's. Every edge in a 
loop is materialized, so all of them arrive before the tuples; binding at the 
first tuple sees every variable and lets an inner variable shadow an outer one 
of the same name.
   - **Lifecycle.** `open()` still runs before the operator sees any tuple, 
just later. No JVM executor overrides `produceStateOnStart` (the default 
returns `None`, as the wrapper does), and every `processState` returns the 
state it received — the default does, and so does `IfOpExec` after choosing its 
output port. So forwarding the states as received, then replaying them into the 
real executor, gives the same output.
   



-- 
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