mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

for i in github.com/BurntSushi/toml github.com/coreos/go-etcd/etcd github.com/coreos/go-log/log github.com/gorilla/context github.com/rcrowley/go-metrics bitbucket.org/kardianos/osext github.com/coreos/go-systemd/journal github.com/coreos/raft code.google.com/p/goprotobuf/proto ; do goven -copy -rewrite $i; done
38 lines
933 B
Go
38 lines
933 B
Go
package v2
|
|
|
|
import (
|
|
"github.com/coreos/etcd/log"
|
|
"github.com/coreos/etcd/store"
|
|
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
|
|
)
|
|
|
|
func init() {
|
|
raft.RegisterCommand(&CompareAndDeleteCommand{})
|
|
}
|
|
|
|
// The CompareAndDelete performs a conditional delete on a key in the store.
|
|
type CompareAndDeleteCommand struct {
|
|
Key string `json:"key"`
|
|
PrevValue string `json:"prevValue"`
|
|
PrevIndex uint64 `json:"prevIndex"`
|
|
}
|
|
|
|
// The name of the compareAndDelete command in the log
|
|
func (c *CompareAndDeleteCommand) CommandName() string {
|
|
return "etcd:compareAndDelete"
|
|
}
|
|
|
|
// Set the key-value pair if the current value of the key equals to the given prevValue
|
|
func (c *CompareAndDeleteCommand) Apply(server raft.Server) (interface{}, error) {
|
|
s, _ := server.StateMachine().(store.Store)
|
|
|
|
e, err := s.CompareAndDelete(c.Key, c.PrevValue, c.PrevIndex)
|
|
|
|
if err != nil {
|
|
log.Debug(err)
|
|
return nil, err
|
|
}
|
|
|
|
return e, nil
|
|
}
|