@@ -668,7 +668,7 @@ class CNodeMapping : public HTMapping<CNodeCacheEntry, CKeyIdAndPos>
668
668
};
669
669
670
670
typedef OwningSimpleHashTableOf<CNodeMapping, CKeyIdAndPos> CNodeTable;
671
- class CNodeMRUCache : public CMRUCacheOf <CKeyIdAndPos, CNodeCacheEntry, CNodeMapping, CNodeTable>
671
+ class CNodeMRUCache final : public CMRUCacheOf<CKeyIdAndPos, CNodeCacheEntry, CNodeMapping, CNodeTable>
672
672
{
673
673
std::atomic<size32_t > sizeInMem{0 };
674
674
size32_t memLimit = 0 ;
@@ -684,15 +684,31 @@ class CNodeMRUCache : public CMRUCacheOf<CKeyIdAndPos, CNodeCacheEntry, CNodeMap
684
684
virtual void makeSpace ()
685
685
{
686
686
// remove LRU until !full
687
+ // This code could walk the list, rather than restarting at the end each time - but there are unlikely to be
688
+ // many entries that have no associated node, and nodes could have been associated in the meantime.
687
689
do
688
690
{
689
- // Never evict an entry that hasn't yet loaded - otherwise the sizeInMem can become inconsistent
690
691
CNodeMapping *tail = mruList.tail ();
691
- assertex (tail);
692
- if (!tail->queryElement ().isReady () )
693
- break ;
692
+ if (unlikely (!tail))
693
+ throw makeStringExceptionV (9999 , " Index cache appears full but contains no entries size=%x limit=%x" , sizeInMem.load (), memLimit);
694
+
695
+ // Never evict an entry that hasn't yet loaded - otherwise the sizeInMem can become inconsistent
696
+ // When running with slow remote storage this can take a long time to be ready - so we need
697
+ // to walk on to the next entry in the lrulist, otherwise we can run out of memory since nothing
698
+ // would be removed.
699
+ while (!tail->queryElement ().isReady ())
700
+ {
701
+ tail = tail->prev ;
702
+ if (!tail)
703
+ {
704
+ // no pages in the cache are ready - this could possibly happen in a tiny race-window where
705
+ // sizes in the cache have been updated, but no nodes have yet been associated with the entries.
706
+ return ;
707
+ }
708
+ }
694
709
695
- clear (1 );
710
+ mruList.remove (tail);
711
+ table.removeExact (tail);
696
712
}
697
713
while (full ());
698
714
}
0 commit comments