aboutsummaryrefslogtreecommitdiff
path: root/weed/server/raft_server_handlers.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-06-12 01:54:09 -0700
committerChris Lu <chris.lu@gmail.com>2018-06-12 01:54:09 -0700
commit03f50180f3f6bfca5ae61fab0fa1c3b1db939e05 (patch)
tree35a236730feafdc8d651d67f996593ac6ffe3ffe /weed/server/raft_server_handlers.go
parent69b4f9383086f71a04a28d358d1ccca1cc149ff2 (diff)
downloadseaweedfs-03f50180f3f6bfca5ae61fab0fa1c3b1db939e05.tar.xz
seaweedfs-03f50180f3f6bfca5ae61fab0fa1c3b1db939e05.zip
simplifying the leader election by raft
fixing https://github.com/chrislusf/seaweedfs/issues/629
Diffstat (limited to 'weed/server/raft_server_handlers.go')
-rw-r--r--weed/server/raft_server_handlers.go45
1 files changed, 0 insertions, 45 deletions
diff --git a/weed/server/raft_server_handlers.go b/weed/server/raft_server_handlers.go
index 0a794ce6c..c91ab0407 100644
--- a/weed/server/raft_server_handlers.go
+++ b/weed/server/raft_server_handlers.go
@@ -1,59 +1,14 @@
package weed_server
import (
- "encoding/json"
- "io/ioutil"
"net/http"
- "strings"
-
- "github.com/chrislusf/raft"
- "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/operation"
)
-// Handles incoming RAFT joins.
-func (s *RaftServer) joinHandler(w http.ResponseWriter, req *http.Request) {
- glog.V(0).Infoln("Processing incoming join. Current Leader", s.raftServer.Leader(), "Self", s.raftServer.Name(), "Peers", s.raftServer.Peers())
- command := &raft.DefaultJoinCommand{}
-
- commandText, _ := ioutil.ReadAll(req.Body)
- glog.V(0).Info("Command:", string(commandText))
- if err := json.NewDecoder(strings.NewReader(string(commandText))).Decode(&command); err != nil {
- glog.V(0).Infoln("Error decoding json message:", err, string(commandText))
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
-
- glog.V(0).Infoln("join command from Name", command.Name, "Connection", command.ConnectionString)
-
- if _, err := s.raftServer.Do(command); err != nil {
- switch err {
- case raft.NotLeaderError:
- s.redirectToLeader(w, req)
- default:
- glog.V(0).Infoln("Error processing join:", err)
- http.Error(w, err.Error(), http.StatusInternalServerError)
- }
- }
-}
-
func (s *RaftServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) {
s.router.HandleFunc(pattern, handler)
}
-func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request) {
- if leader, e := s.topo.Leader(); e == nil {
- //http.StatusMovedPermanently does not cause http POST following redirection
- learderLocation := "http://" + leader + req.URL.Path
- glog.V(0).Infoln("Redirecting to", learderLocation)
- writeJsonQuiet(w, req, http.StatusOK, learderLocation)
- // http.Redirect(w, req, "http://"+leader+req.URL.Path, http.StatusFound) // not working any more
- } else {
- glog.V(0).Infoln("Error: Leader Unknown")
- http.Error(w, "Leader unknown", http.StatusInternalServerError)
- }
-}
-
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) {
ret := operation.ClusterStatusResult{
IsLeader: s.topo.IsLeader(),