@@ -306,7 +306,7 @@ StringSet Store::Config::getDefaultSystemFeatures()
306
306
Store::Store (const Store::Config & config)
307
307
: StoreDirConfig{config}
308
308
, config{config}
309
- , state({( size_t ) config.pathInfoCacheSize } )
309
+ , pathInfoCache(make_ref< decltype (pathInfoCache)::element_type>(( size_t ) config.pathInfoCacheSize) )
310
310
{
311
311
assertLibStoreInitialized ();
312
312
}
@@ -326,7 +326,7 @@ bool Store::PathInfoCacheValue::isKnownNow()
326
326
327
327
void Store::invalidatePathInfoCacheFor (const StorePath & path)
328
328
{
329
- state. lock ()->pathInfoCache . erase (path.to_string ());
329
+ pathInfoCache-> lock ()->erase (path.to_string ());
330
330
}
331
331
332
332
std::map<std::string, std::optional<StorePath>> Store::queryStaticPartialDerivationOutputMap (const StorePath & path)
@@ -448,22 +448,18 @@ void Store::querySubstitutablePathInfos(const StorePathCAMap & paths, Substituta
448
448
449
449
bool Store::isValidPath (const StorePath & storePath)
450
450
{
451
- {
452
- auto state_ (state.lock ());
453
- auto res = state_->pathInfoCache .get (storePath.to_string ());
454
- if (res && res->isKnownNow ()) {
455
- stats.narInfoReadAverted ++;
456
- return res->didExist ();
457
- }
451
+ auto res = pathInfoCache->lock ()->get (storePath.to_string ());
452
+ if (res && res->isKnownNow ()) {
453
+ stats.narInfoReadAverted ++;
454
+ return res->didExist ();
458
455
}
459
456
460
457
if (diskCache) {
461
458
auto res = diskCache->lookupNarInfo (
462
459
config.getReference ().render (/* FIXME withParams=*/ false ), std::string (storePath.hashPart ()));
463
460
if (res.first != NarInfoDiskCache::oUnknown) {
464
461
stats.narInfoReadAverted ++;
465
- auto state_ (state.lock ());
466
- state_->pathInfoCache .upsert (
462
+ pathInfoCache->lock ()->upsert (
467
463
storePath.to_string (),
468
464
res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{}
469
465
: PathInfoCacheValue{.value = res.second });
@@ -518,30 +514,25 @@ std::optional<std::shared_ptr<const ValidPathInfo>> Store::queryPathInfoFromClie
518
514
{
519
515
auto hashPart = std::string (storePath.hashPart ());
520
516
521
- {
522
- auto res = state.lock ()->pathInfoCache .get (storePath.to_string ());
523
- if (res && res->isKnownNow ()) {
524
- stats.narInfoReadAverted ++;
525
- if (res->didExist ())
526
- return std::make_optional (res->value );
527
- else
528
- return std::make_optional (nullptr );
529
- }
517
+ auto res = pathInfoCache->lock ()->get (storePath.to_string ());
518
+ if (res && res->isKnownNow ()) {
519
+ stats.narInfoReadAverted ++;
520
+ if (res->didExist ())
521
+ return std::make_optional (res->value );
522
+ else
523
+ return std::make_optional (nullptr );
530
524
}
531
525
532
526
if (diskCache) {
533
527
auto res = diskCache->lookupNarInfo (config.getReference ().render (/* FIXME withParams=*/ false ), hashPart);
534
528
if (res.first != NarInfoDiskCache::oUnknown) {
535
529
stats.narInfoReadAverted ++;
536
- {
537
- auto state_ (state.lock ());
538
- state_->pathInfoCache .upsert (
539
- storePath.to_string (),
540
- res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{}
541
- : PathInfoCacheValue{.value = res.second });
542
- if (res.first == NarInfoDiskCache::oInvalid || !goodStorePath (storePath, res.second ->path ))
543
- return std::make_optional (nullptr );
544
- }
530
+ pathInfoCache->lock ()->upsert (
531
+ storePath.to_string (),
532
+ res.first == NarInfoDiskCache::oInvalid ? PathInfoCacheValue{}
533
+ : PathInfoCacheValue{.value = res.second });
534
+ if (res.first == NarInfoDiskCache::oInvalid || !goodStorePath (storePath, res.second ->path ))
535
+ return std::make_optional (nullptr );
545
536
assert (res.second );
546
537
return std::make_optional (res.second );
547
538
}
@@ -577,10 +568,7 @@ void Store::queryPathInfo(const StorePath & storePath, Callback<ref<const ValidP
577
568
if (diskCache)
578
569
diskCache->upsertNarInfo (config.getReference ().render (/* FIXME withParams=*/ false ), hashPart, info);
579
570
580
- {
581
- auto state_ (state.lock ());
582
- state_->pathInfoCache .upsert (storePath.to_string (), PathInfoCacheValue{.value = info});
583
- }
571
+ pathInfoCache->lock ()->upsert (storePath.to_string (), PathInfoCacheValue{.value = info});
584
572
585
573
if (!info || !goodStorePath (storePath, info->path )) {
586
574
stats.narInfoMissing ++;
@@ -803,10 +791,7 @@ StorePathSet Store::exportReferences(const StorePathSet & storePaths, const Stor
803
791
804
792
const Store::Stats & Store::getStats ()
805
793
{
806
- {
807
- auto state_ (state.readLock ());
808
- stats.pathInfoCacheSize = state_->pathInfoCache .size ();
809
- }
794
+ stats.pathInfoCacheSize = pathInfoCache->readLock ()->size ();
810
795
return stats;
811
796
}
812
797
0 commit comments