Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logへの追加処理を途中でキャンセルしない #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/issue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#[cfg(test)]
mod test {
use crate::test_dsl::*;
use crate::test_dsl::dsl::*;

#[test]
#[rustfmt::skip]
fn issue_append_cancel() {
use Command::*;
use LogEntry::*;

let a = NodeName(0);
let b = NodeName(1);
let c = NodeName(2);
let (mut service, _cluster) = build_complete_graph(&[a, b, c]);

interpret(
&vec![
RunAllUntilStabilize,
Timeout(a),
RunAllUntilStabilize,

// aがリーダーになっていることを確認する
Check(a, Pred::IsLeader),
Check(b, Pred::IsFollower),
Check(c, Pred::IsFollower),

// a-x->c
RecvBan(c, a),

Propose(a), Propose(a), Propose(a),
Heartbeat(a),

Step(a), Step(a), Step(a), Step(b),
Step(a), Step(a), Step(a), Step(b),

// bで
// history: 22
// log : 2222
// の形にする。
Dump(b),

// aを孤立させて
RecvBan(b, a),

// bとcをタイムアウトさせ
Timeout(b), Timeout(c),
RunAllUntilStabilize,
Timeout(b),
RunAllUntilStabilize,

// bをリーダーにする
Check(b, Pred::IsLeader),
Check(c, Pred::IsFollower),

// bは以下のようになっている
// history: 224
// log : 2242
Dump(b),

// すなわち、bはInconsistentである。
// この状態で再起動するとクラッシュする。
Check(b, Pred::RawLogIs(0, 0, vec![Noop(2), Com(2), Noop(4), Com(2)])),
Check(b, Pred::Not(Box::new(Pred::LogTermConsistency))),
],
&mut service,
);
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod message;
pub mod metrics;
pub mod node;
pub mod test_dsl;
pub mod issue;

mod error;
mod io;
Expand Down
2 changes: 1 addition & 1 deletion src/test_dsl/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::fmt;
/// DSL中でノード名を表すために用いる構造体
/// 現時点ではu8のnewtypeに過ぎない
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub struct NodeName(u8);
pub struct NodeName(pub u8);

impl fmt::Display for NodeName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
13 changes: 9 additions & 4 deletions src/test_dsl/impl_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl Io for TestIo {
}
self.snapshot = Some(prefix);

LogSaver(SaveMode::SnapshotSave, self.node_id.clone())
LogSaver(SaveMode::SnapshotSave, self.node_id.clone(), 2)
}
fn save_log_suffix(&mut self, suffix: &LogSuffix) -> Self::SaveLog {
self.io_events.push(IOEvent::SaveSuffix);
Expand All @@ -359,7 +359,7 @@ impl Io for TestIo {
self.rawlog = Some(suffix.clone());
}

LogSaver(SaveMode::RawLogSave, self.node_id.clone())
LogSaver(SaveMode::RawLogSave, self.node_id.clone(), 2)
}

type LoadLog = LogLoader;
Expand Down Expand Up @@ -518,12 +518,17 @@ enum SaveMode {
}

/// ログ保存を表現するためのfuture(の実体)
pub struct LogSaver(SaveMode, pub NodeId);
pub struct LogSaver(SaveMode, pub NodeId, u8);
impl Future for LogSaver {
type Item = ();
type Error = Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
Ok(Async::Ready(()))
if self.2 == 0 {
Ok(Async::Ready(()))
} else {
self.2 -= 1;
Ok(Async::NotReady)
}
}
}

Expand Down