Skip to content

GH-601: [Gandiva] Synchronize some methods on the Projector - #602

Merged
lidavidm merged 1 commit into
apache:mainfrom
lriggs:projectorSynch
Feb 21, 2025
Merged

lidavidm merged 1 commit into
apache:mainfrom
lriggs:projectorSynch

Conversation

@lriggs

@lriggs lriggs commented Feb 12, 2025 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Multiple threads can attempt to create the same llvm expression in Gandiva. This isn't allowed with the new JIT compiler, so synchronizing will prevent this scenario.

What changes are included in this PR?

Synchronize some methods to avoid adding duplicate llvm expressions.

Are these changes tested?

Yes, through unit tests in Gandiva.

Are there any user-facing changes?

No.

Closes GH-601

@kou kou changed the title GH-601 Synchronize some methods on the Projector. GH-601 Synchronize some methods on the Projector Feb 12, 2025
@lidavidm

Copy link
Copy Markdown
Member

@lriggs since you've been working on Gandiva lately, would you be able to help take a look at the changes here?

@kou kou changed the title GH-601 Synchronize some methods on the Projector GH-601: Synchronize some methods on the Projector Feb 12, 2025
@kou kou changed the title GH-601: Synchronize some methods on the Projector GH-601: [Gandiva] Synchronize some methods on the Projector Feb 12, 2025
@kou

kou commented Feb 12, 2025

Copy link
Copy Markdown
Member

We should rebase on main after we merge GH-595.

@lidavidm

Copy link
Copy Markdown
Member

@lriggs since you've been working on Gandiva lately, would you be able to help take a look at the changes here?

Ok I'm clearly not paying attention...you are lriggs 😬

As Kou states, let's rebase this after the other PR.

@kou

kou commented Feb 20, 2025

Copy link
Copy Markdown
Member

Could you rebase on main?

@lriggs
lriggs requested a review from kou as a code owner February 20, 2025 18:06
@github-actions

This comment has been minimized.

@lriggs

lriggs commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

I rebased but don't seem to have permissions to add the bug-fix label.

@kou kou added the bug-fix PRs that fix a big. label Feb 20, 2025
@lidavidm
lidavidm merged commit 370031e into apache:main Feb 21, 2025
@lidavidm lidavidm added this to the 18.3.0 milestone Feb 21, 2025
lriggs added a commit to dremio/arrow-java that referenced this pull request Oct 8, 2026
…le-large-node parallelism (#33)

* apacheGH-601: Stripe Projector/Filter make() locking by cache key instead of a blanket process-wide lock

Projector.make() and Filter.make() are declared `static synchronized`, so
every LLVM module build in a process serializes behind one class-level
monitor -- regardless of whether the concurrent calls target the same
expression or completely unrelated ones. On a single JVM packed with many
threads (e.g. a large single-node executor), this collapses what should be
independent compilations onto one lock, which JFR shows as the dominant
source of monitor contention under concurrent query load.

The blanket lock was added in apacheGH-601/apache#602 to guard against a genuine
TOCTOU race in Gandiva's native object cache: two threads compiling the
identical (schema, expressions, selection vector mode, configuration)
tuple concurrently can both decide the entry is missing and independently
define the same generated LLVM symbol, causing LLVM ORC's duplicate-symbol
detection to fire. The real fix for that race belongs in the native
Gandiva cache-read path (a separate, non-arrow-java change); until it
lands, some form of serialization is still required for genuinely
identical concurrent builds.

Replace the class-level lock with a small striped lock keyed by a hash of
the same tuple that identifies a native cache entry (schema bytes,
expression/condition bytes, selection vector mode, configuration id).
Concurrent make() calls that hash to the same stripe still serialize --
preserving the invariant that avoids the duplicate-symbol crash -- while
unrelated concurrent compilations, which make up the large majority of
concurrent traffic, proceed in parallel instead of queuing behind one
process-wide lock.

Verified against ProjectorTest#testMakeProjectorParallel (the existing
apacheGH-601 concurrency repro) and the full Projector/Filter test suite with
the real Gandiva JNI library, no regressions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Remove lock stripe

* remove

* spotless

* add benchmark for synchronization changes

* fix error

* fix error

---------

Co-authored-by: Chris Pride <cpride@cpride.net>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][Gandiva] Synchronize some methods on Projector.

3 participants