Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BBS Cache warmup failure #13555

Merged
merged 4 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pkg/util/cloudproviders/cloudfoundry/bbscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,13 @@ func (bc *BBSCache) readData() {
var errActual, errDesired error

wg.Add(2)

go func() {
defer wg.Done()
actualLRPsByProcessGUID, actualLRPsByCellID, errActual = bc.readActualLRPs()
wg.Done()
}()
go func() {
defer wg.Done()
desiredLRPs, errDesired = bc.readDesiredLRPs()
wg.Done()
}()
wg.Wait()
if errActual != nil {
Expand Down
48 changes: 47 additions & 1 deletion pkg/util/cloudproviders/cloudfoundry/cccache.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (ccc *CCCache) setResourceInactive(guid string) {
// release the resource
close(ch)
ccc.Lock()
ccc.activeResources[guid] = nil
delete(ccc.activeResources, guid)
ccc.Unlock()
}
}
Expand Down Expand Up @@ -273,6 +273,14 @@ func (ccc *CCCache) GetProcesses(appGUID string) ([]*cfclient.Process, error) {
return nil, fmt.Errorf("refreshCacheOnMiss is disabled, could not find processes for the app %s in cloud controller cache", appGUID)
}

ccc.RLock()
updatedOnce := !ccc.lastUpdated.IsZero()
ccc.RUnlock()

if !updatedOnce {
return nil, fmt.Errorf("cannot refresh cache on miss, cccache is still warming up")
}

// wait in case the resource is currently being fetched
ccc.waitForResource(appGUID)

Expand Down Expand Up @@ -333,6 +341,14 @@ func (ccc *CCCache) GetCFApplication(guid string) (*CFApplication, error) {
return nil, fmt.Errorf("refreshCacheOnMiss is disabled, could not find CF application %s in cloud controller cache", guid)
}

ccc.RLock()
updatedOnce := !ccc.lastUpdated.IsZero()
ccc.RUnlock()

if !updatedOnce {
return nil, fmt.Errorf("cannot refresh cache on miss, cccache is still warming up")
}

// cfclient.V3App and CFApplication share the same guid which causes a deadlock in the ccc.activeResources map if not properly handled
cfappGUID := "cfapp" + guid

Expand Down Expand Up @@ -438,6 +454,14 @@ func (ccc *CCCache) GetApp(guid string) (*cfclient.V3App, error) {
return nil, fmt.Errorf("refreshCacheOnMiss is disabled, could not find application %s in cloud controller cache", guid)
}

ccc.RLock()
updatedOnce := !ccc.lastUpdated.IsZero()
ccc.RUnlock()

if !updatedOnce {
return nil, fmt.Errorf("cannot refresh cache on miss, cccache is still warming up")
}

// wait in case the resource is currently being fetched
ccc.waitForResource(guid)

Expand Down Expand Up @@ -480,11 +504,20 @@ func (ccc *CCCache) GetSpace(guid string) (*cfclient.V3Space, error) {
ccc.RLock()
space, ok := ccc.spacesByGUID[guid]
ccc.RUnlock()

if !ok {
if !ccc.refreshCacheOnMiss {
return nil, fmt.Errorf("refreshCacheOnMiss is disabled, could not find space %s in cloud controller cache", guid)
}

ccc.RLock()
updatedOnce := !ccc.lastUpdated.IsZero()
ccc.RUnlock()

if !updatedOnce {
return nil, fmt.Errorf("cannot refresh cache on miss, cccache is still warming up")
}

// wait in case the resource is currently being fetched
ccc.waitForResource(guid)

Expand Down Expand Up @@ -527,11 +560,20 @@ func (ccc *CCCache) GetOrg(guid string) (*cfclient.V3Organization, error) {
ccc.RLock()
org, ok := ccc.orgsByGUID[guid]
ccc.RUnlock()

if !ok {
if !ccc.refreshCacheOnMiss {
return nil, fmt.Errorf("refreshCacheOnMiss is disabled, could not find org %s in cloud controller cache", guid)
}

ccc.RLock()
updatedOnce := !ccc.lastUpdated.IsZero()
ccc.RUnlock()

if !updatedOnce {
return nil, fmt.Errorf("cannot refresh cache on miss, cccache is still warming up")
}

// wait in case the resource is currently being fetched
ccc.waitForResource(guid)

Expand Down Expand Up @@ -639,6 +681,10 @@ func (ccc *CCCache) readData() {
log.Errorf("Failed listing sidecars from cloud controller: %v", err)
return
}
// skip apps without sidecars
if len(sidecars) == 0 {
continue
}
for _, sidecar := range sidecars {
s := sidecar
allSidecars = append(allSidecars, &s)
Expand Down