sync_command.go 526 B

12345678910111213141516171819202122232425262728
  1. package v2
  2. import (
  3. "time"
  4. "github.com/coreos/etcd/store"
  5. "github.com/coreos/etcd/third_party/github.com/goraft/raft"
  6. )
  7. func init() {
  8. raft.RegisterCommand(&SyncCommand{})
  9. }
  10. type SyncCommand struct {
  11. Time time.Time `json:"time"`
  12. }
  13. // The name of the Sync command in the log
  14. func (c SyncCommand) CommandName() string {
  15. return "etcd:sync"
  16. }
  17. func (c SyncCommand) Apply(context raft.Context) (interface{}, error) {
  18. s, _ := context.Server().StateMachine().(store.Store)
  19. s.DeleteExpiredKeys(c.Time)
  20. return nil, nil
  21. }