~thumper/juju-core/more-ipperms

« back to all changes in this revision

Viewing changes to state/state.go

state: start allManager on demand

As things are currently, every single agent
will be watching *everything*. This is clearly
wrong, so we start the allManager only
when someone wants to watch everything.

R=fwereade
CC=
https://codereview.appspot.com/8823043

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
        "sort"
24
24
        "strconv"
25
25
        "strings"
 
26
        "sync"
26
27
)
27
28
 
28
29
// TODO(niemeyer): This must not be exported.
131
132
        runner         *txn.Runner
132
133
        watcher        *watcher.Watcher
133
134
        pwatcher       *presence.Watcher
134
 
        allManager     *multiwatcher.StoreManager
 
135
        // mu guards allManager.
 
136
        mu         sync.Mutex
 
137
        allManager *multiwatcher.StoreManager
135
138
}
136
139
 
137
140
func (st *State) Watch() *multiwatcher.Watcher {
 
141
        st.mu.Lock()
 
142
        if st.allManager == nil {
 
143
                st.allManager = multiwatcher.NewStoreManager(newAllWatcherStateBacking(st))
 
144
        }
 
145
        st.mu.Unlock()
138
146
        return multiwatcher.NewWatcher(st.allManager)
139
147
}
140
148