setChildPolicyWrappersInCacheEntry sets up the childPolicyWrappers field in the cache entry to point to the child policy wrappers for the targets specified in the RLS response. Caller must hold a write-lock on p.lb.cacheMu.
(dcEntry *cacheEntry, newTargets []string)
| 364 | // |
| 365 | // Caller must hold a write-lock on p.lb.cacheMu. |
| 366 | func (p *rlsPicker) setChildPolicyWrappersInCacheEntry(dcEntry *cacheEntry, newTargets []string) { |
| 367 | // If the childPolicyWrappers field is already pointing to the right targets, |
| 368 | // then the field's value does not need to change. |
| 369 | targetsChanged := true |
| 370 | func() { |
| 371 | if cpws := dcEntry.childPolicyWrappers; cpws != nil { |
| 372 | if len(newTargets) != len(cpws) { |
| 373 | return |
| 374 | } |
| 375 | for i, target := range newTargets { |
| 376 | if cpws[i].target != target { |
| 377 | return |
| 378 | } |
| 379 | } |
| 380 | targetsChanged = false |
| 381 | } |
| 382 | }() |
| 383 | if !targetsChanged { |
| 384 | return |
| 385 | } |
| 386 | |
| 387 | // If the childPolicyWrappers field is not already set to the right targets, |
| 388 | // then it must be reset. We construct a new list of child policies and |
| 389 | // then swap out the old list for the new one. |
| 390 | newChildPolicies := p.lb.acquireChildPolicyReferences(newTargets) |
| 391 | oldChildPolicyTargets := make([]string, len(dcEntry.childPolicyWrappers)) |
| 392 | for i, cpw := range dcEntry.childPolicyWrappers { |
| 393 | oldChildPolicyTargets[i] = cpw.target |
| 394 | } |
| 395 | p.lb.releaseChildPolicyReferences(oldChildPolicyTargets) |
| 396 | dcEntry.childPolicyWrappers = newChildPolicies |
| 397 | } |
| 398 | |
| 399 | func dcEntrySize(key cacheKey, entry *cacheEntry) int64 { |
| 400 | return int64(len(key.path) + len(key.keys) + len(entry.headerData)) |
no test coverage detected