Fix cahce bug introduced in 2.0.1

Partially chery-picked from f419c18056
This commit is contained in:
Ed Hennis
2026-02-19 18:21:02 +09:00
committed by tequ
parent 950f869715
commit 85838140fb

View File

@@ -63,20 +63,17 @@ CachedViewImpl::read(Keylet const& k) const
hits.increment();
else
misses.increment();
std::lock_guard lock(mutex_);
auto const er = map_.emplace(k.key, *digest);
bool const inserted = er.second;
if (sle && !k.check(*sle))
if (!cacheHit)
{
if (!inserted)
{
// On entry, this function did not find this key in map_. Now
// something (another thread?) has inserted the sle into the map and
// it has the wrong type.
LogicError("CachedView::read: wrong type");
}
return nullptr;
// Avoid acquiring this lock unless necessary. It is only necessary if
// the key was not found in the map_. The lock is needed to add the key
// and digest.
std::lock_guard lock(mutex_);
map_.emplace(k.key, *digest);
}
if (!sle || !k.check(*sle))
return nullptr;
return sle;
}