Skip to content

Commit

Permalink
Moving to Cap'n proto and Replica
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hobden committed Mar 28, 2015
1 parent 34d95c8 commit 95e4d15
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 577 deletions.
19 changes: 13 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,46 @@ use rustc_serialize::{Encodable, Decodable};
// Data structures.
use store::Store;
use node::RaftNode;
use state_machine::StateMachine;

/// This is the primary interface with a `RaftNode` in the cluster. Creating a new `Raft` client
/// will, for now, automatically spawn a `RaftNode` with the relevant parameters. This may be
/// changed in the future. This is based on the assumption that any consuming appliaction
/// interacting with a Raft cluster will also be a participant.
pub struct Raft<T, S>
pub struct Raft<T, S, M>
where T: Encodable + Decodable + Clone + Debug + Send + 'static,
S: Store + Debug
S: Store + Debug,
M: StateMachine
{
current_leader: Option<SocketAddr>,
related_raftnode: SocketAddr, // Not RaftNode because we move that to another thread.
cluster_members: HashSet<SocketAddr>,
// TODO: Can we get rid of these?
phantom_store: PhantomData<S>,
phantom_type: PhantomData<T>,
phantom_state_machine: PhantomData<M>,
}

impl<T, S> Raft<T,S>
impl<T, S, M> Raft<T, S, M>
where T: Encodable + Decodable + Clone + Debug + Send + 'static,
S: Store + Debug {
S: Store + Debug,
M: StateMachine {
/// Create a new `Raft` client that has a cooresponding `RaftNode` attached. Note that this
/// `Raft` may not necessarily interact with the cooreponding `RaftNode`, it will interact with
/// the `Leader` of a cluster in almost all cases.
pub fn new(address: SocketAddr, cluster_members: HashSet<SocketAddr>, store: S) -> Raft<T, S> {
pub fn new(address: SocketAddr, cluster_members: HashSet<SocketAddr>, store: S,
state_machine: M) -> Raft<T, S, M>
{
// TODO: How do we know if this panics?
RaftNode::<T, S>::spawn(address, cluster_members.clone(), store);
RaftNode::<T, S, M>::spawn(address, cluster_members.clone(), store, state_machine);
// Store relevant information.
Raft {
current_leader: None,
related_raftnode: address,
cluster_members: cluster_members,
phantom_store: PhantomData,
phantom_type: PhantomData,
phantom_state_machine: PhantomData,
}
}
pub fn append(entries: Vec<T>) -> io::Result<()> {
Expand Down
8 changes: 7 additions & 1 deletion src/messages.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ struct RequestVoteResponse {
}

struct ClientRequest {
entry @0 :Data;
union {
entry @0 :Data;
# An entry to append.

die @1 :Text;
# Die order, include a reason when killing. Mostly for testing.
}
}

struct ClientResponse {
Expand Down
Loading

0 comments on commit 95e4d15

Please sign in to comment.