docs/agent_guides/streaming-system/replication/replicate.md
Milvus supports multi-cluster WAL replication via a star topology: one PRIMARY cluster (origin of all writes) and one or more SECONDARY clusters (replicas receiving WAL messages). Replication operates per-PChannel.
ReplicateConfiguration (protobuf), stored in the WALCheckpoint and updated atomically via AlterReplicateConfig broadcast message (see Cluster Messages), contains a Clusters list (ClusterID, PChannels ordered list, ConnectionParam) and a CrossClusterTopology edge list (SourceClusterID → TargetClusterID). Only star topology is supported: one PRIMARY center node (out-degree=N-1, in-degree=0) and N-1 SECONDARY leaf nodes (in-degree=1, out-degree=0). All clusters must have the same number of PChannels; cross-cluster PChannel mapping is by index position: Source.PChannels[i] → Target.PChannels[i].
ReplicateCheckpoint. Self-controlled messages (TimeTick, CreateSegment, Flush) and messages carrying the Unreplicable (_ur) property are skipped.CreateReplicateStream gRPC bidirectional stream: sends each message with its original MessageID, Properties, and Payload, along with the SourceClusterID.Some DDL/control messages cannot be safely replayed on a SECONDARY until their replay contract is deterministic across clusters. Producers mark those concrete WAL messages with the Unreplicable (_ur) message property. The CDC sender treats them like ignored messages and advances replication progress without sending them. The SECONDARY replicate interceptor also ignores replicated messages that carry _ur, which protects mixed-version or already-forwarded traffic.
This is a message property, not a static MessageType rule. Future support for one of these DDLs should stop setting _ur on newly generated messages; old WAL messages that already carry _ur remain skipped for rolling-upgrade compatibility.
The secondary maintains a ReplicateCheckpoint per PChannel: {ClusterID, PChannel, MessageID, TimeTick}.
TimeTick ≤ checkpoint.TimeTick are ignored. Txn body messages for the current in-flight transaction keep the equality case for the txn helper to deduplicate by message ID, since all messages within a transaction share the same TimeTick.The checkpoint is persisted in the WALCheckpoint and can be queried by the primary via GetReplicateInfo to resume replication from the correct position after restart.
On WAL open, RecoverReplicateManager loads the ReplicateConfig and ReplicateCheckpoint from the RecoveryStorage snapshot. For SECONDARY clusters, it also recovers in-progress transaction state from the TxnBuffer (uncommitted replicated transactions), so that the secondary can continue receiving body/commit messages for the interrupted transaction.
All topology changes are triggered by AlterReplicateConfig broadcast messages, which require ExclusiveCluster resource lock — acting as a global barrier across all PChannels.
AlterReplicateConfig message. Existing cluster attributes are immutable.SwitchReplicateMode drops the secondary state. On the new primary, it creates a new secondary state pointing to the new source.AlterReplicateConfig message and cleans up the replicate PChannel metadata from etcd.pkg/util/replicateutil/ — ConfigHelper, ConfigValidator, role definitionsinternal/streamingcoord/server/balancer/ — ChannelManager replication config persistence, AvailableInReplication, CDC task creationinternal/streamingnode/server/wal/interceptors/replicate/ — Replicate interceptor, ReplicateManager, secondary stateinternal/cdc/replication/ — CDC ChannelReplicator, ReplicateStreamClient