shashank created CAMEL-26711:
--------------------------------
Summary: camel-kafka - KafkaIdempotentRepository: the rollback of
a failed add also removes the same key added by a peer
Key: CAMEL-26711
URL: https://issues.apache.org/jira/browse/CAMEL-26711
Project: Camel
Issue Type: Bug
Components: camel-kafka
Reporter: shashank
Assignee: shashank
Since CAMEL-23996, {{KafkaIdempotentRepository.add}} puts the key in the local
cache ({{putIfAbsent(key, key)}}), sends the add record synchronously, and when
the send fails rolls the cache back with {{cache.remove(key, key)}}.
The poller thread applies the records of the other instances with
{{cache.put(messageId, messageId)}}. When it applies the add of the same key by
a peer while the send of this instance is in flight, and the send then fails,
the rollback cannot tell the two apart (both values are the key) and removes
the key of the peer too. The local cache then misses a key that a peer added
and processed, so the next copy of the message is processed again on this
instance.
Sequence (two instances A and B, same topic):
# A: {{add("k")}} puts {{k}} and sends {{add k}}; the send waits for the broker.
# B processes the same message id; A's poller applies B's {{add k}} ({{k ->
k}}).
# A's send fails: {{cache.remove("k", "k")}} removes it.
# A: {{contains("k")}} is false, and the next copy of {{k}} is processed as new.
The rollback of CAMEL-23996 was meant to undo only the add of the failed call.
{{KafkaKeyValueRepository.putIfAbsent}} already does so ({{cache.remove(key,
newEntry)}}).
Expected: the rollback removes only the value put by the failed call, and a key
added by a peer in the meantime stays.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)