From ec8f493fde6b227af6d287a25b0a9ed87ee7f890 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Mon, 22 Sep 2014 15:01:16 -0700 Subject: [PATCH] raft: refine comments for Configure --- etcdserver/server.go | 2 +- raft/doc.go | 18 +++++++++++------- raft/node.go | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/etcdserver/server.go b/etcdserver/server.go index c19d62356..0c75b18af 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -349,7 +349,7 @@ func (s *EtcdServer) applyConfig(r raftpb.Config) { s.Node.RemoveNode(r.NodeID) default: // This should never be reached - panic("unsupported config type") + panic("unexpected config type") } } diff --git a/raft/doc.go b/raft/doc.go index 53a42f1f7..5a13a87b9 100644 --- a/raft/doc.go +++ b/raft/doc.go @@ -61,16 +61,20 @@ data, serialize it into a byte slice and call: n.Propose(ctx, data) -To add or remove node in a cluster, serialize the data for configuration change -into a byte slice and call: +To add or remove node in a cluster, build Config struct and call: - n.Configure(ctx, data) + n.Configure(ctx, conf) -For the safety consideration, one configuration should include at most one node -change, which is applied through: +After configuration is committed, you should apply it to node through: - n.AddNode(id) - n.RemoveNode(id) + var conf raftpb.Config + conf.Unmarshal(data) + switch conf.Type { + case raftpb.ConfigAddNode: + n.AddNode(conf.ID) + case raftpb.ConfigRemoveNode: + n.RemoveNode(conf.ID) + } */ package raft diff --git a/raft/node.go b/raft/node.go index 46001b1a3..a8c6385e7 100644 --- a/raft/node.go +++ b/raft/node.go @@ -80,8 +80,8 @@ type Node interface { Campaign(ctx context.Context) error // Propose proposes that data be appended to the log. Propose(ctx context.Context, data []byte) error - // Configure proposes config change. Only one config can be in the process of going through consensus at a time. - // Configure doesn't perform config change. + // Configure proposes config change. At most one config can be in the process of going through consensus. + // Application needs to call AddNode/RemoveNode when applying EntryConfig type entry. Configure(ctx context.Context, conf pb.Config) error // Step advances the state machine using the given message. ctx.Err() will be returned, if any. Step(ctx context.Context, msg pb.Message) error