|
@@ -16,6 +16,7 @@ package etcdserver
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
|
+ "expvar"
|
|
|
"log"
|
|
"log"
|
|
|
"os"
|
|
"os"
|
|
|
"sort"
|
|
"sort"
|
|
@@ -31,6 +32,19 @@ import (
|
|
|
"github.com/coreos/etcd/wal/walpb"
|
|
"github.com/coreos/etcd/wal/walpb"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var (
|
|
|
|
|
+ // indirection for expvar func interface
|
|
|
|
|
+ // expvar panics when publishing duplicate name
|
|
|
|
|
+ // expvar does not support remove a registered name
|
|
|
|
|
+ // so only register a func that calls raftStatus
|
|
|
|
|
+ // and change raftStatus as we need.
|
|
|
|
|
+ raftStatus func() raft.Status
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+func init() {
|
|
|
|
|
+ expvar.Publish("raft.status", expvar.Func(func() interface{} { return raftStatus() }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
type RaftTimer interface {
|
|
type RaftTimer interface {
|
|
|
Index() uint64
|
|
Index() uint64
|
|
|
Term() uint64
|
|
Term() uint64
|
|
@@ -96,6 +110,7 @@ func startNode(cfg *ServerConfig, ids []types.ID) (id types.ID, n raft.Node, s *
|
|
|
log.Printf("etcdserver: start member %s in cluster %s", id, cfg.Cluster.ID())
|
|
log.Printf("etcdserver: start member %s in cluster %s", id, cfg.Cluster.ID())
|
|
|
s = raft.NewMemoryStorage()
|
|
s = raft.NewMemoryStorage()
|
|
|
n = raft.StartNode(uint64(id), peers, cfg.ElectionTicks, 1, s)
|
|
n = raft.StartNode(uint64(id), peers, cfg.ElectionTicks, 1, s)
|
|
|
|
|
+ raftStatus = n.Status
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -115,6 +130,7 @@ func restartNode(cfg *ServerConfig, snapshot *raftpb.Snapshot) (types.ID, raft.N
|
|
|
s.SetHardState(st)
|
|
s.SetHardState(st)
|
|
|
s.Append(ents)
|
|
s.Append(ents)
|
|
|
n := raft.RestartNode(uint64(id), cfg.ElectionTicks, 1, s, 0)
|
|
n := raft.RestartNode(uint64(id), cfg.ElectionTicks, 1, s, 0)
|
|
|
|
|
+ raftStatus = n.Status
|
|
|
return id, n, s, w
|
|
return id, n, s, w
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -156,6 +172,7 @@ func restartAsStandaloneNode(cfg *ServerConfig, snapshot *raftpb.Snapshot) (type
|
|
|
s.SetHardState(st)
|
|
s.SetHardState(st)
|
|
|
s.Append(ents)
|
|
s.Append(ents)
|
|
|
n := raft.RestartNode(uint64(id), cfg.ElectionTicks, 1, s, 0)
|
|
n := raft.RestartNode(uint64(id), cfg.ElectionTicks, 1, s, 0)
|
|
|
|
|
+ raftStatus = n.Status
|
|
|
return id, n, s, w
|
|
return id, n, s, w
|
|
|
}
|
|
}
|
|
|
|
|
|