krishvishal commented on code in PR #3092:
URL: https://github.com/apache/iggy/pull/3092#discussion_r3063731170


##########
core/consensus/src/impls.rs:
##########
@@ -1397,6 +1459,58 @@ impl<B: MessageBus, P: Pipeline<Entry = PipelineEntry>> 
VsrConsensus<B, P> {
         }
     }
 
+    /// Handle a `Commit` (heartbeat) message from the primary.
+    ///
+    /// Advances `commit_max` and resets the backup's `NormalHeartbeat` timeout
+    /// so it doesn't start a spurious view change. Returns `true` if
+    /// `commit_max` advanced, signalling the caller to run `commit_journal`.
+    ///
+    /// Only accepts heartbeats with a strictly newer monotonic timestamp
+    /// to prevent old/replayed messages from suppressing view changes.
+    ///
+    /// # Panics
+    /// - If `header.namespace` does not match this replica's namespace.
+    /// - If `header.replica` is not the primary for `header.view` (protocol 
violation).
+    pub fn handle_commit(&self, header: &iggy_binary_protocol::CommitHeader) 
-> bool {
+        assert_eq!(
+            header.namespace, self.namespace,
+            "Commit routed to wrong group"
+        );
+
+        if self.is_primary() {
+            return false;
+        }
+
+        if self.status.get() != Status::Normal {
+            return false;
+        }
+
+        if header.view != self.view.get() {
+            return false;
+        }
+
+        assert_eq!(

Review Comment:
   Done.
   
   We need peer verification to prevent this.



##########
core/consensus/src/impls.rs:
##########
@@ -1043,6 +1076,35 @@ impl<B: MessageBus, P: Pipeline<Entry = PipelineEntry>> 
VsrConsensus<B, P> {
         vec![VsrAction::RetransmitPrepares { targets }]
     }
 
+    /// Primary heartbeat: send commit point to all backups so they know
+    /// the primary is alive and can advance their own `commit_max`.
+    fn handle_commit_message_timeout(&self) -> Vec<VsrAction> {
+        if !self.is_primary() || self.status.get() != Status::Normal {
+            return Vec::new();
+        }
+
+        assert_eq!(

Review Comment:
   Done.



-- 
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]

Reply via email to