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

   # Description
   
   [CAMEL-27456](https://issues.apache.org/jira/browse/CAMEL-27456)
   
   Follow-up of 
[CAMEL-26539](https://issues.apache.org/jira/browse/CAMEL-26539) (#29122), 
which made the streaming upload
   write one exchange at a time, but only without `timestampGroupingEnabled`.
   
   With `streamingUploadMode=true` and `timestampGroupingEnabled=true`, 
`processWithTimestampGrouping` reads the body of an
   exchange in chunks (`bufferSize`, or `partSize` with `multiPartUpload`) and 
took the producer's lock once per chunk.
   Between two chunks of one exchange the lock was free, so:
   
   - another exchange of the same time window wrote its bytes into the window's 
upload. The stored object held the bytes
     of both exchanges mixed: with `bufferSize=4096`, an exchange A of 8192 
bytes and an exchange B of 8192 bytes sent at
     the same time gave an object of 4096 bytes of A, the 8192 bytes of B, then 
the last 4096 bytes of A, and both
     exchanges returned success. No failure and no timeout is needed, only two 
exchanges of one window at the same time
     (concurrent consumers, parallel splits, `threads()`);
   - the `streamingUploadTimeout` task could flush the window between two 
chunks, so the first part of the exchange went
     into one object and the rest into the next one.
   
   The window lookup and the message count of the window (`state.index++`) were 
also done without the lock.
   
   The change: `processWithTimestampGrouping` takes the lock once and calls 
`writeWithTimestampGrouping`, which holds the
   code that ran before (the window lookup, the reads of the body, and the 
per-chunk writes and S3 calls, without the
   per-chunk lock). This is the same shape as `processWithoutTimestampGrouping` 
/ `writeWithoutTimestampGrouping` since
   CAMEL-26539. The catch that aborts the window's upload on a failure is 
unchanged.
   
   Cost: no S3 call is added under the lock. The S3 calls of an exchange were 
already made under it, one chunk at a time;
   now the other exchanges of the producer, of any window, and the timeout 
flush wait while the body of an exchange is read
   and its chunks are written. A slow S3 already blocked the other exchanges 
for the time of one call; it still does, and a
   large body (several chunks) now keeps them waiting for all of its chunks. 
The reads of the body are under the lock now
   (they were outside it), so a body from a slow stream, such as a network 
stream that stalls, keeps them and the timeout
   flush waiting until it is read. A stop waits for the exchange that is being 
written too; before, a stop in the middle of
   an exchange stored its first chunks, and the rest went to a new upload that 
the stopped producer never completed. This
   is the trade-off CAMEL-26539 made for the
   path without timestamp grouping, and its upgrade guide entry, which says 
that bodies are read one at a time and how to
   upload large bodies in parallel, now covers timestamp grouping too (one 
sentence added, the "without
   `timestampGroupingEnabled`" restriction removed).
   
   An exchange can still end up in two objects when its own bytes reach 
`batchSize` (or the message count reaches
   `batchMessageNumber`) in the middle of its body: that is how batching works 
on both paths and is not changed here.
   
   Found with a TLA+ model of the timestamp grouping path (two producer threads 
with two-chunk exchanges, the timeout
   task, one window, an S3 fake per upload): on `main` the model finds the 
mixed object without any failure or timeout,
   and the timeout flush between two chunks of an exchange.
   
   Tests: new `AWS2S3StreamUploadTimestampGroupingConcurrentExchangesTest` 
(package-private, mocked `S3Client`, latches and
   Awaitility, no sleeps). The body of the first exchange stops after its first 
4096 bytes until the test releases it.
   
   - `anotherExchangeOfTheWindowIsNotWrittenBetweenTheReadsOfAnExchange`: a 
second exchange of the same window is sent
     meanwhile; the window must be one object with the bytes of each exchange 
in one piece (A then B);
   - `theTimeoutFlushDoesNotCutAnExchangeIntoTwoObjects`: 
`streamingUploadTimeout=50`; the exchange must be stored whole in
     one object.
   
   On `main` both fail (`AAAA BBBBBBBB AAAA`, and two objects of 4096 bytes). 
With the change both pass, and the
   camel-aws2-s3 unit tests pass (151 run, 0 failures, 0 skipped; run offline). 
The new class, 20 times in one JVM: 40 run, 0 failures. With
   the two related changes below merged as well, the module passes too (160 
run, 0 failures).
   
   Related changes on the same class, each its own PR and merging cleanly with 
this one: a stop that resets the open
   upload and always ends the timeout task, and the failure handling of the 
timeout flush and of `uploadPart` (data of
   exchanges that succeeded is kept when a flush fails).
   
   # 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-27456](https://issues.apache.org/jira/browse/CAMEL-27456).
   
   # 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 module, 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