Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP

Loading…

feat(get): get from quorum #866

Merged
merged 1 commit into from

4 participants

@xiang90
Owner

@bmizerany @philips

I do not suggest people to use this function unless they know exactly what they want.
This is just for linearizability in real time order. Index is a better indication of the actual order of events.
Nothing to do with etcd's write consensus/consistency model.

@bmizerany

LGTM. It agree it needs a warning in the docs.

@yichengq
Owner

lgtm. A smoke test for it would be great.

@philips
Owner

We need to add documentation for this and figure out what happens in a mixed version cluster.

@philips philips merged commit 1cffdb3 into master
@yichengq yichengq deleted the qread branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 23, 2014
  1. @xiang90

    feat(get): get from quorum

    xiang90 authored
This page is out of date. Refresh to see the latest.
View
10 server/v2/get_handler.go
@@ -17,6 +17,14 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
vars := mux.Vars(req)
key := "/" + vars["key"]
+ recursive := (req.FormValue("recursive") == "true")
+ sort := (req.FormValue("sorted") == "true")
+
+ if req.FormValue("quorum") == "true" {
+ c := s.Store().CommandFactory().CreateGetCommand(key, recursive, sort)
+ return s.Dispatch(c, w, req)
+ }
+
// Help client to redirect the request to the current leader
if req.FormValue("consistent") == "true" && s.State() != raft.Leader {
leader := s.Leader()
@@ -35,8 +43,6 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
return nil
}
- recursive := (req.FormValue("recursive") == "true")
- sort := (req.FormValue("sorted") == "true")
waitIndex := req.FormValue("waitIndex")
stream := (req.FormValue("stream") == "true")
View
1  store/command_factory.go
@@ -24,6 +24,7 @@ type CommandFactory interface {
prevIndex uint64, expireTime time.Time) raft.Command
CreateCompareAndDeleteCommand(key string, prevValue string, prevIndex uint64) raft.Command
CreateSyncCommand(now time.Time) raft.Command
+ CreateGetCommand(key string, recursive, sorted bool) raft.Command
}
// RegisterCommandFactory adds a command factory to the global registry.
View
8 store/v2/command_factory.go
@@ -89,3 +89,11 @@ func (f *CommandFactory) CreateSyncCommand(now time.Time) raft.Command {
Time: time.Now(),
}
}
+
+func (f *CommandFactory) CreateGetCommand(key string, recursive, sorted bool) raft.Command {
+ return &GetCommand{
+ Key: key,
+ Recursive: recursive,
+ Sorted: sorted,
+ }
+}
View
35 store/v2/get_command.go
@@ -0,0 +1,35 @@
+package v2
+
+import (
+ "github.com/coreos/etcd/log"
+ "github.com/coreos/etcd/store"
+ "github.com/coreos/etcd/third_party/github.com/goraft/raft"
+)
+
+func init() {
+ raft.RegisterCommand(&GetCommand{})
+}
+
+// The GetCommand gets a key from the Store.
+type GetCommand struct {
+ Key string `json:"key"`
+ Recursive bool `json:"recursive"`
+ Sorted bool `json:sorted`
+}
+
+// The name of the get command in the log
+func (c *GetCommand) CommandName() string {
+ return "etcd:get"
+}
+
+// Get the key
+func (c *GetCommand) Apply(context raft.Context) (interface{}, error) {
+ s, _ := context.Server().StateMachine().(store.Store)
+ e, err := s.Get(c.Key, c.Recursive, c.Sorted)
+
+ if err != nil {
+ log.Debug(err)
+ return nil, err
+ }
+ return e, nil
+}
Something went wrong with that request. Please try again.