From c6fe0caadc8a9f485553e7f8e7afc40106547c2b Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Sat, 17 Jun 2023 18:59:46 -0700 Subject: [PATCH] Broken finalize view. --- src/ir/record.rs | 10 ++++++---- src/ir/replica.rs | 14 +++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ir/record.rs b/src/ir/record.rs index 7d5ae7e..3d30bd1 100644 --- a/src/ir/record.rs +++ b/src/ir/record.rs @@ -1,17 +1,19 @@ -use super::{OpId, ReplicaUpcalls}; +use super::{OpId, ReplicaUpcalls, ViewNumber}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::{collections::HashMap, fmt::Debug}; #[derive(Copy, Clone, Serialize, Deserialize)] pub enum State { - Finalized, + /// Op was finalized within the given view. + Finalized(ViewNumber), + /// Op hasn't been finalized yet Tentative, } impl Debug for State { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { - Self::Finalized => "Fin", + Self::Finalized(view) => write!(f, "Fin({view:?}"), Self::Tentative => "Tnt", }) } @@ -23,7 +25,7 @@ impl State { } pub fn is_finalized(&self) -> bool { - matches!(self, Self::Finalized) + matches!(self, Self::Finalized(_)) } } diff --git a/src/ir/replica.rs b/src/ir/replica.rs index f8ae9a2..158a4b9 100644 --- a/src/ir/replica.rs +++ b/src/ir/replica.rs @@ -288,7 +288,7 @@ impl>> Replica { let mut sync = self.inner.sync.lock().unwrap(); if sync.status.is_normal() { if let Some(entry) = sync.record.consensus.get_mut(&op_id) { - entry.state = RecordEntryState::Finalized; + entry.state = RecordEntryState::Finalized(sync.view.number); entry.result = result; return Some(Message::::Confirm(Confirm { op_id, @@ -344,6 +344,10 @@ impl>> Replica { if matching.clone().count() >= threshold { eprintln!("DOING VIEW CHANGE"); + sync.changed_view_recently = true; + sync.status = Status::Normal; + sync.view.number = msg_view_number; + sync.latest_normal_view = msg_view_number; { let latest_normal_view = sync.latest_normal_view.max( matching @@ -380,7 +384,7 @@ impl>> Replica { } Entry::Occupied(mut occupied) => { if entry.state.is_finalized() { - occupied.get_mut().state = RecordEntryState::Finalized; + occupied.get_mut().state = RecordEntryState::Finalized(sync.view.number); } } } @@ -455,17 +459,13 @@ impl>> Replica { RecordConsensusEntry { op: entry.op.clone(), result: result.clone(), - state: RecordEntryState::Finalized, + state: RecordEntryState::Finalized(sync.view.number), }, ); } sync.record = R; } - sync.changed_view_recently = true; - sync.status = Status::Normal; - sync.view.number = msg_view_number; - sync.latest_normal_view = msg_view_number; self.persist_view_info(&*sync); for (index, address) in &sync.view.membership { if index == self.index {