Skip to content

Commit

Permalink
Merge pull request #1 from xiangli-cmu/master
Browse files Browse the repository at this point in the history
Change imports to coreos/etcd coreos/go-raft
  • Loading branch information
polvi committed Jul 8, 2013
2 parents 0f22918 + e2f0420 commit cd2355e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"encoding/json"
"github.com/xiangli-cmu/go-raft"
"github.com/coreos/go-raft"
"net/http"
"strconv"
"time"
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
28 changes: 14 additions & 14 deletions trans_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/xiangli-cmu/go-raft"
"github.com/coreos/go-raft"
"io"
"net/http"
)
Expand All @@ -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)
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cd2355e

Please sign in to comment.