Skip to content

Commit

Permalink
Correctly count number of items in LRU (#8742) (#8754)
Browse files Browse the repository at this point in the history
* Updated test to reflect counting issue

* Only increment and adjust size on Add

* Updated LRU count computation logic

Co-authored-by: Koen <koen@bpk.ltd>
  • Loading branch information
ReubenBond and koenbeuk committed Dec 2, 2023
1 parent 8f73d43 commit 236b398
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Orleans.Core/Utils/LRU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public TValue AddOrUpdate<TState>(TKey key, Func<TState, TKey, TValue> addFunc,
key,
static (key, state) =>
{
var (outerState, addFunc, generation) = state;
var (_, outerState, addFunc, generation) = state;
return new TimestampedValue(addFunc(outerState, key), generation);
},
static (key, existing, state) =>
{
var (outerState, addFunc, generation) = state;
return new TimestampedValue(addFunc(outerState, key), generation);
var (self, outerState, addFunc, generation) = state;
return new TimestampedValue(addFunc(outerState, key), self.GetNewGeneration());
},
(State: state, AddFunc: addFunc, Generation: generation));
(Self: this, State: state, AddFunc: addFunc, Generation: generation));

var result = storedValue.Value;

Expand Down
3 changes: 3 additions & 0 deletions test/NonSilo.Tests/General/LruTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public void LruCountTest()

target.Add("2", "two");
Assert.Equal(2, target.Count); // "Count wrong after adding two items"

target.AddOrUpdate("2", "two");
Assert.Equal(2, target.Count); // "Count wrong after updating existing item"
}

[Fact, TestCategory("BVT"), TestCategory("LRU")]
Expand Down

0 comments on commit 236b398

Please sign in to comment.