diff --git a/consul/fsm.go b/consul/fsm.go index 739e5d9225..f8451913f2 100644 --- a/consul/fsm.go +++ b/consul/fsm.go @@ -218,7 +218,7 @@ func (c *consulFSM) Restore(old io.ReadCloser) error { if err := dec.Decode(&req); err != nil { return err } - if err := c.state.KVSSet(req.CreateIndex, &req); err != nil { + if err := c.state.KVSRestore(&req); err != nil { return err } diff --git a/consul/state_store.go b/consul/state_store.go index ded7e13b0b..be18995a15 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -746,6 +746,22 @@ func (s *StateStore) KVSSet(index uint64, d *structs.DirEntry) error { return tx.Commit() } +// KVSRestore is used to restore a DirEntry. It should only be used when +// doing a restore, otherwise KVSSet should be used. +func (s *StateStore) KVSRestore(d *structs.DirEntry) error { + // Start a new txn + tx, err := s.kvsTable.StartTxn(false, nil) + if err != nil { + return err + } + defer tx.Abort() + + if err := s.kvsTable.InsertTxn(tx, d); err != nil { + return err + } + return tx.Commit() +} + // KVSGet is used to get a KV entry func (s *StateStore) KVSGet(key string) (uint64, *structs.DirEntry, error) { idx, res, err := s.kvsTable.Get("id", key)