Badhusha Muhammed created KAFKA-21593:
-----------------------------------------
Summary: Infinite loop in MM2 Bi-Directional replication
Key: KAFKA-21593
URL: https://issues.apache.org/jira/browse/KAFKA-21593
Project: Kafka
Issue Type: New Feature
Components: mirrormaker
Reporter: Badhusha Muhammed
h3. Background & Problem Statement
In Apache Kafka 3.x, MirrorMaker 2 (MM2) can be configured to use
{{IdentityReplicationPolicy}} to preserve original topic names across clusters
instead of prefixing them with the source cluster alias (the default behavior
in {{{}DefaultReplicationPolicy{}}}).
While {{IdentityReplicationPolicy}} works seamlessly for unidirectional
(active-passive) replication, configuring it in a bidirectional (active-active)
replication topology ({{{}Cluster A <-> Cluster B{}}}) results in an infinite
replication loop:
{noformat}
Cluster A (topic-x) ---> MM2 (A->B) ---> Cluster B (topic-x) ---> MM2 (B->A)
---> Cluster A (topic-x) ...
{noformat}
Because topic names are identical on both clusters and no origin cluster
metadata or header check is enforced by default under
{{{}IdentityReplicationPolicy{}}}, each MirrorSourceConnector treats replicated
records as newly produced local records and replicates them back to the origin
cluster indefinitely.
h3. Impact
* Unbounded message duplication
h3. Steps to Reproduce
# Configure two Kafka 3.x clusters ({{{}A{}}} and {{{}B{}}}).
# Configure MirrorMaker 2 with bidirectional flows ({{{}A->B{}}} and
{{{}B->A{}}}).
# Set {{replication.policy.class =
org.apache.kafka.connect.mirror.IdentityReplicationPolicy}} for both flows.
# Produce a single message to {{topic-x}} on Cluster {{{}A{}}}.
# Observe the message continuously cycling between Cluster {{A}} and Cluster
{{{}B{}}}.
h3. Expected Behavior / Proposed Enhancement
MirrorMaker 2 should provide a built-in mechanism (such as record header-based
origin tracking or explicit loop-detection guardrails/validation) to identify
the origin cluster of a message and prevent re-replicating records back to
their source cluster—or clearly fail/warn on unsafe bidirectional
configurations when using {{{}IdentityReplicationPolicy{}}}.
Every events that land on kafka can have a Origin header , if mirror maker is
trying to replicate to the same kafka cluseter it can drop the message in
consumer Interceptor class
{code:java}
Cluster A
|
Event [ Header {from: A} ]
|
Mirror Maker (Validate Message is coming from A ( using header ) and going to B
- Valid, Replicate )
|
Cluster B
---------------
Cluster A
|
Event [ Header {from: B} ]
|
Mirror Maker (Validate Message is coming from A ( using header ) and going to B
- Not valid, drop the record)
|
Cluster B {code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)