Browse Source

change imports to coreos/etcd coreos/go-raft; change API to work with new go-raft

Xiang Li 12 years ago
parent
commit
e2f0420862
6 changed files with 28 additions and 28 deletions
  1. 4 4
      command.go
  2. 4 4
      etcd.go
  3. 4 4
      handlers.go
  4. 14 14
      trans_handler.go
  5. 1 1
      util.go
  6. 1 1
      web/web.go

+ 4 - 4
command.go

@@ -8,8 +8,8 @@ package main
 
 import (
 	"encoding/json"
-	"github.com/xiangli-cmu/go-raft"
-	"github.com/xiangli-cmu/raft-etcd/store"
+	"github.com/coreos/etcd/store"
+	"github.com/coreos/go-raft"
 	"time"
 )
 
@@ -33,7 +33,7 @@ func (c *SetCommand) CommandName() string {
 
 // Set the value of key to value
 func (c *SetCommand) Apply(server *raft.Server) (interface{}, error) {
-	return store.Set(c.Key, c.Value, c.ExpireTime, server.CommittedIndex())
+	return store.Set(c.Key, c.Value, c.ExpireTime, server.CommitIndex())
 }
 
 // Get the path for http request
@@ -88,7 +88,7 @@ func (c *DeleteCommand) CommandName() string {
 
 // Delete the key
 func (c *DeleteCommand) Apply(server *raft.Server) (interface{}, error) {
-	return store.Delete(c.Key, server.CommittedIndex())
+	return store.Delete(c.Key, server.CommitIndex())
 }
 
 // Watch command

+ 4 - 4
etcd.go

@@ -8,9 +8,9 @@ import (
 	"encoding/pem"
 	"flag"
 	"fmt"
-	"github.com/xiangli-cmu/go-raft"
-	"github.com/xiangli-cmu/raft-etcd/store"
-	"github.com/xiangli-cmu/raft-etcd/web"
+	"github.com/coreos/etcd/store"
+	"github.com/coreos/etcd/web"
+	"github.com/coreos/go-raft"
 	//"io"
 	"io/ioutil"
 	"log"
@@ -187,7 +187,7 @@ func main() {
 		// start as a leader in a new cluster
 		if cluster == "" {
 			server.StartLeader()
-			
+
 			time.Sleep(time.Millisecond * 20)
 
 			// join self as a peer

+ 4 - 4
handlers.go

@@ -2,7 +2,7 @@ package main
 
 import (
 	"encoding/json"
-	"github.com/xiangli-cmu/go-raft"
+	"github.com/coreos/go-raft"
 	"net/http"
 	"strconv"
 	"time"
@@ -25,7 +25,7 @@ func VoteHttpHandler(w http.ResponseWriter, req *http.Request) {
 	err := decodeJsonRequest(req, rvreq)
 	if err == nil {
 		debug("[recv] POST http://%v/vote [%s]", server.Name(), rvreq.CandidateName)
-		if resp, _ := server.RequestVote(rvreq); resp != nil {
+		if resp := server.RequestVote(rvreq); resp != nil {
 			w.WriteHeader(http.StatusOK)
 			json.NewEncoder(w).Encode(resp)
 			return
@@ -40,7 +40,7 @@ func AppendEntriesHttpHandler(w http.ResponseWriter, req *http.Request) {
 	err := decodeJsonRequest(req, aereq)
 	if err == nil {
 		debug("[recv] POST http://%s/log/append [%d]", server.Name(), len(aereq.Entries))
-		if resp, _ := server.AppendEntries(aereq); resp != nil {
+		if resp := server.AppendEntries(aereq); resp != nil {
 			w.WriteHeader(http.StatusOK)
 			json.NewEncoder(w).Encode(resp)
 			if !resp.Success {
@@ -187,7 +187,7 @@ func excute(c Command, w *http.ResponseWriter, req *http.Request) {
 		url := scheme + leaderClient() + path
 
 		debug("redirect to %s", url)
-		
+
 		http.Redirect(*w, req, url, http.StatusTemporaryRedirect)
 		return
 	}

+ 14 - 14
trans_handler.go

@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"encoding/json"
 	"fmt"
-	"github.com/xiangli-cmu/go-raft"
+	"github.com/coreos/go-raft"
 	"io"
 	"net/http"
 )
@@ -15,49 +15,49 @@ type transHandler struct {
 }
 
 // Sends AppendEntries RPCs to a peer when the server is the leader.
-func (t transHandler) SendAppendEntriesRequest(server *raft.Server, peer *raft.Peer, req *raft.AppendEntriesRequest) (*raft.AppendEntriesResponse, error) {
+func (t transHandler) SendAppendEntriesRequest(server *raft.Server, peer *raft.Peer, req *raft.AppendEntriesRequest) *raft.AppendEntriesResponse {
 	var aersp *raft.AppendEntriesResponse
 	var b bytes.Buffer
 	json.NewEncoder(&b).Encode(req)
 
 	debug("Send LogEntries to %s ", peer.Name())
 
-	resp, err := Post(&t, fmt.Sprintf("%s/log/append", peer.Name()), &b)
+	resp, _ := Post(&t, fmt.Sprintf("%s/log/append", peer.Name()), &b)
 
 	if resp != nil {
 		defer resp.Body.Close()
 		aersp = &raft.AppendEntriesResponse{}
-		if err = json.NewDecoder(resp.Body).Decode(&aersp); err == nil || err == io.EOF {
-			return aersp, nil
+		if err := json.NewDecoder(resp.Body).Decode(&aersp); err == nil || err == io.EOF {
+			return aersp
 		}
 
 	}
-	return aersp, fmt.Errorf("raftd: Unable to append entries: %v", err)
+	return aersp
 }
 
 // Sends RequestVote RPCs to a peer when the server is the candidate.
-func (t transHandler) SendVoteRequest(server *raft.Server, peer *raft.Peer, req *raft.RequestVoteRequest) (*raft.RequestVoteResponse, error) {
+func (t transHandler) SendVoteRequest(server *raft.Server, peer *raft.Peer, req *raft.RequestVoteRequest) *raft.RequestVoteResponse {
 	var rvrsp *raft.RequestVoteResponse
 	var b bytes.Buffer
 	json.NewEncoder(&b).Encode(req)
 
 	debug("Send Vote to %s", peer.Name())
 
-	resp, err := Post(&t, fmt.Sprintf("%s/vote", peer.Name()), &b)
+	resp, _ := Post(&t, fmt.Sprintf("%s/vote", peer.Name()), &b)
 
 	if resp != nil {
 		defer resp.Body.Close()
 		rvrsp := &raft.RequestVoteResponse{}
-		if err = json.NewDecoder(resp.Body).Decode(&rvrsp); err == nil || err == io.EOF {
-			return rvrsp, nil
+		if err := json.NewDecoder(resp.Body).Decode(&rvrsp); err == nil || err == io.EOF {
+			return rvrsp
 		}
 
 	}
-	return rvrsp, fmt.Errorf("Unable to request vote: %v", err)
+	return rvrsp
 }
 
 // Sends SnapshotRequest RPCs to a peer when the server is the candidate.
-func (t transHandler) SendSnapshotRequest(server *raft.Server, peer *raft.Peer, req *raft.SnapshotRequest) (*raft.SnapshotResponse, error) {
+func (t transHandler) SendSnapshotRequest(server *raft.Server, peer *raft.Peer, req *raft.SnapshotRequest) *raft.SnapshotResponse {
 	var aersp *raft.SnapshotResponse
 	var b bytes.Buffer
 	json.NewEncoder(&b).Encode(req)
@@ -72,8 +72,8 @@ func (t transHandler) SendSnapshotRequest(server *raft.Server, peer *raft.Peer,
 		aersp = &raft.SnapshotResponse{}
 		if err = json.NewDecoder(resp.Body).Decode(&aersp); err == nil || err == io.EOF {
 
-			return aersp, nil
+			return aersp
 		}
 	}
-	return aersp, fmt.Errorf("Unable to send snapshot: %v", err)
+	return aersp
 }

+ 1 - 1
util.go

@@ -3,7 +3,7 @@ package main
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/xiangli-cmu/raft-etcd/web"
+	"github.com/coreos/etcd/web"
 	"io"
 	"io/ioutil"
 	"net/http"

+ 1 - 1
web/web.go

@@ -3,7 +3,7 @@ package web
 import (
 	"code.google.com/p/go.net/websocket"
 	"fmt"
-	"github.com/xiangli-cmu/go-raft"
+	"github.com/coreos/go-raft"
 	//"github.com/xiangli-cmu/raft-etcd/store"
 	"html/template"
 	"net/http"