Only write to etcd if values have changed

This prevents certain loops from writing data to etcd every few
seconds (when data hasn't changed).
This commit is contained in:
Clayton Coleman
2014-08-14 15:51:20 -04:00
parent 778c89f65e
commit befbf8466f
2 changed files with 37 additions and 1 deletions

View File

@@ -249,7 +249,7 @@ type EtcdUpdateFunc func(input interface{}) (output interface{}, err error)
// // Before this function is called, currentObj has been reset to etcd's current
// // contents for "myKey".
//
// cur := input.(*MyType) // Gauranteed to work.
// cur := input.(*MyType) // Guaranteed to work.
//
// // Make a *modification*.
// cur.Counter++
@@ -290,6 +290,10 @@ func (h *EtcdHelper) AtomicUpdate(key string, ptrToType interface{}, tryUpdate E
return err
}
if string(data) == origBody {
return nil
}
_, err = h.Client.CompareAndSwap(key, string(data), 0, origBody, index)
if IsEtcdTestFailed(err) {
continue