Browse Source

raft: return active config in Status

This is useful for debug purposes, and more so once we support joint
quorums.
Tobias Schottdorf 6 years ago
parent
commit
7ce934cbec
2 changed files with 10 additions and 0 deletions
  1. 8 0
      raft/rawnode_test.go
  2. 2 0
      raft/status.go

+ 8 - 0
raft/rawnode_test.go

@@ -21,6 +21,7 @@ import (
 	"reflect"
 	"reflect"
 	"testing"
 	"testing"
 
 
+	"go.etcd.io/etcd/raft/quorum"
 	"go.etcd.io/etcd/raft/raftpb"
 	"go.etcd.io/etcd/raft/raftpb"
 	"go.etcd.io/etcd/raft/tracker"
 	"go.etcd.io/etcd/raft/tracker"
 )
 )
@@ -460,6 +461,13 @@ func TestRawNodeStatus(t *testing.T) {
 	if exp, act := *rn.raft.prs.Progress[1], status.Progress[1]; !reflect.DeepEqual(exp, act) {
 	if exp, act := *rn.raft.prs.Progress[1], status.Progress[1]; !reflect.DeepEqual(exp, act) {
 		t.Fatalf("want: %+v\ngot:  %+v", exp, act)
 		t.Fatalf("want: %+v\ngot:  %+v", exp, act)
 	}
 	}
+	expCfg := tracker.Config{Voters: quorum.JointConfig{
+		quorum.MajorityConfig{1: {}},
+		nil,
+	}}
+	if !reflect.DeepEqual(expCfg, status.Config) {
+		t.Fatalf("want: %+v\ngot:  %+v", expCfg, status.Config)
+	}
 }
 }
 
 
 // TestRawNodeCommitPaginationAfterRestart is the RawNode version of
 // TestRawNodeCommitPaginationAfterRestart is the RawNode version of

+ 2 - 0
raft/status.go

@@ -28,6 +28,7 @@ type Status struct {
 	SoftState
 	SoftState
 
 
 	Applied  uint64
 	Applied  uint64
+	Config   tracker.Config
 	Progress map[uint64]tracker.Progress
 	Progress map[uint64]tracker.Progress
 
 
 	LeadTransferee uint64
 	LeadTransferee uint64
@@ -54,6 +55,7 @@ func getStatusWithoutProgress(r *raft) Status {
 	s.HardState = r.hardState()
 	s.HardState = r.hardState()
 	s.SoftState = *r.softState()
 	s.SoftState = *r.softState()
 	s.Applied = r.raftLog.applied
 	s.Applied = r.raftLog.applied
+	s.Config = r.prs.Config.Clone()
 	return s
 	return s
 }
 }