-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
raftstorev2: add basic layout #12843
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "raftstore-v2" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[features] | ||
default = ["test-engine-kv-rocksdb", "test-engine-raft-raft-engine"] | ||
failpoints = ["raftstore/failpoints"] | ||
testexport = ["raftstore/testexport"] | ||
test-engine-kv-rocksdb = [ | ||
"raftstore/test-engine-kv-rocksdb" | ||
] | ||
test-engine-raft-raft-engine = [ | ||
"raftstore/test-engine-raft-raft-engine" | ||
] | ||
test-engines-rocksdb = [ | ||
"raftstore/test-engines-rocksdb", | ||
] | ||
test-engines-panic = [ | ||
"raftstore/test-engines-panic", | ||
] | ||
|
||
cloud-aws = ["raftstore/cloud-aws"] | ||
cloud-gcp = ["raftstore/cloud-gcp"] | ||
cloud-azure = ["raftstore/cloud-azure"] | ||
|
||
[dependencies] | ||
collections = { path = "../collections" } | ||
crossbeam = "0.8" | ||
engine_traits = { path = "../engine_traits" } | ||
error_code = { path = "../error_code" } | ||
kvproto = { git = "https://github.com/pingcap/kvproto.git" } | ||
pd_client = { path = "../pd_client" } | ||
raft = { version = "0.7.0", default-features = false, features = ["protobuf-codec"] } | ||
raft-proto = { version = "0.7.0" } | ||
raftstore = { path = "../raftstore" } | ||
slog = "2.3" | ||
smallvec = "1.4" | ||
tikv_util = { path = "../tikv_util", default-features = false } |
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 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. |
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,5 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
mod apply; | ||
mod peer; | ||
mod store; |
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,22 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use engine_traits::RaftEngine; | ||
use kvproto::metapb; | ||
use raftstore::store::Config; | ||
use slog::Logger; | ||
|
||
use crate::{raft::Peer, Result}; | ||
|
||
pub struct PeerFsm<ER: RaftEngine> { | ||
peer: Peer<ER>, | ||
} | ||
|
||
impl<ER: RaftEngine> PeerFsm<ER> { | ||
pub fn new(peer: Peer<ER>) -> Result<Self> { | ||
Ok(PeerFsm { peer }) | ||
} | ||
|
||
pub fn logger(&self) -> &Logger { | ||
self.peer.logger() | ||
} | ||
} |
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 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. |
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,19 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
//! Raftstore is the place where we implement multi-raft. | ||
//! | ||
//! The thread module of raftstore is batch-system, more check components/batch-system. | ||
//! All state machines are defined in [`fsm`] module. Everything that wrapping raft is | ||
//! implemented in [`raft`] module. And the commands are implemented in [`operation`] module. | ||
//! All state machines are expected to communicate with messages. They are defined in | ||
//! [`router`] module. | ||
|
||
#![allow(unused)] | ||
|
||
mod fsm; | ||
mod operation; | ||
mod raft; | ||
mod router; | ||
|
||
pub use raftstore::{Error, Result}; | ||
pub use router::{PeerMsg, PeerTick, StoreMsg, StoreTick}; |
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 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. |
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,7 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
mod peer; | ||
mod storage; | ||
|
||
pub use peer::Peer; | ||
pub use storage::Storage; |
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,70 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use engine_traits::RaftEngine; | ||
use kvproto::metapb; | ||
use raft::RawNode; | ||
use raftstore::store::Config; | ||
use slog::{o, Logger}; | ||
use tikv_util::{box_err, config::ReadableSize}; | ||
|
||
use super::storage::Storage; | ||
use crate::Result; | ||
|
||
/// A peer that delegates commands between state machine and raft. | ||
pub struct Peer<ER: RaftEngine> { | ||
region_id: u64, | ||
peer: metapb::Peer, | ||
raft_group: RawNode<Storage<ER>>, | ||
logger: Logger, | ||
} | ||
|
||
impl<ER: RaftEngine> Peer<ER> { | ||
pub fn new( | ||
cfg: &Config, | ||
store_id: u64, | ||
region: metapb::Region, | ||
engine: ER, | ||
logger: Logger, | ||
) -> Result<Self> { | ||
let peer = region | ||
.get_peers() | ||
.iter() | ||
.find(|p| p.get_store_id() == store_id && p.get_id() != raft::INVALID_ID); | ||
let peer = match peer { | ||
Some(p) => p, | ||
None => return Err(box_err!("no valid peer found in {:?}", region.get_peers())), | ||
}; | ||
let l = logger.new(o!("peer_id" => peer.id)); | ||
|
||
let ps = Storage::new(engine, l.clone()); | ||
|
||
let applied_index = ps.applied_index(); | ||
|
||
let raft_cfg = raft::Config { | ||
id: peer.get_id(), | ||
election_tick: cfg.raft_election_timeout_ticks, | ||
heartbeat_tick: cfg.raft_heartbeat_ticks, | ||
min_election_tick: cfg.raft_min_election_timeout_ticks, | ||
max_election_tick: cfg.raft_max_election_timeout_ticks, | ||
max_size_per_msg: cfg.raft_max_size_per_msg.0, | ||
max_inflight_msgs: cfg.raft_max_inflight_msgs, | ||
applied: applied_index, | ||
check_quorum: true, | ||
skip_bcast_commit: true, | ||
pre_vote: cfg.prevote, | ||
max_committed_size_per_ready: ReadableSize::mb(16).0, | ||
..Default::default() | ||
}; | ||
|
||
Ok(Peer { | ||
region_id: region.get_id(), | ||
peer: peer.clone(), | ||
raft_group: RawNode::new(&raft_cfg, ps, &logger)?, | ||
logger: l, | ||
}) | ||
} | ||
|
||
pub fn logger(&self) -> &Logger { | ||
&self.logger | ||
} | ||
} |
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,56 @@ | ||
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use engine_traits::RaftEngine; | ||
use raft::{ | ||
eraftpb::{Entry, Snapshot}, | ||
GetEntriesContext, RaftState, | ||
}; | ||
use slog::Logger; | ||
|
||
/// A storage for raft. | ||
pub struct Storage<ER> { | ||
engine: ER, | ||
logger: Logger, | ||
} | ||
|
||
impl<ER> Storage<ER> { | ||
pub fn new(engine: ER, logger: Logger) -> Storage<ER> { | ||
Storage { engine, logger } | ||
} | ||
|
||
pub fn applied_index(&self) -> u64 { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
impl<ER: RaftEngine> raft::Storage for Storage<ER> { | ||
fn initial_state(&self) -> raft::Result<RaftState> { | ||
unimplemented!() | ||
} | ||
|
||
fn entries( | ||
&self, | ||
low: u64, | ||
high: u64, | ||
max_size: impl Into<Option<u64>>, | ||
context: GetEntriesContext, | ||
) -> raft::Result<Vec<Entry>> { | ||
unimplemented!() | ||
} | ||
|
||
fn term(&self, idx: u64) -> raft::Result<u64> { | ||
unimplemented!() | ||
} | ||
|
||
fn first_index(&self) -> raft::Result<u64> { | ||
unimplemented!() | ||
} | ||
|
||
fn last_index(&self) -> raft::Result<u64> { | ||
unimplemented!() | ||
} | ||
|
||
fn snapshot(&self, request_index: u64, to: u64) -> raft::Result<Snapshot> { | ||
unimplemented!() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for Raft Storage, what's the expecting difference between v2 and v1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization is different.