raft: refine comments for Configure

This commit is contained in:
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) s.Node.RemoveNode(r.NodeID)
default: default:
// This should never be reached // 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) n.Propose(ctx, data)
To add or remove node in a cluster, serialize the data for configuration change To add or remove node in a cluster, build Config struct and call:
into a byte slice and call:
n.Configure(ctx, data) n.Configure(ctx, conf)
For the safety consideration, one configuration should include at most one node After configuration is committed, you should apply it to node through:
change, which is applied through:
n.AddNode(id) var conf raftpb.Config
n.RemoveNode(id) conf.Unmarshal(data)
switch conf.Type {
case raftpb.ConfigAddNode:
n.AddNode(conf.ID)
case raftpb.ConfigRemoveNode:
n.RemoveNode(conf.ID)
}
*/ */
package raft package raft

View File

@ -80,8 +80,8 @@ type Node interface {
Campaign(ctx context.Context) error Campaign(ctx context.Context) error
// Propose proposes that data be appended to the log. // Propose proposes that data be appended to the log.
Propose(ctx context.Context, data []byte) error 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 proposes config change. At most one config can be in the process of going through consensus.
// Configure doesn't perform config change. // Application needs to call AddNode/RemoveNode when applying EntryConfig type entry.
Configure(ctx context.Context, conf pb.Config) error 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 advances the state machine using the given message. ctx.Err() will be returned, if any.
Step(ctx context.Context, msg pb.Message) error Step(ctx context.Context, msg pb.Message) error