aglinxinyuan opened a new issue, #9410:
URL: https://github.com/apache/texera/issues/9410
### What happened?
Root cause: a state that an operator inside a loop body sends itself, from
`produce_state_on_start` or `produce_state_on_finish`, carries no loop stamp,
that is, no Loop Start id. #9366 makes an operator whose `process_state`
changes a loop's message send the message on unchanged first and the change
after it, so that a parallel branch's unchanged copy arriving later is one the
receiver already processed. That rule covers only stamped messages. An operator
that changes a body operator's own state sends only the change, and where the
branches meet again, or at Loop End, the other branch's unchanged copy is a
message the receiver has not seen, so whichever of the two arrives last wins.
```
P sends s = 1 when its input ends; P feeds X, whose process_state sets s =
10, and Y, which passes states on
X and Y both feed M, which reads s, and Loop End (update: got = s)
with #9366: M and Loop End read s = 10 in 3 of the 6 arrival orders, and s
= 1 in the other 3
main: M fails when it reads s: "loop variable s got two different
values in one iteration, 10 and 1";
Loop End's update fails: NameError: name 's' is not defined
(main's Loop End sends every state without a stamp on, out of the loop)
wanted: X sends P's state on before its change, so Y's copy is a
duplicate: s = 10 in every order
```
The loop design calls for every state message sent inside a loop to carry
its Loop Start's id, its message id and its depth, so that a copy cannot undo a
body operator's change: an operator where branches meet that receives A, then B
(a change of A), then the slower branch's copy of A ignores the copy. A body
operator's own state is such a message, but today it carries no Loop Start id.
Expected: an operator inside a loop stamps the states it sends itself with
its loop, at depth 0, so a change to one follows the original and a parallel
branch's unchanged copy is dropped as a duplicate, where the branches meet and
at Loop End. A body worker can take the stamp from the loop's message, which
Loop Start sends ahead of its data. Loop End's lost-envelope check
(`MainLoop._check_loop_state_arrived`) tells a body operator's own state from
the loop's by its missing stamp today, so it would need another signal.
Found in the review of #9366, which leaves this case out of its scope.
### How to reproduce?
The loop body, with Python UDFs:
```
Text Input -> Loop Start (initialization: i = 0)
-> P produce_state_on_finish: return State({"s": 1})
-> X process_state: if "s" in state: state["s"] = 10; return state
-> Y (the default process_state)
X and Y -> M (a UDF whose process_tuple reads self.loop_variables["s"]) and
-> Loop End (update: got = s)
```
Running it end to end, the result depends on the order in which X's and Y's
states reach M and Loop End. Replaying each worker's output, with every
interleaving of X's and Y's states (each in its own order) handed to M and to
Loop End, gives:
- With #9366 (fa08044725): P sends Loop Start's message and its state `s =
1` (new id, no stamp). X sends Loop Start's message and `s = 10` (new id, no
stamp); Y sends Loop Start's message and `s = 1` under P's id. M and Loop End
read `s = 10` in 3 orders (Y's `s = 1` before X's change) and `s = 1` in 3 (Y's
copy after it), with no error.
- On main (4fba9ebcfa): M processes every state without an error, but
reading `s` fails in every order with "loop variable s got two different values
in one iteration, 10 and 1: a loop's variables must not change inside its body"
(or "1 and 10"), and Loop End's update fails with `NameError: name 's' is not
defined`, because main's Loop End sends every state without a stamp on, out of
the loop.
### Version/Branch
1.4.0-incubating-SNAPSHOT (main)
### Commit Hash (Optional)
fa08044725ad32b6f886eb1e6e1f5fe8cf1a5ce2 (head of #9366; on main the same
workflow fails instead, see above)
### What browsers are you seeing the problem on?
_No response_
### Relevant log output
```shell
main: RuntimeError: loop variable s got two different values in one
iteration, 10 and 1: a loop's variables must not change inside its body
NameError: name 's' is not defined (Loop End's update)
with #9366: none; M and Loop End read s = 1 in 3 of the 6 orders
```
--
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]