diff --git a/server/server.go b/server/server.go index 786947c81..36df79f6f 100644 --- a/server/server.go +++ b/server/server.go @@ -254,11 +254,10 @@ func (s *Server) SpeedTestHandler(w http.ResponseWriter, req *http.Request) erro for i := 0; i < count; i++ { go func() { for j := 0; j < 10; j++ { - c := &store.CreateCommand{ + c := &store.SetCommand{ Key: "foo", Value: "bar", ExpireTime: time.Unix(0, 0), - Force: true, } s.peerServer.RaftServer().Do(c) } diff --git a/server/v1/set_key_handler.go b/server/v1/set_key_handler.go index acd4037c1..887c8c22e 100644 --- a/server/v1/set_key_handler.go +++ b/server/v1/set_key_handler.go @@ -39,11 +39,10 @@ func SetKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error { } } else { - c = &store.CreateCommand{ + c = &store.SetCommand{ Key: key, Value: value, ExpireTime: expireTime, - Force: true, } } diff --git a/server/v2/put_handler.go b/server/v2/put_handler.go index 6a5856f92..a0580f840 100644 --- a/server/v2/put_handler.go +++ b/server/v2/put_handler.go @@ -35,11 +35,10 @@ func PutHandler(w http.ResponseWriter, req *http.Request, s Server) error { // Set command: create a new node or replace the old one. if !valueOk && !indexOk && !existOk { - c = &store.CreateCommand{ + c = &store.SetCommand{ Key: key, Value: value, ExpireTime: expireTime, - Force: true, } return s.Dispatch(c, w, req) } diff --git a/store/create_command.go b/store/create_command.go index 43c09f998..c1f57910a 100644 --- a/store/create_command.go +++ b/store/create_command.go @@ -16,7 +16,6 @@ type CreateCommand struct { Value string `json:"value"` ExpireTime time.Time `json:"expireTime"` IncrementalSuffix bool `json:"incrementalSuffix"` - Force bool `json:"force"` } // The name of the create command in the log @@ -28,7 +27,7 @@ func (c *CreateCommand) CommandName() string { func (c *CreateCommand) Apply(server raft.Server) (interface{}, error) { s, _ := server.StateMachine().(Store) - e, err := s.Create(c.Key, c.Value, c.IncrementalSuffix, c.Force, c.ExpireTime, server.CommitIndex(), server.Term()) + e, err := s.Create(c.Key, c.Value, c.IncrementalSuffix, false, c.ExpireTime, server.CommitIndex(), server.Term()) if err != nil { log.Debug(err) diff --git a/store/set_command.go b/store/set_command.go new file mode 100644 index 000000000..ac8e2cf58 --- /dev/null +++ b/store/set_command.go @@ -0,0 +1,38 @@ +package store + +import ( + "github.com/coreos/etcd/log" + "github.com/coreos/go-raft" + "time" +) + +func init() { + raft.RegisterCommand(&CreateCommand{}) +} + +// Create command +type SetCommand struct { + Key string `json:"key"` + Value string `json:"value"` + ExpireTime time.Time `json:"expireTime"` +} + +// The name of the create command in the log +func (c *SetCommand) CommandName() string { + return "etcd:set" +} + +// Create node +func (c *SetCommand) Apply(server raft.Server) (interface{}, error) { + s, _ := server.StateMachine().(Store) + + // create a new node or replace the old node. + e, err := s.Create(c.Key, c.Value, false, true, c.ExpireTime, server.CommitIndex(), server.Term()) + + if err != nil { + log.Debug(err) + return nil, err + } + + return e, nil +}