Browse Source

raft: refine comments for Configure

Yicheng Qin 11 years ago
parent
commit
ec8f493fde
3 changed files with 14 additions and 10 deletions
  1. 1 1
      etcdserver/server.go
  2. 11 7
      raft/doc.go
  3. 2 2
      raft/node.go

+ 1 - 1
etcdserver/server.go

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

+ 11 - 7
raft/doc.go

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

+ 2 - 2
raft/node.go

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