delete_command.go 694 B

1234567891011121314151617181920212223242526272829303132333435
  1. package store
  2. import (
  3. "github.com/coreos/etcd/log"
  4. "github.com/coreos/go-raft"
  5. )
  6. func init() {
  7. raft.RegisterCommand(&DeleteCommand{})
  8. }
  9. // The DeleteCommand removes a key from the Store.
  10. type DeleteCommand struct {
  11. Key string `json:"key"`
  12. Recursive bool `json:"recursive"`
  13. }
  14. // The name of the delete command in the log
  15. func (c *DeleteCommand) CommandName() string {
  16. return "etcd:delete"
  17. }
  18. // Delete the key
  19. func (c *DeleteCommand) Apply(server *raft.Server) (interface{}, error) {
  20. s, _ := server.StateMachine().(*Store)
  21. e, err := s.Delete(c.Key, c.Recursive, server.CommitIndex(), server.Term())
  22. if err != nil {
  23. log.Debug(err)
  24. return nil, err
  25. }
  26. return e, nil
  27. }