mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
minor adjustment for weed master nodes clustering
This commit is contained in:
parent
260fcd8e1e
commit
6887e55f6a
|
@ -32,10 +32,12 @@ func NewRaftServer(r *mux.Router, version string, peers []string, httpAddr strin
|
||||||
router: r,
|
router: r,
|
||||||
}
|
}
|
||||||
|
|
||||||
//raft.SetLogLevel(2)
|
if glog.V(4) {
|
||||||
|
raft.SetLogLevel(2)
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
transporter := raft.NewHTTPTransporter("/raft")
|
transporter := raft.NewHTTPTransporter("/cluster")
|
||||||
s.raftServer, err = raft.NewServer(s.httpAddr, s.dataDir, transporter, nil, nil, "")
|
s.raftServer, err = raft.NewServer(s.httpAddr, s.dataDir, transporter, nil, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infoln(err)
|
glog.V(0).Infoln(err)
|
||||||
|
@ -46,7 +48,8 @@ func NewRaftServer(r *mux.Router, version string, peers []string, httpAddr strin
|
||||||
s.raftServer.SetElectionTimeout(1500 * time.Millisecond)
|
s.raftServer.SetElectionTimeout(1500 * time.Millisecond)
|
||||||
s.raftServer.Start()
|
s.raftServer.Start()
|
||||||
|
|
||||||
s.router.HandleFunc("/raft/join", s.joinHandler).Methods("POST")
|
s.router.HandleFunc("/cluster/join", s.joinHandler).Methods("POST")
|
||||||
|
s.router.HandleFunc("/cluster/status", s.statusHandler).Methods("GET")
|
||||||
|
|
||||||
// Join to leader if specified.
|
// Join to leader if specified.
|
||||||
if len(s.peers) > 0 {
|
if len(s.peers) > 0 {
|
||||||
|
@ -117,7 +120,7 @@ func (s *RaftServer) Join(peers []string) error {
|
||||||
for _, m := range peers {
|
for _, m := range peers {
|
||||||
glog.V(0).Infoln("Attempting to connect to:", m)
|
glog.V(0).Infoln("Attempting to connect to:", m)
|
||||||
|
|
||||||
resp, err := http.Post(fmt.Sprintf("http://%s/raft/join", strings.TrimSpace(m)), "application/json", &b)
|
resp, err := http.Post(fmt.Sprintf("http://%s/cluster/join", strings.TrimSpace(m)), "application/json", &b)
|
||||||
glog.V(0).Infoln("Post returned: ", err)
|
glog.V(0).Infoln("Post returned: ", err)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -44,3 +44,10 @@ func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request)
|
||||||
http.Error(w, "Leader unknown", http.StatusInternalServerError)
|
http.Error(w, "Leader unknown", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
m["Leader"] = s.Leader()
|
||||||
|
m["Members"] = s.Members()
|
||||||
|
writeJsonQuiet(w, r, m)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue