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

   # Description
   
   [CAMEL-26705](https://issues.apache.org/jira/browse/CAMEL-26705)
   
   A stopped service runs `doInit()` again when it is started 
(`BaseService.init()`: "allow to initialize again if stopped or failed"). An 
idempotent repository is restarted like that when it is stopped and started, 
when its route is removed and added again (route reload, JMX), or when the 
CamelContext is restarted. Two camel-sql repositories were not safe to 
initialize twice:
   
   - `JdbcOrphanLockAwareIdempotentRepository.doInit()` rewrote its own 
`updateTimestampQuery` with `replaceFirst(DEFAULT_TABLENAME, getTableName())`, 
and `JdbcCachedMessageIdRepository.doInit()` its `queryAllString`. With a table 
name that contains the default name (`CAMEL_MESSAGEPROCESSED_ORDERS`, or 
`MYSCHEMA.CAMEL_MESSAGEPROCESSED` as in CAMEL-20010), every restart added it 
again: `UPDATE CAMEL_MESSAGEPROCESSED_ORDERS_ORDERS ...`. The orphan-lock 
keep-alive then failed on every run (only logged at ERROR), so the node's 
leases expired and another node could take over keys it was still processing; 
taking over an orphan lock failed with an SQL error. The cached repository 
could not be started again, as reloading its cache failed.
   - `JdbcOrphanLockAwareIdempotentRepository.doInit()` also created the 
keep-alive executor, which was shut down only in `doShutdown()`. Every 
stop/start left the previous executor running, and a stopped repository kept 
refreshing its leases.
   
   CAMEL-20010 (#11759) fixed the first point for the statements of the parent 
`JdbcMessageIdRepository` by deriving them from `DEFAULT_*` constants; these 
two queries were not covered.
   
   Change:
   - Both queries are derived from a new default constant in `doInit()`, in the 
same way as the parent class (`DEFAULT_UPDATE_TIMESTAMP_QUERY`, 
`DEFAULT_QUERY_ALL_STRING`, `String.replace`). As with the parent's statements, 
a custom query set together with `tableName` is now replaced by the default 
query for that table; the page already says `tableName` means "the default SQL 
queries but with a different table name", and the parent's 
`queryString`/`insertString`, which this repository also uses, are already 
replaced that way.
   - The keep-alive executor is created in `doStart()` and shut down in 
`doStop()` (`shutdown()` stops first, so it is shut down there too).
   
   A stopped repository no longer refreshes its leases. The keys it holds are 
kept, as before, so after a restart it refreshes them again; if it stays 
stopped longer than `lockMaxAgeMillis`, another node may take them over 
meanwhile, as it would for a crashed node.
   
   Tests (H2 embedded database, `tableName=CAMEL_MESSAGEPROCESSED_ORDERS`, 3 
stop/start cycles):
   - `JdbcOrphanLockAwareIdempotentRepositoryRestartTest`: the update query is 
unchanged and `keepAlive()` refreshes an expired lease; a recording 
`ExecutorServiceManager` shows that each stop shuts the keep-alive executor 
down, that one runs after the restarts, and none after `shutdown()`.
   - `JdbcCachedMessageIdRepositoryRestartTest`: the reload query is unchanged, 
and a key inserted into the table while the repository was stopped is in the 
cache after the next start.
   
   On main all three tests fail (`UPDATE 
CAMEL_MESSAGEPROCESSED_ORDERS_ORDERS_ORDERS_ORDERS ...`, the executor is not 
shut down on stop, the second start fails with `BadSqlGrammarException` on 
`..._ORDERS_ORDERS`); with the fix 3/3, and 60/60 over 20 runs. camel-sql 
module tests: 339 run (offline, both changes together), 0 failures; 2 errors in 
`SqlFunctionDataSourceTest`, which installs an embedded MariaDB and cannot run 
offline here (unrelated to this change).
   
   # 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-26705](https://issues.apache.org/jira/browse/CAMEL-26705).
   
   # 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 the core modules and camel-sql with the formatter and import-sort 
plugins and ran the camel-sql tests; no generated file changes. 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