Croway opened a new pull request, #2054:
URL: https://github.com/apache/camel-spring-boot/pull/2054
## Summary
`SpringCacheStateStoreRedisIT` was added in #2046 and fails intermittently:
`providerLevelTimeToLiveExpiresEntries` in `Camel-Spring-Boot Daily` main #418,
and `explicitEipAdaptersRoundTripSerializableValues` locally. In both cases a
`get` right after a `put` returns `null`.
### Root cause
- Since Spring Data Redis 4.0 (we use 4.1.2), `DefaultRedisCacheWriter`
writes asynchronously by default when the connection factory is Lettuce. The
commit that introduced this is spring-projects/spring-data-redis@9f069e5a.
`RedisCache.put` returns before the `SET` has reached Redis. Strict behavior is
an opt-in setting: `RedisCacheWriterConfigurer#immediateWrites()`.
- Spring Boot 4.1 has no `spring.cache.redis.*` property for this setting.
- Spring's `Cache.put` contract allows it: "Actual registration may be
performed in an asynchronous or deferred fashion, with subsequent lookups
possibly not seeing the entry yet."
- A Redis `MONITOR` trace confirms it. The `SET` goes out on a separate
connection, and the next `GET` can reach Redis first.
This is not only a test problem. The state store, and EIPs such as the
Aggregate EIP that use it through `KeyValueAggregationRepository`, expect a
value to be readable right after it is written.
### Changes
- **Docs**, in `usage.adoc` and `limitations.adoc`, plus the regenerated
`state-store.adoc`:
- A new "Write visibility" limitation.
- A Redis example that enables immediate writes through a
`RedisCacheManagerBuilderCustomizer`.
- **Javadoc** of `SpringCacheKeyValueRepository`: the same constraint is
added to the design constraints list.
- **`SpringCacheStateStoreRedisIT`**:
- Configures immediate writes, as the docs recommend.
- New test `putIsVisibleToSubsequentGet`: 500 put/get round trips. Without
the customizer it fails within a few iterations (`expected: "value-2" but was:
"value-1"`).
### Alternative for reviewers
Because the state store has not been released yet, the starter could instead
configure this itself. When `camel.state-store.spring-cache.enabled=true` and
Spring Data Redis is present, it could register a highest-precedence
`RedisCacheManagerBuilderCustomizer` that enables immediate writes, so user
customizers can still override it. That needs optional dependencies on
`spring-boot-cache` and `spring-data-redis`. It would also change write
behavior for every cache of the application's `RedisCacheManager`, not only the
state stores. This PR keeps the documented opt-in. I'm happy to switch if
reviewers prefer the automatic approach.
## Test
- `mvn verify` in `components-starter/camel-state-store-starter`: 26 unit
tests and 5 Redis ITs pass.
- The Redis IT passed 5 runs in a row locally with Docker.
_Claude Code on behalf of Federico Mariani_
--
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]