raft: refine comments for Configure

release-2.0
Yicheng Qin 2014-09-22 15:01:16 -07:00
parent dc36ae7058
commit ec8f493fde
3 changed files with 14 additions and 10 deletions

View File

@ -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")
}
}

View File

@ -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

View File

@ -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