Repository navigation
Conversation
|
QA tests have started for PR 1643. This patch merges cleanly. |
|
QA results for PR 1643: |
|
QA tests have started for PR 1643. This patch merges cleanly. |
|
QA results for PR 1643: |
There was a problem hiding this comment.
Does sock.recv return 0 itself?
There was a problem hiding this comment.
Are there any concerns (performance or otherwise) related to two different processes polling on the same file descriptor?
There was a problem hiding this comment.
If an Exception raised, n is not defined.
This threads will sleep 0.1 after every poll, the overhead will be low, it should not effect another process reading the socket.
There was a problem hiding this comment.
I was wondering if the kernel does anything special to tie sockets to processes (similar to Java lock biasing).
For the n thing, I was asking why we bother reading n, why not just set something like socketClosed = False which we set to True in the except condition, rather than reusing this variable n.
There was a problem hiding this comment.
In most cases, there is no exception, recv() will return 0.
|
QA tests have started for PR 1643. This patch merges cleanly. |
|
QA results for PR 1643: |
|
QA tests have started for PR 1643. This patch merges cleanly. |
|
QA results for PR 1643: |
|
Would it be possible to store the PIDs of the workers inside of PythonWorkerFactory and directly kill the workers via SIGTERM? Or send a command to the Python daemon and have it kill the workers? That seems like it would be less complex than this socket-polling approach. |
|
I had tried these two approach, we have not easy way to get PIDs of workers, because it's platform dependent. Sending command to Python daemon will also need the identity of worker, it will need another channel to send commands. If there are exceptions in Java reading/writing threads, which may lead to close the socket, so we still need this kind of method to kill worker if the socket is closed. |
|
I don't think we have platform-dependent problems using PIDs, since Windows doesn't use the daemon to launch its PySpark workers; we only have to support Unix platforms in this code. |
|
I think that some of the existing One note: I'm a bit wary of the mixture of fork() and Thread in the same daemon's forked process; is this safe? |
|
Good question, it's dangerous to mix threads and fork(), it may be cause dead lock in child process. But in this case, because of GIL, then fork() happens, monitor thread is blocked or sleeping or polling, they are thread safe, so it will be a problem. |
|
I will wait for your patch, and think about using PIDs. |
|
@JoshRosen I had redo this PR based your cleanup, plz review again. |
|
QA tests have started for PR 1643. This patch merges cleanly. |
|
QA results for PR 1643: |
There was a problem hiding this comment.
I think that os.fork() already handles negative return values by throwing OSError, so I think this else block is dead code: https://docs.python.org/2/library/os.html#os.fork
|
QA tests have started for PR 1643. This patch merges cleanly. |
There was a problem hiding this comment.
The other accesses of daemonWorkers are guarded by synchronized blocks; does this access also need synchronization? It looks like calls to stopWorker() only occur from destroyPythonWorker(), which is synchronized using the SparkEnv object, but that's a different lock. To be on the safe side, we should probably add synchronized here unless there's a good reason not to.
There was a problem hiding this comment.
Actually, I think the current synchronization is fine: every call of PythonWorkerFactory's public methods is guarded by SparkEnv's lock.
|
This looks good overall and I'd say it's ready to merge once we address my last two comments. |
|
QA results for PR 1643: |
fix several bugs
|
QA tests have started for PR 1643. This patch merges cleanly. |
|
I had fixed several bugs and improve the kill approach, it has unit tests now. |
|
QA results for PR 1643: |
|
Thanks for updating this! In my earlier review, I had overlooked that the kill involved forking the JVM; your new approach of having the daemon kill the workers is much better. The test case looks good, too (clever use of Python's In #1680, there was some discussion over whether to use SIGKILL vs. SIGHUP to kill the Python workers. Now that I've had more time to think about it, I think SIGKILL is a fine approach:
|
|
I've merged this into |
Kill only the python worker related to cancelled tasks. The daemon will start a background thread to monitor all the opened sockets for all workers. If the socket is closed by JVM, this thread will kill the worker. When an task is cancelled, the socket to worker will be closed, then the worker will be killed by deamon. Author: Davies Liu <davies.liu@gmail.com> Closes #1643 from davies/kill and squashes the following commits: 8ffe9f3 [Davies Liu] kill worker by deamon, because runtime.exec() is too heavy 46ca150 [Davies Liu] address comment acd751c [Davies Liu] kill the worker when task is canceled (cherry picked from commit 55349f9) Signed-off-by: Josh Rosen <joshrosen@apache.org>
|
@JoshRosen Thanks to review this, your comments help me a lot. |
Kill only the python worker related to cancelled tasks. The daemon will start a background thread to monitor all the opened sockets for all workers. If the socket is closed by JVM, this thread will kill the worker. When an task is cancelled, the socket to worker will be closed, then the worker will be killed by deamon. Author: Davies Liu <davies.liu@gmail.com> Closes apache#1643 from davies/kill and squashes the following commits: 8ffe9f3 [Davies Liu] kill worker by deamon, because runtime.exec() is too heavy 46ca150 [Davies Liu] address comment acd751c [Davies Liu] kill the worker when task is canceled
…metric (apache#1643) ### What changes were proposed in this pull request? This patch updates how `SQLMetric` merges two invalid instances where the value is both -1. ### Why are the changes needed? We use -1 as initial value of `SQLMetric`, and change it to 0 while merging with other `SQLMetric` instances. A `SQLMetric` will be treated as invalid and filtered out later. While we are developing with Spark, it is trouble behavior that two invalid `SQLMetric` instances merge to a valid `SQLMetric` because merging will set the value to 0. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing tests. Closes apache#38969 from viirya/minor_sql_metrics. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
… m8 (apache#1666) ### What changes were proposed in this pull request? This adds two rows to `sql/varka/plans/m8/PLAN.md` for two option-matrix findings of 23 November 2026: one random failure and one skip that flips. It also returns row 638 and the first step of row 637 to milestone 8. - Row 643: `VarkaFallbackReasonSuite`'s test "a planted reason is counted under its own metric..." failed in bin b001 (`isa=avx2`) of apache#1646's matrix, run 45118992922, and passed on rerun. It threw `IllegalStateException: no SQL execution of the session reports the node's metrics` (`VarkaFallbackReasons.java:89`). Row 402 fixed a failure of the same helper on 26 October, with a cause that was guessed and never confirmed. This throw is the branch that fix added. It means no execution in the store held the node's metrics at all, so the guessed cause does not explain it. The row asks for a failure message that lists the store's executions and their metric ids, then the real cause and a fix shown against it. - Row 644: `VarkaGroupingBoundSuite`'s test "under the exact grouping no shape declines, and none falls back to the greedy grouping" has a `skips.tsv` line under `driverOutputTable=false` that names composition 8. Matrices 45118008614 (apache#1644) and 45123550199 (apache#1643) called the line stale. On apache#1644's head with master merged in, the test fails again, and now composition 16 falls back. The skip list is keyed only by configuration, suite and test name. The test draws 60 compositions with a fixed seed from the coverage table, so every new coverage row re-draws all of them, and the index that falls back moves. The row asks for a verdict that does not depend on which composition falls back: remove the fallback, or excuse projections by their content, never by an index. - Row 638 (the arm sweep on vecbricks/varka's runners) comes back from `m9/SCOPE.md` item 138 by the owner's decision of 23 November 2026. The local gate's sweep is the throughput limit. The row loses its "Moved" note and gets a dated one. `VARKA-638.md` moves back to `m8/`, and its citations of rows 637 and 522 now point at `m9/`. Item 138 and `PLAN.md` section 8 drop the row and now count 41 rows. Row 638 depends on row 637's step 1, the first stage, which comes back too (next item). On merge the issue mirror (`dev/varka_issues.py`) should reopen apache#1654, the row's issue, which apache#1656 closed. - Row 637's step 1 (the first stage of a pull request's option matrix: `dev/varka_matrix_scope.py --suites`, the `first` and `rest` lists, the plan artifact, the `stages` input, the two bin jobs and the summary line) comes back to milestone 8 by the owner's decision of 23 November 2026. Row 638 plans from its `dev/varka_matrix_scope.py`, and the fork's 40 slots are the other limit on throughput. Steps 2 and 3 (the optional path tiers, `--replay`, the `auto` default) stay in milestone 9. The row's status is Planned again with a dated note, and in milestone 8 it is done on step 1's done-when: the two test dispatches have run, one live week is committed and predictions 1 to 4 are scored. `VARKA-637.md` moves back to `m8/`, and its citation of row 522 now points at `m9/`. Item 138 keeps only 637's steps 2 and 3 and now counts 40 whole rows; `PLAN.md` section 8 does the same. Row 638 and `VARKA-638.md` no longer say that their dependency is in milestone 9. `VARKA-637.md` 3.1 gains a note: on 23 November the local gate's arm sweep was narrowed to the defaults, `useAVX=2`/`useAVX=3` and the configurations that name a changed option (`varka-gate-sweep-scope`, apache#1667). So `first` keeps "the changed suites under every configuration" on CI as its own definition, not as "`pre-pr.sh`'s arm sweep". On merge the issue mirror should reopen apache#1653, the row's issue, which apache#1656 closed. A dry run of `dev/varka_issues.py` shows both reopens. Rows 643 and 644 move no census cell. They stay in milestone 8 because each turns red the option matrix that every milestone 8 pull request must pass before merge. Row 644 flips on the very pull requests that add coverage rows. ### Why are the changes needed? Two tests fail the option matrix at random or as coverage grows, and no open row owns either one. Each red run costs a rerun and holds up a merge. Row 638 comes back because the owner decided that the laptop's sweep is now the limit on how fast pull requests land. Row 637's first step comes back with it: row 638 builds on it, and the fork's slots are the other limit. ### Does this PR introduce _any_ user-facing change? No. Plan files only. ### How was this patch tested? Documents only. `dev/varka_plan_lint.py` (also `--check --offline`), `dev/varka_quote_check.py`, `dev/varka_catalogue_move.sh --check 8 9` and the pre-commit hook pass. The failure texts were read from the matrix report jobs of the three runs. ### Review `/code-review high` ran three times on 23 November 2026: on rows 643 and 644, after row 638's return was added, and after row 637's step 1 was returned. The third round fixed: `VARKA-637.md` 3.1's note says apache#1667 is still open, and `first` keeps its own definition either way; `VARKA-638.md` says its sweep stays the full one and is timed against the full laptop sweeps of 22 November; the tier clause in row 637's done-when is marked as milestone 9's steps 2 and 3; one paragraph was rewrapped. Earlier rounds fixed: Fixed: row 644 now says the test always draws 60 compositions and every coverage row re-draws them, so an excuse must name projections by content, and its done-when needs the same verdict over several draws; the composition-16 reading is marked as having no run id; row 643 closes only on a reproduction or a diagnostic message, not on passing runs; item 138 records that it first listed 42 rows and that row 638 went back; one section reference and one wrapped line were fixed. Left as they are: - Both reviews asked to file rows 643 and 644 in milestone 9 under 12.3. They stay in milestone 8, with the reason written in each row: each one turns red the matrix every milestone 8 pull request must pass. - Not from this branch: `VARKA-638.md` 3.5 and its step 4 still treat `pre-pr.sh` as a `~/varka-ops` script, but apache#1639 moved it into the tree as `dev/varka_ops/pre-pr.sh`. Row 638's build should change the copy in the tree and count it toward the size cap. - Also not from this branch: `dev/varka_issues.py` does not treat **Filed** as a status, so every Filed row's issue is titled "[VARKA-n] Filed" (622, 631, 632 and 636 already are), and 643 and 644 will be too. Row 356's status still says it is not merged, though apache#1567 merged on 21 November. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5)
…che#1643) <!-- title: [VARKA-358] Fuse exp, expm1, cbrt and the logarithms bit for bit --> ### What changes were proposed in this pull request? Varka now fuses `exp`, `expm1`, `cbrt`, `ln`, `log` (one and two arguments), `log10`, `log1p` and `log2` over `DOUBLE`. Before this, each of them declined and the row engine ran it. - Each lane calls the method Spark's generated code calls: `StrictMath.exp`, `expm1`, `log`, `log10`, `log1p`, and `Math.cbrt`. So every answer has Spark's bits. - The log family's null (`x <= 0.0`, `x <= -1.0` for `log1p`) is built as `IfElse(x <= t, NULL, call)` from nodes the emitter already lowers. No new node. - `log2(x)` and `log(b, x)` divide as Spark writes them. A constant base is folded at compile time. - `coverage.json` gains 11 "Math functions" rows. The census marks the eight entries done. - The math baseline benchmark marks twelve sections as fused. <details> <summary>Design details</summary> `MathFn` gains `EXP`, `EXPM1`, `LOG`, `LOG10`, `LOG1P` (owner `java.lang.StrictMath`, the class Spark's code names) and `CBRT` (owner `java.lang.Math`, the host's answer, as in Spark). They use the per-lane call that row 356 (apache#1567) built: `v.lane(k)`, the static call, `v.withLane(k, r)`, unrolled over the baked lane count. The emitter changes only in its operator switch. `VarkaMathDomain.nullAtOrBelow(fn, x, t, fault)` builds `IfElse(Compare(IEEE_LE, x, t), NullValue(DOUBLE), MathUnary(fn, x))`. `IEEE_LE` is Java's `<=`. So `-0.0` is null and NaN reaches the call, as in Spark. A null operand makes the compare unknown. That lane takes the call, whose validity is the operand's, so it stays null. `VarkaMathCompiler`: - `exp`, `expm1`, `cbrt`: the call. - `ln`, `log10`, `log1p`: the call under the null. - `log2`: `ln(x) / StrictMath.log(2)`, Java's divide (`DIV WRAP`). - `log` with `EulerNumber` on the left (as parsed): `ln(x)`, no divide, as Spark's code generator writes it. After the optimizer folds `e`, it is a constant base, and Spark's code divides too. - `log(b, x)` with a constant base: `ln(x)` divided by `StrictMath.log(b)`, computed by Catalyst's own `eval`. A base at or below `0.0`, a null base, or a base whose evaluation throws declines. - `log(b, x)` with a column base: `ln(x) / ln(b)`, null where either is. - `pow` and `hypot` still decline. They are the next part (358a2, a two-operand call node). A test-only fault, `FloatingFault.MATH_DOMAIN_LT`, plants `<` for `<=` in the null. </details> ### Why are the changes needed? Queries with `exp` or a logarithm ran wholly on the row engine, together with the arithmetic around them. This part adds the exact default form, a per-lane call, bit for bit Spark's. Later parts measure Varka's fdlibm ports (`VarkaMathPort.exp`, merged in apache#1609) against it, as option arms. ### Does this PR introduce _any_ user-facing change? No new setting. Projections with these functions over `DOUBLE` now fuse, with Spark's answers bit for bit. ### How was this patch tested? `pre-pr.sh` passed on the laptop on head `7c0d498e2db`, master `194f28f6777` merged and the generated files regenerated: - extra-gate passed: `lint-java`, Error Prone, `lint-scala` and the invariant and proof suites. - The push check passed: six catalyst suites under the defaults, 46 tests passed and none failed. The size is 831 counted lines. - The arm sweep passed: `VarkaCoverageSuite`, `VarkaMathCompilerSuite`, `VarkaMathExactSuite` and `VarkaMatrixSuite` under the defaults and all 58 configurations, with no failure. - Not run: any benchmark, CI Build and the option matrix. - The `driverOutputTable=false` skip of VarkaGroupingBoundSuite's "under the exact grouping no shape declines" test is dropped: option matrix 45123550199 (bin b086) called it stale, and on the head merged with master `c4b0475d86e` the test passes under that option and at the defaults (`dev/varka_matrix.sh --module catalyst --config driverOutputTable=false --suites VarkaGroupingBoundSuite`). `pre-pr.sh` then passed again on `f9ed820738d`, master `c685d37b8eb` merged. <details> <summary>Full test record and what was not run</summary> The 20 November run of the same change on its old base (`catalyst/Test/compile`, `sql/Test/compile`, `VarkaMathExactSuite` and `VarkaMathCompilerSuite`, 11 tests passed) is recorded in `VARKA-356.md` 10.2. It ran before the rebuild on master and is not evidence for this head. The rebuild moved the domain plant into `FloatingFault.MATH_DOMAIN_LT` and added 22 `skips.tsv` lines for the 11 new coverage rows, under `validityByWidth=false` and `lanesOverride=16`. The arm sweep passed with those lines. The first gate failed in `VarkaMathCompilerSuite`: the failing-base test parsed its SQL through a test helper that folds a string cast to double itself, so the ANSI cast raised in the test before the compiler ran. The test now builds the expression, bare and inside an `If`, and a null-base test was added. </details> ### Review `/code-review high` found two important issues. One is fixed and the other is resolved by the owed regeneration. One nit is fixed and one is left. The size is 798 counted lines. <details> <summary>Review findings and what changed</summary> - Important, fixed: a constant `log` base whose evaluation throws, such as an ANSI cast in a branch that no row takes, failed the query at planning. Such a base now declines and the row engine answers. - A second `/code-review high` on the test fix: four nits fixed (null-base test, the `If` shape, a comment and the Javadoc). Left: the test helper's unguarded fold, and the decline reason not naming the exception. - Important: the census lines said done before `coverage.json` was regenerated. The regeneration commit resolves this. - Nit, fixed: the `log(x)` coverage note now says what the optimizer's folded `e` compiles to. - Nit, left: the `MATH_DOMAIN_LT` plant builds its IR directly, not through the compiler. The coverage harness and differential suites compare each SQL form with the row engine, so they check the compiler's asymptotes and divisors. </details> ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5)
…e#1644 made stale (apache#1694) ### What changes were proposed in this pull request? This deletes one line of the option matrix's skip list, `sql/varka/matrix/skips.tsv`, and records the event in row 644 of the plan. The line says that the `VarkaGroupingBoundSuite` test "under the exact grouping no shape declines, and none falls back to the greedy grouping" fails under `driverOutputTable=false`. Since apache#1644 the test passes there, so the matrix fails the line as stale. ### Why are the changes needed? The option matrix fails on master. The skip list must name only tests that do fail: a listed test that passes fails its bin, so that the list does not hide a test. Every pull request's matrix that runs on master since apache#1644 fails this bin, as apache#1693's bin b135 did, and so does the next scheduled matrix of master. The local runs of the suite under `driverOutputTable=false` (`dev/varka_matrix.sh --module catalyst --config driverOutputTable=false --suites VarkaGroupingBoundSuite`): | Commit | Result | |---|---| | `a55f82c2427` (apache#1643) | the test passes; apache#1643 had deleted the line | | `26b24c75b1b` (apache#1644) | the test passes: stale line | | `6ec492b53cf` (master, apache#1692) | the test passes: stale line | | master with the line deleted | passes | apache#1643 deleted the line, because its coverage rows made the test pass. apache#1644 added the line back, because the test failed on its own base, which did not have apache#1643. Its refresh onto master merged without a conflict, and no matrix ran on the result. This is a stopgap. Row 644 of `sql/varka/plans/m8/PLAN.md` tracks this line: the test draws 60 compositions from the coverage table with a fixed seed, so each new coverage row draws them again, and the verdict under `driverOutputTable=false` follows whichever draw falls back. The next pull request that adds a coverage row can make the test fail again under this option. Row 644's fix makes the verdict not depend on the draw. This pull request adds the day's data point to the row. `skips.tsv` merges with git's union driver (`sql/varka/.gitattributes`). A branch that appends a line after this one in the `driverOutputTable=false` block can bring the deleted line back in a local merge with master, so check the block after such a merge. ### Does this PR introduce _any_ user-facing change? No. It changes only the test configuration of the option matrix. ### How was this patch tested? - The suite under `driverOutputTable=false`, with the line deleted, on the laptop: passes. - The local gate (`pre-pr.sh`): the regeneration of generated files, lint-java, Error Prone, lint-scala, the invariant and proof suites, and the push check. - `/code-review high` of the change: no bugs, 3 findings. Fixed: the pull request cites row 644 and adds the data point to it. Recorded here: the line can flip again (row 644), and the union merge driver can bring it back. - The option matrix of this pull request. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5)
Kill only the python worker related to cancelled tasks.
The daemon will start a background thread to monitor all the opened sockets for all workers. If the socket is closed by JVM, this thread will kill the worker.
When an task is cancelled, the socket to worker will be closed, then the worker will be killed by deamon.