agent/proxy: improve comments on snapshotting

This commit is contained in:
Mitchell Hashimoto 2018-05-03 17:47:38 -07:00
parent e0bbe66427
commit 1a32435a4d
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 11 additions and 2 deletions

View File

@ -96,8 +96,14 @@ type Manager struct {
// for changes to this value.
runState managerRunState
proxies map[string]Proxy
// lastSnapshot stores a pointer to the last snapshot that successfully
// wrote to disk. This is used for dup detection to prevent rewriting
// the same snapshot multiple times. snapshots should never be that
// large so keeping it in-memory should be cheap even for thousands of
// proxies (unlikely scenario).
lastSnapshot *snapshot
proxies map[string]Proxy
}
// NewManager initializes a Manager. After initialization, the exported

View File

@ -101,7 +101,10 @@ func (m *Manager) snapshot(path string, checkDup bool) error {
// Write the file
err = file.WriteAtomic(path, encoded)
if err == nil && checkDup {
// If we are checking for dups and we had a successful write, store
// it so we don't rewrite the same value.
if checkDup && err == nil {
m.lastSnapshot = &s
}
return err