mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
not hardcode debug scheme
This commit is contained in:
parent
749a89d5a5
commit
d2382c232e
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/coreos/etcd/store"
|
"github.com/coreos/etcd/store"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -116,10 +115,10 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool)
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
if body == nil {
|
if body == nil {
|
||||||
fmt.Println("empty but not err!")
|
|
||||||
http.NotFound((*w), req)
|
http.NotFound((*w), req)
|
||||||
} else {
|
} else {
|
||||||
body, ok := body.([]byte)
|
body, ok := body.([]byte)
|
||||||
|
// this should not happen
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("wrong type")
|
panic("wrong type")
|
||||||
}
|
}
|
||||||
|
25
etcd.go
25
etcd.go
@ -52,6 +52,8 @@ var ignore bool
|
|||||||
|
|
||||||
var maxSize int
|
var maxSize int
|
||||||
|
|
||||||
|
var snapshot bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&verbose, "v", false, "verbose logging")
|
flag.BoolVar(&verbose, "v", false, "verbose logging")
|
||||||
|
|
||||||
@ -75,6 +77,8 @@ func init() {
|
|||||||
|
|
||||||
flag.BoolVar(&ignore, "i", false, "ignore the old configuration, create a new node")
|
flag.BoolVar(&ignore, "i", false, "ignore the old configuration, create a new node")
|
||||||
|
|
||||||
|
flag.BoolVar(&snapshot, "snapshot", false, "open or close snapshot")
|
||||||
|
|
||||||
flag.IntVar(&maxSize, "m", 1024, "the max size of result buffer")
|
flag.IntVar(&maxSize, "m", 1024, "the max size of result buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,13 +211,15 @@ func startRaft(securityType int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadSnapshot
|
// LoadSnapshot
|
||||||
// err = raftServer.LoadSnapshot()
|
if snapshot {
|
||||||
|
err = raftServer.LoadSnapshot()
|
||||||
|
|
||||||
// if err == nil {
|
if err == nil {
|
||||||
// debug("%s finished load snapshot", raftServer.Name())
|
debug("%s finished load snapshot", raftServer.Name())
|
||||||
// } else {
|
} else {
|
||||||
// debug(err)
|
debug(err.Error())
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
raftServer.Initialize()
|
raftServer.Initialize()
|
||||||
raftServer.SetElectionTimeout(ELECTIONTIMTOUT)
|
raftServer.SetElectionTimeout(ELECTIONTIMTOUT)
|
||||||
@ -267,7 +273,9 @@ func startRaft(securityType int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// open the snapshot
|
// open the snapshot
|
||||||
//go raftServer.Snapshot()
|
if snapshot {
|
||||||
|
go raftServer.Snapshot()
|
||||||
|
}
|
||||||
|
|
||||||
// start to response to raft requests
|
// start to response to raft requests
|
||||||
go startRaftTransport(info.RaftPort, securityType)
|
go startRaftTransport(info.RaftPort, securityType)
|
||||||
@ -567,9 +575,6 @@ func joinCluster(s *raft.Server, serverName string) error {
|
|||||||
json.NewEncoder(&b).Encode(command)
|
json.NewEncoder(&b).Encode(command)
|
||||||
resp, err = t.Post(fmt.Sprintf("%s/join", address), &b)
|
resp, err = t.Post(fmt.Sprintf("%s/join", address), &b)
|
||||||
} else {
|
} else {
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
|
||||||
fmt.Println(string(b))
|
|
||||||
resp.Body.Close()
|
|
||||||
return fmt.Errorf("Unable to join")
|
return fmt.Errorf("Unable to join")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
// Get all the current logs
|
// Get all the current logs
|
||||||
func GetLogHttpHandler(w http.ResponseWriter, req *http.Request) {
|
func GetLogHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
debug("[recv] GET http://%v/log", raftServer.Name())
|
debug("[recv] GET %s/log", raftTransporter.scheme+raftServer.Name())
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(raftServer.LogEntries())
|
json.NewEncoder(w).Encode(raftServer.LogEntries())
|
||||||
@ -24,7 +24,7 @@ func VoteHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
rvreq := &raft.RequestVoteRequest{}
|
rvreq := &raft.RequestVoteRequest{}
|
||||||
err := decodeJsonRequest(req, rvreq)
|
err := decodeJsonRequest(req, rvreq)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
debug("[recv] POST http://%v/vote [%s]", raftServer.Name(), rvreq.CandidateName)
|
debug("[recv] POST %s/vote [%s]", raftTransporter.scheme+raftServer.Name(), rvreq.CandidateName)
|
||||||
if resp := raftServer.RequestVote(rvreq); resp != nil {
|
if resp := raftServer.RequestVote(rvreq); resp != nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(w).Encode(resp)
|
||||||
@ -41,7 +41,7 @@ func AppendEntriesHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
err := decodeJsonRequest(req, aereq)
|
err := decodeJsonRequest(req, aereq)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
debug("[recv] POST http://%s/log/append [%d]", raftServer.Name(), len(aereq.Entries))
|
debug("[recv] POST %s/log/append [%d]", raftTransporter.scheme+raftServer.Name(), len(aereq.Entries))
|
||||||
if resp := raftServer.AppendEntries(aereq); resp != nil {
|
if resp := raftServer.AppendEntries(aereq); resp != nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(w).Encode(resp)
|
||||||
@ -60,7 +60,7 @@ func SnapshotHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
aereq := &raft.SnapshotRequest{}
|
aereq := &raft.SnapshotRequest{}
|
||||||
err := decodeJsonRequest(req, aereq)
|
err := decodeJsonRequest(req, aereq)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
debug("[recv] POST http://%s/snapshot/ ", raftServer.Name())
|
debug("[recv] POST %s/snapshot/ ", raftTransporter.scheme+raftServer.Name())
|
||||||
if resp := raftServer.RequestSnapshot(aereq); resp != nil {
|
if resp := raftServer.RequestSnapshot(aereq); resp != nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(w).Encode(resp)
|
||||||
@ -76,7 +76,7 @@ func SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
aereq := &raft.SnapshotRecoveryRequest{}
|
aereq := &raft.SnapshotRecoveryRequest{}
|
||||||
err := decodeJsonRequest(req, aereq)
|
err := decodeJsonRequest(req, aereq)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
debug("[recv] POST http://%s/snapshotRecovery/ ", raftServer.Name())
|
debug("[recv] POST %s/snapshotRecovery/ ", raftTransporter.scheme+raftServer.Name())
|
||||||
if resp := raftServer.SnapshotRecoveryRequest(aereq); resp != nil {
|
if resp := raftServer.SnapshotRecoveryRequest(aereq); resp != nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(w).Encode(resp)
|
||||||
@ -89,7 +89,7 @@ func SnapshotRecoveryHttpHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
// Get the port that listening for client connecting of the server
|
// Get the port that listening for client connecting of the server
|
||||||
func ClientHttpHandler(w http.ResponseWriter, req *http.Request) {
|
func ClientHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
debug("[recv] Get http://%v/client/ ", raftServer.Name())
|
debug("[recv] Get %s/client/ ", raftTransporter.scheme+raftServer.Name())
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
client := hostname + ":" + strconv.Itoa(clientPort)
|
client := hostname + ":" + strconv.Itoa(clientPort)
|
||||||
w.Write([]byte(client))
|
w.Write([]byte(client))
|
||||||
|
@ -104,7 +104,6 @@ func (t transporter) SendSnapshotRecoveryRequest(server *raft.Server, peer *raft
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
aersp = &raft.SnapshotRecoveryResponse{}
|
aersp = &raft.SnapshotRecoveryResponse{}
|
||||||
if err = json.NewDecoder(resp.Body).Decode(&aersp); err == nil || err == io.EOF {
|
if err = json.NewDecoder(resp.Body).Decode(&aersp); err == nil || err == io.EOF {
|
||||||
|
|
||||||
return aersp
|
return aersp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user