gnodet-bot commented on code in PR #30368:
URL: https://github.com/apache/camel/pull/30368#discussion_r4625497019
##########
components/camel-redis/src/main/java/org/apache/camel/component/redis/processor/aggregate/RedisAggregationRepository.java:
##########
@@ -477,13 +529,46 @@ protected void doStart() throws Exception {
}
}
- cache = redisson.getMap(mapName);
+ cache = redisson.getMap(mapName, CODEC);
+ warnUnreadableEntries(cache, mapName);
if (useRecovery) {
- persistedCache = redisson.getMap(persistenceMapName);
+ persistedCache = redisson.getMap(persistenceMapName, CODEC);
+ warnUnreadableEntries(persistedCache, persistenceMapName);
}
}
+ /**
+ * Logs a WARN when the hash has entries that are not serialized
exchanges, such as the entries stored by an older
+ * version of this repository, which are not read. Only the first bytes of
each value are checked.
+ */
+ private void warnUnreadableEntries(RMap<String, byte[]> map, String name) {
+ try {
+ long count = 0;
+ for (Map.Entry<String, byte[]> entry : map.entrySet(SCAN_COUNT)) {
Review Comment:
⚠️ **Medium:** `map.entrySet(SCAN_COUNT)` streams Redis entries in pages of
100, but the `for` loop consumes **all** pages. For a large aggregation hash
(e.g. 100k entries × 1KB each = ~100MB of byte[]s), this loads every serialized
value into the JVM heap at startup, just to check the first 2 magic bytes of
each. Consider streaming and discarding entries as they're read, or limiting
the check to the first N entries (e.g. break after finding the first 10
non-serialized entries, since the purpose is to warn, not to count exactly). If
an exact count is needed, a Redis Lua script checking magic bytes server-side
would avoid the JVM memory spike entirely.
##########
components/camel-redis/src/main/java/org/apache/camel/component/redis/processor/aggregate/RedisAggregationRepository.java:
##########
@@ -477,13 +529,46 @@ protected void doStart() throws Exception {
}
}
- cache = redisson.getMap(mapName);
+ cache = redisson.getMap(mapName, CODEC);
+ warnUnreadableEntries(cache, mapName);
if (useRecovery) {
- persistedCache = redisson.getMap(persistenceMapName);
+ persistedCache = redisson.getMap(persistenceMapName, CODEC);
+ warnUnreadableEntries(persistedCache, persistenceMapName);
}
}
+ /**
+ * Logs a WARN when the hash has entries that are not serialized
exchanges, such as the entries stored by an older
+ * version of this repository, which are not read. Only the first bytes of
each value are checked.
+ */
+ private void warnUnreadableEntries(RMap<String, byte[]> map, String name) {
+ try {
+ long count = 0;
+ for (Map.Entry<String, byte[]> entry : map.entrySet(SCAN_COUNT)) {
+ if (!isSerializedObject(entry.getValue())) {
+ count++;
+ }
+ }
+ if (count > 0) {
+ LOG.warn("The Redis hash {} has entries that are not exchanges
serialized by this version of"
+ + " RedisAggregationRepository (count: {}). These
entries are ignored: entries stored by an"
+ + " older Camel version are not read. See the
camel-redis section of the Camel 4.24 upgrade"
+ + " guide.",
+ name, count);
+ }
+ } catch (Exception e) {
+ LOG.debug("Cannot check the entries of the Redis hash {}", name,
e);
Review Comment:
💡 **Low:** When the scan fails (e.g. Redis is unreachable at startup), the
exception is silently downgraded to `DEBUG`. If the connection is broken, users
get no visible indication that the compatibility check was skipped — they might
not discover they're running against an incompatible Redis schema until they
encounter silent data loss. Consider `WARN` instead:
```suggestion
LOG.warn("Cannot check the entries of the Redis hash {}", name,
e);
```
--
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]