Skip to content

Commit

Permalink
Adjust cache ModuleDataProvider to re-retrieve delegate values from…
Browse files Browse the repository at this point in the history
… store after putting in store (#3449)

Co-authored-by: bufdev <[email protected]>
  • Loading branch information
doriable and bufdev authored Nov 8, 2024
1 parent b4916b4 commit 62082b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions private/bufpkg/bufmodule/bufmodulecache/base_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ func (p *baseProvider[K, V]) getValuesForKeys(ctx context.Context, keys []K) ([]
); err != nil {
return nil, err
}
// We are getting the values again so that we retrieve the values from the cache directly.
// This matters for ie ModuleDatas where the storage.Bucket attached will have local paths
// instead of empty local paths if read from the cache. We documment NewModuleDataProvider
// to return a ModuleDataProvider that will always have local paths for returned storage.Buckets,
// if the cache is an on-disk cache.
var delegateNotFoundKeys []K
delegateValues, delegateNotFoundKeys, err = p.storeGetValuesForKeys(ctx, notFoundKeys)
if err != nil {
return nil, err
}
// We need to ensure that all the delegate values can be retrieved from the store. If there
// are unfound keys, we return an error.
if len(delegateNotFoundKeys) > 0 {
return nil, syserror.Newf(
"delegate keys %v not found in the store after putting in the store",
delegateNotFoundKeys,
)
}

p.keysRetrieved.Add(int64(len(keys)))
p.keysHit.Add(int64(len(foundValues)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
// NewModuleDataProvider returns a new ModuleDataProvider that caches the results of the delegate.
//
// The ModuleDataStore is used as a cache.
//
// All files in returned [storage.Bucket]s will have local paths if the cache is on-disk.
func NewModuleDataProvider(
logger *slog.Logger,
delegate bufmodule.ModuleDataProvider,
Expand Down

0 comments on commit 62082b2

Please sign in to comment.