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

Method UpdateClientConnState

balancer/rls/balancer.go:296–354  ·  view source on GitHub ↗
(ccs balancer.ClientConnState)

Source from the content-addressed store, hash-verified

294}
295
296func (b *rlsBalancer) UpdateClientConnState(ccs balancer.ClientConnState) error {
297 defer clientConnUpdateHook()
298
299 b.stateMu.Lock()
300 if b.closed.HasFired() {
301 b.stateMu.Unlock()
302 b.logger.Warningf("Received service config after balancer close: %s", pretty.ToJSON(ccs.BalancerConfig))
303 return errBalancerClosed
304 }
305
306 newCfg := ccs.BalancerConfig.(*lbConfig)
307 if b.lbCfg.Equal(newCfg) {
308 b.stateMu.Unlock()
309 b.logger.Infof("New service config matches existing config")
310 return nil
311 }
312
313 b.logger.Infof("Delaying picker updates until config is propagated to and processed by child policies")
314 b.inhibitPickerUpdates = true
315
316 // When the RLS server name changes, the old control channel needs to be
317 // swapped out for a new one. All state associated with the throttling
318 // algorithm is stored on a per-control-channel basis; when we swap out
319 // channels, we also swap out the throttling state.
320 b.handleControlChannelUpdate(newCfg)
321
322 // Any changes to child policy name or configuration needs to be handled by
323 // either creating new child policies or pushing updates to existing ones.
324 b.resolverState = ccs.ResolverState
325 b.handleChildPolicyConfigUpdate(newCfg, &ccs)
326
327 // Resize the cache if the size in the config has changed.
328 resizeCache := newCfg.cacheSizeBytes != b.lbCfg.cacheSizeBytes
329
330 // Update the copy of the config in the LB policy before releasing the lock.
331 b.lbCfg = newCfg
332 b.stateMu.Unlock()
333
334 // We cannot do cache operations above because `cacheMu` needs to be grabbed
335 // before `stateMu` if we are to hold both locks at the same time.
336 b.cacheMu.Lock()
337 b.dataCache.updateRLSServerTarget(newCfg.lookupService)
338 if resizeCache {
339 // If the new config changes reduces the size of the data cache, we
340 // might have to evict entries to get the cache size down to the newly
341 // specified size. If we do evict an entry with valid backoff timer,
342 // the new picker needs to be sent to the channel to re-process any
343 // RPCs queued as a result of this backoff timer.
344 b.dataCache.resize(newCfg.cacheSizeBytes)
345 }
346 b.cacheMu.Unlock()
347 // Enqueue an event which will notify us when the above update has been
348 // propagated to all child policies, and the child policies have all
349 // processed their updates, and we have sent a picker update.
350 done := make(chan struct{})
351 b.updateCh.Put(resumePickerUpdates{done: done})
352 <-done
353 return nil

Callers

nothing calls this directly

Calls 12

ToJSONFunction · 0.92
updateRLSServerTargetMethod · 0.80
resizeMethod · 0.80
WarningfMethod · 0.65
EqualMethod · 0.65
InfofMethod · 0.65
PutMethod · 0.65
LockMethod · 0.45
HasFiredMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected