update_command.go 762 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package v2
  2. import (
  3. "github.com/coreos/etcd/log"
  4. "github.com/coreos/etcd/store"
  5. "github.com/coreos/etcd/third_party/github.com/goraft/raft"
  6. "time"
  7. )
  8. func init() {
  9. raft.RegisterCommand(&UpdateCommand{})
  10. }
  11. // Update command
  12. type UpdateCommand struct {
  13. Key string `json:"key"`
  14. Value string `json:"value"`
  15. ExpireTime time.Time `json:"expireTime"`
  16. }
  17. // The name of the update command in the log
  18. func (c *UpdateCommand) CommandName() string {
  19. return "etcd:update"
  20. }
  21. // Create node
  22. func (c *UpdateCommand) Apply(context raft.Context) (interface{}, error) {
  23. s, _ := context.Server().StateMachine().(store.Store)
  24. e, err := s.Update(c.Key, c.Value, c.ExpireTime)
  25. if err != nil {
  26. log.Debug(err)
  27. return nil, err
  28. }
  29. return e, nil
  30. }