Skip to content

Commit 62082b2

Browse files
doriablebufdev
andauthored
Adjust cache ModuleDataProvider to re-retrieve delegate values from store after putting in store (#3449)
Co-authored-by: bufdev <bufdev-github@buf.build>
1 parent b4916b4 commit 62082b2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

private/bufpkg/bufmodule/bufmodulecache/base_provider.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ func (p *baseProvider[K, V]) getValuesForKeys(ctx context.Context, keys []K) ([]
8080
); err != nil {
8181
return nil, err
8282
}
83+
// We are getting the values again so that we retrieve the values from the cache directly.
84+
// This matters for ie ModuleDatas where the storage.Bucket attached will have local paths
85+
// instead of empty local paths if read from the cache. We documment NewModuleDataProvider
86+
// to return a ModuleDataProvider that will always have local paths for returned storage.Buckets,
87+
// if the cache is an on-disk cache.
88+
var delegateNotFoundKeys []K
89+
delegateValues, delegateNotFoundKeys, err = p.storeGetValuesForKeys(ctx, notFoundKeys)
90+
if err != nil {
91+
return nil, err
92+
}
93+
// We need to ensure that all the delegate values can be retrieved from the store. If there
94+
// are unfound keys, we return an error.
95+
if len(delegateNotFoundKeys) > 0 {
96+
return nil, syserror.Newf(
97+
"delegate keys %v not found in the store after putting in the store",
98+
delegateNotFoundKeys,
99+
)
100+
}
83101

84102
p.keysRetrieved.Add(int64(len(keys)))
85103
p.keysHit.Add(int64(len(foundValues)))

private/bufpkg/bufmodule/bufmodulecache/module_data_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
// NewModuleDataProvider returns a new ModuleDataProvider that caches the results of the delegate.
2727
//
2828
// The ModuleDataStore is used as a cache.
29+
//
30+
// All files in returned [storage.Bucket]s will have local paths if the cache is on-disk.
2931
func NewModuleDataProvider(
3032
logger *slog.Logger,
3133
delegate bufmodule.ModuleDataProvider,

0 commit comments

Comments
 (0)