MCPcopy
hub / github.com/grpc/grpc-go / rlsBalancer

Struct rlsBalancer

balancer/rls/balancer.go:161–208  ·  balancer/rls/balancer.go::rlsBalancer

rlsBalancer implements the RLS LB policy.

Source from the content-addressed store, hash-verified

159
160// rlsBalancer implements the RLS LB policy.
161type rlsBalancer struct {
162 closed *grpcsync.Event // Fires when Close() is invoked. Guarded by stateMu.
163 done *grpcsync.Event // Fires when Close() is done.
164 cc balancer.ClientConn
165 bopts balancer.BuildOptions
166 purgeTicker *time.Ticker
167 dataCachePurgeHook func()
168 logger *internalgrpclog.PrefixLogger
169
170 // unregisterMetricHandler is the function to deregister the async metric reporter.
171 unregisterMetricHandler func()
172
173 // If both cacheMu and stateMu need to be acquired, the former must be
174 // acquired first to prevent a deadlock. This order restriction is due to the
175 // fact that in places where we need to acquire both the locks, we always
176 // start off reading the cache.
177
178 // cacheMu guards access to the data cache and pending requests map. We
179 // cannot use an RWMutex here since even an operation like
180 // dataCache.getEntry() modifies the underlying LRU, which is implemented as
181 // a doubly linked list.
182 cacheMu sync.Mutex
183 dataCache *dataCache // Cache of RLS data.
184 pendingMap map[cacheKey]*backoffState // Map of pending RLS requests.
185
186 // stateMu guards access to all LB policy state.
187 stateMu sync.Mutex
188 lbCfg *lbConfig // Most recently received service config.
189 childPolicyBuilder balancer.Builder // Cached child policy builder.
190 resolverState resolver.State // Cached resolver state.
191 ctrlCh *controlChannel // Control channel to the RLS server.
192 bg *balancergroup.BalancerGroup
193 childPolicies map[string]*childPolicyWrapper
194 defaultPolicy *childPolicyWrapper
195 // A reference to the most recent picker sent to gRPC as part of a state
196 // update is cached in this field so that we can release the reference to the
197 // default child policy wrapper when a new picker is created. See
198 // sendNewPickerLocked() for details.
199 lastPicker *rlsPicker
200 // Set during UpdateClientConnState when pushing updates to child policies.
201 // Prevents state updates from child policies causing new pickers to be sent
202 // up the channel. Cleared after all child policies have processed the
203 // updates sent to them, after which a new picker is sent up the channel.
204 inhibitPickerUpdates bool
205
206 // Channel on which all updates are pushed. Processed in run().
207 updateCh *buffer.Unbounded
208}
209
210type resumePickerUpdates struct {
211 done chan struct{}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected