Upgrade to Pro — share decks privately, control downloads, hide ads and more …

etcd over gossip

etcd over gossip

Strongly consistent semantics in a weakly consistent world.

Peter Bourgon

May 09, 2016
Tweet

More Decks by Peter Bourgon

Other Decks in Programming

Transcript

  1. weaveworks- Your application Router :6379 Gossip Receiver Gossip Sender Gossip

    Data GossipUnicast(dst Peer, m Msg) GossipBroadcast(m Msg) OnGossip(src Peer, m Msg) Peers() []Peer
  2. weaveworks- type Proposer interface { ProposeEntry(Entry) error ProposeConfChange(ConfChange) error }

    type CommitReceiver interface { ReceiveCommit(Entry) } type ErrorReceiver interface { ReceiveError(error) }
  3. weaveworks- type Proposer interface { ProposeEntry(Entry) error ProposeConfChange(ConfChange) error }

    type CommitReceiver interface { ReceiveCommit(Entry) } type ErrorReceiver interface { ReceiveError(error) } func main() { n := newRaftNode(...) s := newStore(...) a := newAPI(...) n.commitReceiver = s n.errorReceiver = s a.store = s a.proposer = n // ... }
  4. weaveworks- type Proposer interface { ProposeEntry(Entry) error ProposeConfChange(ConfChange) error }

    type CommitReceiver interface { ReceiveCommit(Entry) } type ErrorReceiver interface { ReceiveError(error) } func main() { n := newRaftNode(...) s := newStore(...) a := newAPI(...) n.commitReceiver = s n.errorReceiver = s a.store = s a.proposer = n // ... } ✕
  5. weaveworks- func main() { var ( entryc = make(chan entry)

    confchangec = make(chan confchange) commitc = make(chan entry) errorc = make(chan error) ) n := newRaftNode(entryc, confchangec, commitc, errorc, ...) s := newStore(commitc, ...) a := newAPI(entryc, ...) // ... }
  6. weaveworks- type raftNode struct { node raft.Node entryc <-chan entry

    confchangec <-chan confchange commitc chan<- entry errorc chan<- error // storage? // transport? // ... quitc chan struct{} }
  7. weaveworks- type PacketConn interface { ReadFrom(b []byte) (n int, addr

    Addr, err error) WriteTo(b []byte, addr Addr) (n int, err error) Close() error LocalAddr() Addr SetDeadline(t time.Time) error SetReadDeadline(t time.Time) error SetWriteDeadline(t time.Time) error }
  8. weaveworks- type PacketConn interface { ReadFrom(b []byte) (n int, addr

    Addr, err error) WriteTo(b []byte, addr Addr) (n int, err error) Close() error LocalAddr() Addr SetDeadline(t time.Time) error SetReadDeadline(t time.Time) error SetWriteDeadline(t time.Time) error }
  9. weaveworks- Router GossipUnicast(dst Peer, m Msg) GossipBroadcast(m Msg) OnGossip(src Peer,

    m Msg) Adapter? ReadFrom(b []byte) ... WriteTo(b []byte, addr Addr) ...
  10. weaveworks- Router GossipUnicast(dst Peer, m Msg) GossipBroadcast(m Msg) OnGossip(src Peer,

    m Msg) meshconn.Peer ReadFrom(b []byte) ... WriteTo(b []byte, addr Addr) ...
  11. weaveworks- Router GossipUnicast(dst Peer, m Msg) GossipBroadcast(m Msg) OnGossip(src Peer,

    m Msg) meshconn.Peer ReadFrom(b []byte) ... WriteTo(b []byte, addr Addr) ... incomingc chan Msg outgoingc chan Msg
  12. weaveworks- type raftNode struct { node raft.Node entryc <-chan entry

    confchangec <-chan confchange commitc chan<- entry errorc chan<- error // storage? incoming <-chan msg // transport outgoing chan<- msg // transport // ... quitc chan struct{} }
  13. weaveworks- for { select { case <-ticker: c.node.Tick() case r

    := <-c.node.Ready(): // save entries // send messages // publish entries // advance case <-c.quitc: return } }
  14. weaveworks- for { select { case <-ticker: c.node.Tick() case r

    := <-c.node.Ready(): // save entries // send messages // publish entries // advance case <-c.quitc: return } }
  15. weaveworks- case r := <-c.node.Ready(): if !c.readySave(r) { return }

    c.readySend(r) if !c.readyApply(r) { return } c.readyAdvance()
  16. weaveworks- type raftNode struct { node raft.Node incomingc <-chan raftpb.Message

    // from the transport unreachablec <-chan nodeID // from the transport confchangec <-chan raftpb.ConfChange // from the mesh proposalc <-chan []byte // from the state machine outgoingc chan<- raftpb.Message // to the transport entryc chan<- raftpb.Entry // to the demuxer snapshotc chan<- raftpb.Snapshot // to the state machine removedc chan<- struct{} // to calling context stopc chan struct{} // from the user terminatedc chan struct{} // to the user // storage? }
  17. weaveworks- type raftNode struct { node raft.Node incomingc <-chan raftpb.Message

    // from the transport unreachablec <-chan nodeID // from the transport confchangec <-chan raftpb.ConfChange // from the mesh proposalc <-chan []byte // from the state machine outgoingc chan<- raftpb.Message // to the transport entryc chan<- raftpb.Entry // to the demuxer snapshotc chan<- raftpb.Snapshot // to the state machine removedc chan<- struct{} // to calling context stopc chan struct{} // from the user terminatedc chan struct{} // to the user // storage? }
  18. weaveworks- type raftNode struct { node raft.Node incomingc <-chan raftpb.Message

    // from the transport unreachablec <-chan nodeID // from the transport confchangec <-chan raftpb.ConfChange // from the mesh proposalc <-chan []byte // from the state machine outgoingc chan<- raftpb.Message // to the transport entryc chan<- raftpb.Entry // to the demuxer snapshotc chan<- raftpb.Snapshot // to the state machine removedc chan<- struct{} // to calling context stopc chan struct{} // from the user terminatedc chan struct{} // to the user // storage? }
  19. weaveworks- type raftNode struct { node raft.Node incomingc <-chan raftpb.Message

    // from the transport unreachablec <-chan nodeID // from the transport confchangec <-chan raftpb.ConfChange // from the mesh proposalc <-chan []byte // from the state machine outgoingc chan<- raftpb.Message // to the transport entryc chan<- raftpb.Entry // to the demuxer snapshotc chan<- raftpb.Snapshot // to the state machine removedc chan<- struct{} // to calling context stopc chan struct{} // from the user terminatedc chan struct{} // to the user // storage? }
  20. weaveworks- Transport Router meshconn Controller incomingc outgoingc raft.Node Step ProposeConfChange

    entryc Demuxer Normal entries ConfChange entries unreachablec ReportUnreachable confchangec
  21. weaveworks- Transport Router meshconn Controller incomingc outgoingc raft.Node Step ProposeConfChange

    entryc Demuxer Normal entries ConfChange entries unreachablec ReportUnreachable confchangec
  22. weaveworks- Transport Router Membership meshconn Controller incomingc outgoingc raft.Node Step

    ProposeConfChange entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  23. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  24. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  25. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange ProposeEntry proposalc snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  26. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange ProposeEntry proposalc snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  27. weaveworks- type raftNode struct { node raft.Node incomingc <-chan raftpb.Message

    // from the transport unreachablec <-chan nodeID // from the transport confchangec <-chan raftpb.ConfChange // from the mesh proposalc <-chan []byte // from the state machine outgoingc chan<- raftpb.Message // to the transport entryc chan<- raftpb.Entry // to the demuxer snapshotc chan<- raftpb.Snapshot // to the state machine removedc chan<- struct{} // to calling context stopc chan struct{} // from the user terminatedc chan struct{} // to the user // storage? }
  28. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange ProposeEntry proposalc snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  29. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange ProposeEntry proposalc snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  30. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange ProposeEntry proposalc snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable
  31. weaveworks- Transport Router Membership meshconn Controller State incomingc outgoingc raft.Node

    Step ProposeConfChange ProposeEntry proposalc snapshotc entryc Demuxer Normal entries ConfChange entries unreachablec confchangec ReportUnreachable