davsclaus opened a new pull request, #30875: URL: https://github.com/apache/camel/pull/30875
JIRA: [CAMEL-26669](https://issues.apache.org/jira/browse/CAMEL-26669), [CAMEL-26670](https://issues.apache.org/jira/browse/CAMEL-26670) (follow-ups of CAMEL-26650) Two commits, one per ticket, both in the polling `aws2-kinesis` consumer (`useKclConsumers=false`, `Kinesis2Consumer`). ## CAMEL-26669: a stop or suspend ends the poll after the record being routed **Problem.** `processBatch` looped `while (!exchanges.isEmpty())` and never called `isBatchAllowed()`. A stop or suspend of the route waited until the whole `GetRecords` response of every shard was routed. Since CAMEL-26650 that can be 1000 records per shard, so with a slow route the graceful stop reached the shutdown timeout and was forced, and the records not routed by then failed one by one with `RouteStoppingException`. **Change** (the same as CAMEL-25570 did for `aws2-ddbstream`): - `processBatch` stops when `isBatchAllowed()` is false (the route is stopping or suspending with the default `CompleteCurrentTaskOnly`). - A shard whose batch was cut short does not keep the next iterator of the response (a null one, of a closed shard, would mark the shard closed too early). The next poll, after a resume, asks for a new iterator: `AFTER_SEQUENCE_NUMBER` of the last routed record. If no record of the shard was routed yet, it asks for `AT_SEQUENCE_NUMBER` of the first record of the response (new `firstNotRoutedSequenceNumbers`). - The exchanges that were not routed are released to the exchange factory (pooled exchanges). - A route that is stopped and started gets a new consumer, which starts from `iteratorType` or the resume strategy, as before. ## CAMEL-26670: the shards are read on a Camel thread pool, not on `ForkJoinPool.commonPool()` **Problem.** `getCurrentShardList().parallelStream().forEach(...)` did the blocking `GetShardIterator`/`GetRecords` calls and routed the records on the JVM-wide common fork-join pool. Those threads have no Camel name, are not managed or shut down by Camel, and are shared with the rest of the JVM. The concurrency was the CPU count and could not be set per endpoint. **Change**, as the ticket proposes: - New endpoint option `maxConcurrentShards` (default `10`). The consumer creates a fixed pool of that size with the `ExecutorServiceManager` in `doStart` (threads named `Kinesis_shard_reader`) and shuts it down in `doStop`. `shutdownNow` interrupts the reads still running on a forced stop and cancels the ones not started. A poll submits one task per shard and waits for all of them, so it still sends one `GetRecords` per shard and returns the routed count. - Failures behave as before: each shard keeps its own `RuntimeException`, and once all shards are read the poll throws the first one, unwrapped, with the others suppressed. An interrupt of the poll thread (forced stop) cancels the shard tasks too. - With one shard, or `maxConcurrentShards=1`, the consumer reads the shards one after the other on its own thread (one shard already ran there before). A configured `shardId` does not use the pool. - **Default (my decision, the ticket left it open):** `10`, the pool size of Camel's default thread pool profile. Every machine gets the same behaviour, and it is close to what a 10-CPU machine did before. On smaller machines, streams with more shards than CPUs are now read with more concurrency. The upgrade guide says how to limit it. ## Docs - Component page: the consumer-throughput section now describes `maxConcurrentShards` and the new stop/suspend behaviour. The catalog copy is regenerated. - Upgrade guide 4.24: two new `camel-aws2-kinesis` entries. The CAMEL-26650 entry is aligned: the long graceful-shutdown wait now applies only to `CompleteAllTasks`. `aws2-kinesis` is removed from the "not yet covered" batch consumers of the CAMEL-27515 entry, because `isBatchAllowed()` is false after a fatal error too. - Metadata, configurers, catalog JSON and the endpoint and component DSLs are regenerated for the new option. ## Tests - `KinesisConsumerSuspendedBatchTest` (5 tests) and `KinesisConsumerSuspendedBatchPooledExchangeTest` (+1) cover: - a suspend in the middle of a response, then resume: the rest is routed once, from `AFTER_SEQUENCE_NUMBER` 2; - a suspend before the first record: resumes at `AT_SEQUENCE_NUMBER` 1; - a closed shard cut short is read to its end before it counts as closed; - two shards, each cut at its own record, then complete after the resume; - `stopRoute` routes 2 of 1000 records with no shutdown timeout; - the pooled exchanges that were not routed are released once. **Fails on main:** all 11 (for example the stop test routed all 1000 records). - `KinesisConsumerShardThreadsTest` (4 tests) covers: - records are routed on `Kinesis_shard_reader` threads of this context; - `maxConcurrentShards=2` uses exactly two threads, and a barrier shows two shards are read at the same time; - `maxConcurrentShards=1` routes on the consumer thread, shard after shard; - the reader threads end when the route stops. **Fails without the second commit:** all 4 (records ran on `ForkJoinPool.commonPool-worker-N`). - Whole module: `mvn test` in `camel-aws2-kinesis` passes, including the DST test `KinesisConsumerDstTest` (1000 seeds), which now runs the shard reads through the `ExecutorServiceManager`. ## Overlap with #30843 #30843 (CAMEL-27459, shard monitor error handling) changes the same file. This PR does not touch the `ShardMonitor` class. A `git merge-tree` of #30843 with this branch gives only the conflict #30843 already has with current `main` (the `shardListError` line of CAMEL-27458 in `ShardMonitor.run`). This PR adds no new conflict. _Claude Code on behalf of davsclaus_ 🤖 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]
