Skip to content

Conversation

@bitfaster
Copy link
Owner

@bitfaster bitfaster commented Oct 18, 2023

This test exposed a bug - there was logic missing to handle nodes being removed while being read/updated.

In this case, the node was previously in probation, so Position=Probation, and the node's list is null (since it was removed). The debug assert attempts to verify that the probation node is attached to the list, which it is not.

Error Message:
   System.InvalidOperationException : Node is already attached to a different list.
  Stack Trace:
     at BitFaster.Caching.Throw.InvalidOp(String message) in /_/BitFaster.Caching/Throw.cs:line 29
   at BitFaster.Caching.Lfu.LfuNodeList`2.ValidateNode(LfuNode`2 node) in /_/BitFaster.Caching/Lfu/LfuNodeList.cs:line 140
   at BitFaster.Caching.Lfu.LfuNodeList`2.Remove(LfuNode`2 node) in /_/BitFaster.Caching/Lfu/LfuNodeList.cs:line 61
   at BitFaster.Caching.Lfu.ConcurrentLfu`2.PromoteProbation(LfuNode`2 node) in /_/BitFaster.Caching/Lfu/ConcurrentLfu.cs:line 691
   at BitFaster.Caching.Lfu.ConcurrentLfu`2.OnWrite(LfuNode`2 node) in /_/BitFaster.Caching/Lfu/ConcurrentLfu.cs:line 679
   at BitFaster.Caching.Lfu.ConcurrentLfu`2.Maintenance(LfuNode`2 droppedWrite) in /_/BitFaster.Caching/Lfu/ConcurrentLfu.cs:line 588
   at BitFaster.Caching.Lfu.ConcurrentLfu`2.AfterWrite(LfuNode`2 node) in /_/BitFaster.Caching/Lfu/ConcurrentLfu.cs:line 470
   at BitFaster.Caching.Lfu.ConcurrentLfu`2.TryAdd(K key, V value) in /_/BitFaster.Caching/Lfu/ConcurrentLfu.cs:line 205
   at BitFaster.Caching.Lfu.ConcurrentLfu`2.GetOrAdd(K key, Func`2 valueFactory) in /_/BitFaster.Caching/Lfu/ConcurrentLfu.cs:line 224
   at BitFaster.Caching.UnitTests.Lfu.ConcurrentLfuSoakTests.<>c__DisplayClass7_0.<WhenConcurrentGetAndUpdateCacheEndsInConsistentState>b__0() in D:\a\BitFaster.Caching\BitFaster.Caching\BitFaster.Caching.UnitTests\Lfu\ConcurrentLfuSoakTests.cs:line 125

@bitfaster bitfaster changed the title soak lfu add soak lfu add + fix detached nodes Oct 23, 2023
@bitfaster bitfaster marked this pull request as ready for review October 23, 2023 07:22
@coveralls
Copy link

Coverage Status

coverage: 98.582% (+0.2%) from 98.344% when pulling dfd03ce on users/alexpeck/soaklfuadd into 60e78bf on main.

@bitfaster bitfaster merged commit 393458b into main Oct 23, 2023
@bitfaster bitfaster deleted the users/alexpeck/soaklfuadd branch October 23, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants