Skip to content

[GH-3548] Fix ST_Force4D thread safety - #3549

Merged
jiayuasu merged 2 commits into
apache:masterfrom
FurkhanShaikh:fix/force3dm-force4d-correctness
Nov 16, 2026
Merged

jiayuasu merged 2 commits into
apache:masterfrom
FurkhanShaikh:fix/force3dm-force4d-correctness

Conversation

@FurkhanShaikh

@FurkhanShaikh FurkhanShaikh commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

GeometryForce4DTransformer kept hasZ/hasM in private static fields that were set in transform() and read in transformCoordinates(). Concurrent calls on geometries with different dimensions overwrote each other's flags and silently returned wrong ordinates, including NaN (details and reproducer in #3548).

hasZ and hasM are now instance fields, set on the transformer that the static entry point already creates for each call, so concurrent calls no longer share state.

This PR is limited to the race. The mixed-dimension collection handling and the ST_Force3DM XYZM case described in #3548 will be handled in a follow-up issue and PR.

How was this patch tested?

  • New FunctionsTest.force4DIsThreadSafe: 8 threads alternate between an XYZ and an XYM line. On master it fails (6,692 wrong results out of 160,000 calls on my machine); with this change it passes.
  • Existing FunctionsTest passes.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

…4D dimension handling

GeometryForce4DTransformer kept hasZ/hasM in static fields, so concurrent
calls on geometries with different dimensions overwrote each other's state
and returned wrong ordinates (including NaN). The decision is now made per
coordinate sequence with no shared state.

Also fixed:
- ST_Force3DM returned XYZM input unchanged instead of dropping Z.
- Geometry collections with mixed dimensions lost existing M values in
  ST_Force3DM and got NaN Z values in ST_Force4D.

Generated-by: AI coding assistants (Gemini, GPT, Claude)
@jiayuasu

Copy link
Copy Markdown
Member

Could we keep this PR focused on the ST_Force4D race and move the dimension-handling changes to a separate PR?

The static transform(geometry, zValue, mValue) entry point already creates a new GeometryForce4DTransformer for each call. Making hasZ and hasM instance fields and initializing them on that new transformer before calling transform(geometry) would isolate the flags between concurrent calls. The static entry point would also need to use transformer.hasZ / transformer.hasM for its early-return check; changing the field declarations alone would not compile.

I compiled this minimal variant against the base revision and ran the new force4DIsThreadSafe test locally: it passed all 160,000 calls across 8 threads. The new mixed-dimension collection case still failed, as expected, since that is a separate correctness fix.

Please retain the concurrency regression test here and move the shared transformer refactor, mixed-dimension/NaN handling, and ST_Force3DM XYZM correction into a follow-up PR with their tests. That would let us fix the race with a small change and review dimension semantics, geometry-type preservation, and empty collection members separately.

Per review: make hasZ/hasM instance fields set on the per-call
transformer, keep the concurrency regression test, and move the shared
transformer refactor, mixed-dimension handling and the ST_Force3DM XYZM
fix to a follow-up PR.

Also rename test variables that the codespell pre-commit hook flagged.

Generated-by: AI coding assistants (Gemini, GPT, Claude)
@FurkhanShaikh FurkhanShaikh changed the title [GH-3548] Fix ST_Force4D thread safety and ST_Force3DM/ST_Force4D dimension handling [GH-3548] Fix ST_Force4D thread safety Nov 16, 2026
@FurkhanShaikh

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've narrowed the PR to the race fix as you suggested: hasZ/hasM are now instance fields set on the per-call transformer, and the static entry point uses them for the early return. The force4DIsThreadSafe regression test is kept. I also renamed two test variables that codespell flagged.

I'll open a separate issue and follow-up PR for the mixed-dimension collection handling and the ST_Force3DM XYZM case, with their tests.

@jiayuasu jiayuasu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 16, 2026
@jiayuasu
jiayuasu merged commit bb217ed into apache:master Nov 16, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ST_Force4D returns wrong Z/M values under concurrent execution (static state in GeometryForce4DTransformer)

2 participants