Skip to content

Commit

Permalink
Apply new RefMutOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jun 27, 2023
1 parent 6559242 commit c0baad7
Show file tree
Hide file tree
Showing 39 changed files with 1,876 additions and 490 deletions.
2 changes: 2 additions & 0 deletions harness/tests/test_raft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3554,6 +3554,8 @@ def new_test_learner_raft(
storage.initial_state().initialized() and not peers
), f"new_test_raft with empty peers on initialized store"

# 이렇게 하면 유일하게 깨지는 케이스가 이거.
# 얘는 참조가 비어 있어서 깨진다.
if peers and not storage.initial_state().initialized():
storage.initialize_with_conf_state(ConfState(peers, learners))

Expand Down
6 changes: 3 additions & 3 deletions src/bindings/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pyo3::{intern, prelude::*};

use raft::Config;

use utils::implement_type_conversion_v2;
use utils::reference_v2::{RefMutOwner, RustRef};
use utils::implement_type_conversion;
use utils::reference::{RefMutOwner, RustRef};

use utils::errors::Py_RaftError;

Expand All @@ -27,7 +27,7 @@ pub enum Py_Config_Mut<'p> {
RefMut(Py_Config_Ref),
}

implement_type_conversion_v2!(Config, Py_Config_Mut);
implement_type_conversion!(Config, Py_Config_Mut);

