From 1a32435a4d6eeb8ff6f77e7db052bc65619f8c41 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 3 May 2018 17:47:38 -0700 Subject: [PATCH] agent/proxy: improve comments on snapshotting --- agent/proxy/manager.go | 8 +++++++- agent/proxy/snapshot.go | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/agent/proxy/manager.go b/agent/proxy/manager.go index 7a8cd5d4cd..5bb871c65f 100644 --- a/agent/proxy/manager.go +++ b/agent/proxy/manager.go @@ -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 diff --git a/agent/proxy/snapshot.go b/agent/proxy/snapshot.go index 973a2f083d..8f81a182a2 100644 --- a/agent/proxy/snapshot.go +++ b/agent/proxy/snapshot.go @@ -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