consul: More efficient restore of KVS entriesg

This commit is contained in:
Armon Dadgar 2014-04-01 11:29:55 -07:00
parent cfa4ba2d34
commit 4ccb2d4a73
2 changed files with 17 additions and 1 deletions

View File

@ -218,7 +218,7 @@ func (c *consulFSM) Restore(old io.ReadCloser) error {
if err := dec.Decode(&req); err != nil { if err := dec.Decode(&req); err != nil {
return err return err
} }
if err := c.state.KVSSet(req.CreateIndex, &req); err != nil { if err := c.state.KVSRestore(&req); err != nil {
return err return err
} }

View File

@ -746,6 +746,22 @@ func (s *StateStore) KVSSet(index uint64, d *structs.DirEntry) error {
return tx.Commit() 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 // KVSGet is used to get a KV entry
func (s *StateStore) KVSGet(key string) (uint64, *structs.DirEntry, error) { func (s *StateStore) KVSGet(key string) (uint64, *structs.DirEntry, error) {
idx, res, err := s.kvsTable.Get("id", key) idx, res, err := s.kvsTable.Get("id", key)