fn format_config<T: Into<Config>>(cfg: T) -> String {
let cfg: Config = cfg.into();
Expand Down
9 changes: 4 additions & 5 deletions src/bindings/get_entries_context.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use pyo3::{intern, prelude::*};
use raft::GetEntriesContext;

use utils::reference::RustRef;
use utils::reference::{RefMutOwner, RustRef};

#[pyclass(name = "GetEntriesContext")]
pub struct Py_GetEntriesContext {
pub inner: GetEntriesContext,
pub inner: RefMutOwner<GetEntriesContext>,
}

#[pyclass(name = "GetEntriesContext_Ref")]
Expand All @@ -18,7 +17,7 @@ impl Py_GetEntriesContext {
#[staticmethod]
pub fn empty(can_async: bool) -> Self {
Py_GetEntriesContext {
inner: GetEntriesContext::empty(can_async),
inner: RefMutOwner::new(GetEntriesContext::empty(can_async)),
}
}

Expand All @@ -29,7 +28,7 @@ impl Py_GetEntriesContext {
}

pub fn __repr__(&self) -> String {
format!("{:?}", self.inner)
format!("{:?}", self.inner.inner)
}

fn __getattr__(this: PyObject, py: Python, attr: &str) -> PyResult<PyObject> {
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use raftpb_bindings::message_type::{

use external_bindings::slog::Py_Logger;
use raftpb_bindings::message_type::Py_MessageType;
use utils::reference_v2::RefMutOwner;
use utils::reference::RefMutOwner;

// Global scope functions
#[pyfunction]
Expand All @@ -39,7 +39,7 @@ pub fn vote_resp_msg_type(typ: &Py_MessageType) -> Py_MessageType {
#[pyfunction]
pub fn new_conf_change_single(node_id: u64, typ: &Py_ConfChangeType) -> Py_ConfChangeSingle {
Py_ConfChangeSingle {
inner: _new_conf_change_single(node_id, typ.0),
inner: RefMutOwner::new(_new_conf_change_single(node_id, typ.0)),
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/bindings/inflights.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use pyo3::{intern, prelude::*, pyclass::CompareOp};

use raft::Inflights;

use utils::{implement_type_conversion, reference::RustRef};
use utils::{
implement_type_conversion,
reference::{RefMutOwner, RustRef},
};

#[derive(Clone)]
#[pyclass(name = "Inflights")]
pub struct Py_Inflights {
pub inner: Inflights,
pub inner: RefMutOwner<Inflights>,
}

#[derive(Clone)]
Expand All @@ -29,7 +31,7 @@ impl Py_Inflights {
#[new]
pub fn new(cap: usize) -> Self {
Py_Inflights {
inner: Inflights::new(cap),
inner: RefMutOwner::new(Inflights::new(cap)),
}
}

Expand All @@ -40,15 +42,15 @@ impl Py_Inflights {
}

pub fn __repr__(&self) -> String {
format!("{:?}", self.inner)
format!("{:?}", self.inner.inner)
}

pub fn __richcmp__(&self, py: Python, rhs: Py_Inflights_Mut, op: CompareOp) -> PyObject {
let rhs: Inflights = rhs.into();

match op {
CompareOp::Eq => (self.inner == rhs).into_py(py),
CompareOp::Ne => (self.inner != rhs).into_py(py),
CompareOp::Eq => (self.inner.inner == rhs).into_py(py),
CompareOp::Ne => (self.inner.inner != rhs).into_py(py),
_ => py.NotImplemented(),
}
}
Expand Down Expand Up @@ -84,7 +86,7 @@ impl Py_Inflights_Ref {

pub fn clone(&self) -> PyResult<Py_Inflights> {
Ok(Py_Inflights {
inner: self.inner.map_as_ref(|inner| inner.clone())?,
inner: RefMutOwner::new(self.inner.map_as_ref(|inner| inner.clone())?),
})
}

Expand Down
20 changes: 11 additions & 9 deletions src/bindings/joint_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use pyo3::{intern, prelude::*, pyclass::CompareOp, types::PySet};

use fxhash::FxHasher;
use raft::JointConfig;

use utils::{implement_type_conversion, reference::RustRef};
use utils::{
implement_type_conversion,
reference::{RefMutOwner, RustRef},
};

#[derive(Clone)]
#[pyclass(name = "JointConfig")]
pub struct Py_JointConfig {
pub inner: JointConfig,
pub inner: RefMutOwner<JointConfig>,
}

#[derive(Clone)]
Expand All @@ -32,9 +34,9 @@ impl Py_JointConfig {
#[new]
pub fn new(voters: &PySet) -> PyResult<Self> {
Ok(Py_JointConfig {
inner: JointConfig::new(
inner: RefMutOwner::new(JointConfig::new(
voters.extract::<HashSet<u64, BuildHasherDefault<FxHasher>>>()?,
),
)),
})
}

Expand All @@ -45,15 +47,15 @@ impl Py_JointConfig {
}

pub fn __repr__(&self) -> String {
format!("{:?}", self.inner)
format!("{:?}", self.inner.inner)
}

pub fn __richcmp__(&self, py: Python, rhs: Py_JointConfig_Mut, op: CompareOp) -> PyObject {
let rhs: JointConfig = rhs.into();

match op {
CompareOp::Eq => (self.inner == rhs).into_py(py),
CompareOp::Ne => (self.inner != rhs).into_py(py),
CompareOp::Eq => (self.inner.inner == rhs).into_py(py),
CompareOp::Ne => (self.inner.inner != rhs).into_py(py),
_ => py.NotImplemented(),
}
}
Expand Down Expand Up @@ -97,7 +99,7 @@ impl Py_JointConfig_Ref {

pub fn clone(&self) -> PyResult<Py_JointConfig> {
Ok(Py_JointConfig {
inner: self.inner.map_as_ref(|inner| inner.clone())?,
inner: RefMutOwner::new(self.inner.map_as_ref(|inner| inner.clone())?),
})
}

Expand Down
24 changes: 15 additions & 9 deletions src/bindings/light_ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use raftpb_bindings::{
entry::{Py_Entry, Py_Entry_Ref},
message::{Py_Message, Py_Message_Ref},
};
use utils::reference::RustRef;
use utils::unsafe_cast::make_mut;
use utils::{
reference::{RefMutOwner, RustRef},
unsafe_cast::make_mut,
};

#[pyclass(name = "LightReady")]
pub struct Py_LightReady {
pub inner: LightReady,
pub inner: RefMutOwner<LightReady>,
}

#[pyclass(name = "LightReady_Ref")]
Expand All @@ -22,7 +24,7 @@ impl Py_LightReady {
#[staticmethod]
pub fn default() -> Self {
Py_LightReady {
inner: LightReady::default(),
inner: RefMutOwner::new(LightReady::default()),
}
}

Expand All @@ -33,7 +35,7 @@ impl Py_LightReady {
}

pub fn __repr__(&self) -> String {
format!("{:?}", self.inner)
format!("{:?}", self.inner.inner)
}

fn __getattr__(this: PyObject, py: Python, attr: &str) -> PyResult<PyObject> {
Expand All @@ -58,7 +60,7 @@ impl Py_LightReady_Ref {
.committed_entries()
.iter()
.map(|entry| Py_Entry_Ref {
inner: RustRef::new(unsafe { make_mut(entry) }),
inner: RustRef::new_raw(unsafe { make_mut(entry) }),
})
.collect::<Vec<_>>()
.into_py(py)
Expand All @@ -70,7 +72,9 @@ impl Py_LightReady_Ref {
inner
.take_committed_entries()
.into_iter()
.map(|entry| Py_Entry { inner: entry })
.map(|entry| Py_Entry {
inner: RefMutOwner::new(entry),
})
.collect::<Vec<_>>()
.into_py(py)
})
Expand All @@ -82,7 +86,7 @@ impl Py_LightReady_Ref {
.messages()
.iter()
.map(|msg| Py_Message_Ref {
inner: RustRef::new(unsafe { make_mut(msg) }),
inner: RustRef::new_raw(unsafe { make_mut(msg) }),
})
.collect::<Vec<_>>()
.into_py(py)
Expand All @@ -94,7 +98,9 @@ impl Py_LightReady_Ref {
inner
.take_messages()
.into_iter()
.map(|msg| Py_Message { inner: msg })
.map(|msg| Py_Message {
inner: RefMutOwner::new(msg),
})
.collect::<Vec<_>>()
.into_py(py)
})
Expand Down
20 changes: 11 additions & 9 deletions src/bindings/majority_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use pyo3::{intern, prelude::*, pyclass::CompareOp, types::PySet};
use fxhash::FxHasher;
use raft::MajorityConfig;
use std::{collections::HashSet, hash::BuildHasherDefault};

use utils::{implement_type_conversion, reference::RustRef};
use utils::{
implement_type_conversion,
reference::{RefMutOwner, RustRef},
};

#[derive(Clone)]
#[pyclass(name = "MajorityConfig")]
pub struct Py_MajorityConfig {
pub inner: MajorityConfig,
pub inner: RefMutOwner<MajorityConfig>,
}

#[derive(Clone)]
Expand All @@ -31,9 +33,9 @@ impl Py_MajorityConfig {
#[new]
pub fn new(voters: &PySet) -> PyResult<Self> {
Ok(Py_MajorityConfig {
inner: MajorityConfig::new(
inner: RefMutOwner::new(MajorityConfig::new(
voters.extract::<HashSet<u64, BuildHasherDefault<FxHasher>>>()?,
),
)),
})
}

Expand All @@ -44,15 +46,15 @@ impl Py_MajorityConfig {
}

pub fn __repr__(&self) -> String {
format!("{:?}", self.inner)
format!("{:?}", self.inner.inner)
}

pub fn __richcmp__(&self, py: Python, rhs: Py_MajorityConfig_Mut, op: CompareOp) -> PyObject {
let rhs: MajorityConfig = rhs.into();

match op {
CompareOp::Eq => (self.inner == rhs).into_py(py),
CompareOp::Ne => (self.inner != rhs).into_py(py),
CompareOp::Eq => (self.inner.inner == rhs).into_py(py),
CompareOp::Ne => (self.inner.inner != rhs).into_py(py),
_ => py.NotImplemented(),
}
}
Expand Down Expand Up @@ -100,7 +102,7 @@ impl Py_MajorityConfig_Ref {

pub fn clone(&self) -> PyResult<Py_MajorityConfig> {
Ok(Py_MajorityConfig {
inner: self.inner.map_as_ref(|inner| inner.clone())?,
inner: RefMutOwner::new(self.inner.map_as_ref(|inner| inner.clone())?),
})
}

Expand Down
9 changes: 4 additions & 5 deletions src/bindings/peer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use pyo3::{intern, prelude::*, types::PyBytes};

use raft::raw_node::Peer;

use utils::reference::RustRef;
use utils::reference::{RefMutOwner, RustRef};

#[pyclass(name = "Peer")]
pub struct Py_Peer {
pub inner: Peer,
pub inner: RefMutOwner<Peer>,
}

#[pyclass(name = "Peer_Ref")]
Expand All @@ -19,7 +18,7 @@ impl Py_Peer {
#[new]
pub fn new() -> Self {
Py_Peer {
inner: Peer::default(),
inner: RefMutOwner::new(Peer::default()),
}
}

Expand All @@ -30,7 +29,7 @@ impl Py_Peer {
}

pub fn __repr__(&self) -> String {
format!("{:?}", self.inner)
format!("{:?}", self.inner.inner)
}

fn __getattr__(this: PyObject, py: Python, attr: &str) -> PyResult<PyObject> {
Expand Down
Loading

0 comments on commit c0baad7

Please sign in to comment.