mirror of https://github.com/status-im/consul.git
consul: More efficient restore of KVS entriesg
This commit is contained in:
parent
cfa4ba2d34
commit
4ccb2d4a73
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue