Skip to content

Commit

Permalink
just propose from time to time
Browse files Browse the repository at this point in the history
  • Loading branch information
haaase committed Feb 3, 2025
1 parent a6ce798 commit 92f9682
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class KeyValueReplica(val uid: Uid, val votingReplicas: Set[Uid]) {
// else log(s"upkept: ${pprint(upkept)}")
val newState = publish(upkept)
maybeAnswerClient(old, newState)
// try to propose a new value in case voting is decided
maybeProposeNewValue(newState, clientState)
}
}

Expand All @@ -121,16 +123,16 @@ class KeyValueReplica(val uid: Uid, val votingReplicas: Set[Uid]) {
}
if old != changed then {
assert(changed == clientState)
maybeProposeNewValue(old, changed)
maybeProposeNewValue(clusterState, changed)
// else log(s"upkept: ${pprint(upkept)}")
}
}

private def maybeProposeNewValue(oldState: ClientState, newState: ClientState)(using LocalUid): Unit = {
private def maybeProposeNewValue(cluster: ClusterState, client: ClientState)(using LocalUid): Unit = {
// check if we are the leader and ready to handle a request
if clusterState.leader.contains(replicaId) && clusterState.phase == MultipaxosPhase.Idle then
if cluster.leader.contains(replicaId) && cluster.phase == MultipaxosPhase.Idle then
// ready to propose value
newState.firstUnansweredRequest match
client.firstUnansweredRequest match
case Some(req) =>
log(s"Proposing new value $req.")
val _ = transformCluster(_.proposeIfLeader(req))
Expand Down

0 comments on commit 92f9682

Please sign in to comment.