-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: compat07::SnapshotMeta should decode v08 SnapshotMeta
- Loading branch information
1 parent
04e4060
commit 3433126
Showing
13 changed files
with
303 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::fmt::Debug; | ||
|
||
use super::EntryPayload; | ||
use super::LogId; | ||
use crate::compat::Upgrade; | ||
|
||
/// v0.7 compatible Entry. | ||
/// | ||
/// To load from either v0.7 or the latest format data and upgrade it to the latest type: | ||
/// ```ignore | ||
/// let x:openraft::Entry = serde_json::from_slice::<compat07::Entry>(&serialized_bytes)?.upgrade() | ||
/// ``` | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
#[serde(bound = "")] | ||
pub struct Entry<C: crate::RaftTypeConfig> { | ||
pub log_id: LogId, | ||
pub payload: EntryPayload<C>, | ||
} | ||
|
||
impl<C> Upgrade<crate::Entry<C>> for or07::Entry<C::D> | ||
where | ||
C: crate::RaftTypeConfig<NodeId = u64, Node = crate::EmptyNode>, | ||
<C as crate::RaftTypeConfig>::D: or07::AppData + Debug, | ||
{ | ||
fn upgrade(self) -> crate::Entry<C> { | ||
let log_id = self.log_id.upgrade(); | ||
let payload = self.payload.upgrade(); | ||
crate::Entry { log_id, payload } | ||
} | ||
} | ||
|
||
impl<C: crate::RaftTypeConfig<NodeId = u64, Node = crate::EmptyNode>> Upgrade<crate::Entry<C>> for Entry<C> { | ||
fn upgrade(self) -> crate::Entry<C> { | ||
crate::Entry { | ||
log_id: self.log_id.upgrade(), | ||
payload: self.payload.upgrade(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::fmt::Debug; | ||
|
||
use super::Membership; | ||
use crate::compat::Upgrade; | ||
|
||
/// v0.7 compatible EntryPayload. | ||
/// | ||
/// To load from either v0.7 or the latest format data and upgrade it to the latest type: | ||
/// ```ignore | ||
/// let x:openraft::EntryPayload = serde_json::from_slice::<compat07::EntryPayload>(&serialized_bytes)?.upgrade() | ||
/// ``` | ||
#[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
pub enum EntryPayload<C: crate::RaftTypeConfig> { | ||
Blank, | ||
Normal(C::D), | ||
Membership(Membership), | ||
} | ||
|
||
impl<C> Upgrade<crate::EntryPayload<C>> for or07::EntryPayload<C::D> | ||
where | ||
C: crate::RaftTypeConfig<NodeId = u64, Node = crate::EmptyNode>, | ||
<C as crate::RaftTypeConfig>::D: or07::AppData + Debug, | ||
{ | ||
fn upgrade(self) -> crate::EntryPayload<C> { | ||
match self { | ||
Self::Blank => crate::EntryPayload::Blank, | ||
Self::Membership(m) => crate::EntryPayload::Membership(m.upgrade()), | ||
Self::Normal(d) => crate::EntryPayload::Normal(d), | ||
} | ||
} | ||
} | ||
|
||
impl<C: crate::RaftTypeConfig<NodeId = u64, Node = crate::EmptyNode>> Upgrade<crate::EntryPayload<C>> | ||
for EntryPayload<C> | ||
{ | ||
fn upgrade(self) -> crate::EntryPayload<C> { | ||
match self { | ||
EntryPayload::Blank => crate::EntryPayload::Blank, | ||
EntryPayload::Normal(d) => crate::EntryPayload::Normal(d), | ||
EntryPayload::Membership(m) => crate::EntryPayload::Membership(m.upgrade()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::compat::Compat; | ||
use crate::compat::Upgrade; | ||
|
||
/// v0.7 compatible LogId. | ||
/// | ||
/// To load from either v0.7 or the latest format data and upgrade it to the latest type: | ||
/// ```ignore | ||
/// let x:openraft::LogId = serde_json::from_slice::<compat07::LogId>(&serialized_bytes)?.upgrade() | ||
/// ``` | ||
pub type LogId = Compat<or07::LogId, crate::LogId<u64>>; | ||
|
||
impl Upgrade<crate::LogId<u64>> for or07::LogId { | ||
fn upgrade(self) -> crate::LogId<u64> { | ||
let committed_leader_id = crate::CommittedLeaderId::new(self.term, 0); | ||
crate::LogId::new(committed_leader_id, self.index) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::collections::BTreeMap; | ||
use std::collections::BTreeSet; | ||
use std::fmt::Debug; | ||
|
||
use crate::compat::Upgrade; | ||
|
||
/// v0.7 compatible Membership. | ||
/// | ||
/// To load from either v0.7 or the latest format data and upgrade it to the latest type: | ||
/// ```ignore | ||
/// let x:openraft::Membership = serde_json::from_slice::<compat07::Membership>(&serialized_bytes)?.upgrade() | ||
/// ``` | ||
#[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
pub struct Membership { | ||
pub configs: Vec<BTreeSet<u64>>, | ||
pub nodes: Option<BTreeMap<u64, crate::EmptyNode>>, | ||
pub all_nodes: Option<BTreeSet<u64>>, | ||
} | ||
|
||
impl Upgrade<crate::Membership<u64, crate::EmptyNode>> for or07::Membership { | ||
fn upgrade(self) -> crate::Membership<u64, crate::EmptyNode> { | ||
let configs = self.get_configs().clone(); | ||
let nodes = self.all_nodes().iter().map(|nid| (*nid, crate::EmptyNode::new())).collect::<BTreeMap<_, _>>(); | ||
crate::Membership::new(configs, nodes) | ||
} | ||
} | ||
|
||
impl Upgrade<crate::Membership<u64, crate::EmptyNode>> for Membership { | ||
fn upgrade(self) -> crate::Membership<u64, crate::EmptyNode> { | ||
if let Some(ns) = self.nodes { | ||
crate::Membership::new(self.configs, ns) | ||
} else { | ||
crate::Membership::new(self.configs, self.all_nodes.unwrap()) | ||
} | ||
} | ||
} |
Oops, something went wrong.