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

   # Description
   
   [CAMEL-27384](https://issues.apache.org/jira/browse/CAMEL-27384)
   
   With `recursive=true` and a done file with a fixed name 
(`doneFileName=ready`), each directory has its own done file: the consumer 
takes the files of a directory only while `ready` is in that directory. The 
docs say the done file is deleted when its files are consumed. But a poll sets 
`BATCH_COMPLETE` on its last exchange only, and 
`GenericFileOnCompletion.handleDoneFile` deletes the done file of that exchange 
only. When a poll consumed files of several directories, only the done file of 
the directory of its last file was deleted; the others stayed. The done-file 
guard then no longer worked for those directories: the next file a producer 
wrote there was consumed at once, without a new done file, and with the default 
`readLock=none` possibly while it was still being written. Example: `d1/a.txt`, 
`d1/ready`, `d2/b.txt`, `d2/ready`; one poll consumes both files and deletes 
only `d2/ready`; a later `d1/next.txt` is consumed without a done file.
   
   CAMEL-25728 (the done file kept for the files a poll leaves) left this as it 
was.
   
   Change (`GenericFileConsumer`, `GenericFileOnCompletion`): with a done file 
with a fixed name (not `noop`, not a dynamic `${file:name}` name), 
`processBatch` finds the last exchange of each done file among the files of the 
batch, and that file deletes its done file once it completed, unless the poll 
kept it for files it left (as before for the last file of the poll). 
`BATCH_COMPLETE` and the other batch properties do not change. Without 
`recursive=true` all files share one done file, and its last file is the last 
file of the poll, so nothing changes there. Dynamic done files are still 
deleted for each file, and `noop=true` keeps them. The FTP, SFTP, SMB and Azure 
Files consumers share these classes.
   
   Docs: one sentence in the done file section of the file component (and its 
catalog copy). Upgrade guide: a 4.24 entry, as the done files of the other 
directories are now deleted where they stayed before.
   
   Model: found with a TLA+ model of the kept done files (polls, files of each 
poll routing on other threads, failures, read locks, stop/start, two 
directories, a producer that waits for the done file to go). I added the change 
as a switch (`PerDirLast`). On main a poll of two directories leaves a done 
file for files that are gone (`NoOrphanDone`, 149 and 851 distinct states, with 
and without `maxMessagesPerPoll`). With the change both hold (1,953 and 4,879 
distinct states), and so does every configuration that passed on main (same 
verdicts and counts). Together with the kept done file fixes of a separate PR 
(a kept done file is no longer deleted while a file of its poll still routes), 
every two-directory configuration holds up to 142,895 distinct states except 
the stop case below. TLC confirms the same counts on 6 configurations.
   
   Tests: new `FileConsumerDoneFileNameRecursiveTest` (camel-core, 
package-private): one poll consumes a file in each of three directories; once 
the files are moved, no done file may be left. Then a file written into `d1` 
without a done file must not be consumed while a file with a new done file in 
`d2` is. On main it fails (the done file of `d1` is left). With the change: 
camel-file 47 tests and the file tests of camel-core 
(`org.apache.camel.component.file.**`) 553 run, 12 skipped, 0 failures. The new 
test with `FileConsumerDoneFileNameAsyncLastFileTest`, 
`FileConsumerDoneFileNameFilesLeftTest` and `FilerConsumerDoneFileNameTest` 20 
times in one JVM: 340 run, 0 failures. The camel-ftp done-file tests were not 
run locally (CI runs them). Formatter and import-sort checks pass.
   
   Not changed:
   
   - With `recursive=true` and `maxMessagesPerPoll`, a poll whose listing was 
cut keeps the done file of every directory it listed. When the consumer stops, 
the kept done files are forgotten (as documented in 
`GenericFileKeptDoneFiles`), so a done file kept for a directory whose files 
were all consumed stays after a restart. Keeping the kept done files across a 
stop would fix it; I can open a separate JIRA.
   
   # 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): 
[CAMEL-27384](https://issues.apache.org/jira/browse/CAMEL-27384).
   
   # 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 the affected modules, including the formatter and 
import-sort plugins, and edited the catalog copy of the component doc by hand. 
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 commits carry 
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