Skip to content

Commit 95f012c

Browse files
committed
dont return quorum if requester isnt involved
1 parent 79572e6 commit 95f012c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lighthouse.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ impl LighthouseService for Arc<Lighthouse> {
444444
.requester
445445
.ok_or_else(|| return Status::invalid_argument("missing requester"))?;
446446

447+
let requester_id = requester.replica_id.clone();
448+
let requester_copy = requester.clone();
447449
info!("got quorum request for replica {}", &requester.replica_id);
448450

449451
let mut rx = {
@@ -471,7 +473,28 @@ impl LighthouseService for Arc<Lighthouse> {
471473
rx
472474
};
473475

474-
let quorum = rx.recv().await.map_err(|e| Status::from_error(e.into()))?;
476+
let quorum = loop {
477+
let current_quorum = rx.recv().await.map_err(|e| Status::from_error(e.into()))?;
478+
479+
if current_quorum
480+
.participants
481+
.iter()
482+
.any(|p| p.replica_id == requester_id)
483+
{
484+
break current_quorum;
485+
}
486+
487+
// Only continue the loop if the replica is not in the quorum
488+
let mut state = self.state.lock().await;
489+
state.participants.insert(
490+
requester_id.clone(),
491+
QuorumMemberDetails {
492+
joined: Instant::now(),
493+
member: requester_copy.clone(),
494+
},
495+
);
496+
info!("Replica {} not in quorum, retrying", requester_id);
497+
};
475498

476499
let reply = LighthouseQuorumResponse {
477500
quorum: Some(quorum),

0 commit comments

Comments
 (0)