allthingssecurity opened a new pull request, #27638:
URL: https://github.com/apache/camel/pull/27638

   # Description
   
   [CAMEL-25505](https://issues.apache.org/jira/browse/CAMEL-25505)
   
   A `lucene:<name>:insert` endpoint has one `LuceneIndexer` (one index 
`Directory`) that all its producers share. Three things stop indexing for good:
   
   - `LuceneIndexProducer.doStop()` closed the shared directory, so after a 
route restart, or after another route sending to the same endpoint is stopped, 
every insert fails with `AlreadyClosedException: this Directory is closed`.
   - `LuceneIndexer.index()` only closed its `IndexWriter` when the whole 
exchange was added. An exchange that fails in between (no body, a header that 
cannot be converted) left the writer open with the index write lock held, so 
every later insert fails with `LockObtainFailedException` until the JVM 
restarts.
   - Two exchanges indexing at the same time failed on that same lock (and 
shared the `indexWriter` field).
   
   This change closes the directory in `LuceneEndpoint.doShutdown()` instead of 
the producer's `doStop()`, makes `index()` synchronized, and rolls the writer 
back (discarding the failed exchange's documents and releasing the lock) when 
adding fails.
   
   This is one of three independent camel-lucene fixes of the same batch 
(inserts after a restart, query producer state, per-endpoint configuration); 
they change different files and apply in any order.
   
   Tests:
   - New `LuceneIndexProducerLifecycleTest` in camel-lucene: insert after a 
route restart; insert after stopping another route on the same endpoint; insert 
after an insert without a body; two inserts at once (a header whose String 
conversion waits while the first insert holds the writer).
   - Without the change: all four fail, e.g. `an insert after the route was 
restarted must succeed ==> expected: <null> but was: 
<org.apache.lucene.store.AlreadyClosedException: this Directory is closed>`.
   - With the change, camel-lucene tests pass: 
`LuceneIndexProducerLifecycleTest` (4), `LuceneIndexAndQueryProducerIT` (4), 
`LuceneQueryProcessorIT` (2), 0 failures.
   
   Found with a TLA+ model of the insert path (per-route producer start/stop, 
the shared directory, the write lock and the writer field): "every exchange 
sent to a started insert producer is indexed" is violated in 4 steps (stop, 
start, send, open on the closed directory). I then reproduced it with the real 
component.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built and tested camel-lucene, including the formatter and import-sort 
plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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