Comments (9)
You beat me to it - I was going to try with ForegroundScheduler
.
I think the reason ForegroundScheduler
is working and BackgroundThreadScheduler
fails (even when calling Clear
twice) is due to a bug - the Clear
method is immediately purging the write buffer which contains the removed items that were just added by TryRemove
- they are removed before they have been processed in the background. Foreground scheduler works because TryRemove is fully completed before the write buffer is cleared.
What isn't clear to me is how the unit test for this can pass. I will debug this in detail.
from bitfaster.caching.
I looked at this some more yesterday - the code is wrong and leaves orphan nodes in the window/probation/protected LRUs. These are the bogus items you observed in the probation LRU.
The unit test I have passes because it only validates via the count and whether the removed keys exist. Both count and exists are based on the internal dictionary. Clear
internally calls TryRemove
which immediately removes the key from the dictionary (thus test criteria is met and the unit test passes). TryRemove
also stores a record of removal in the write buffer (so the LRUs can be cleaned up by maintenance later). But since Clear
immediately drops the buffers before maintenance, orphans are left behind in window/probation/protected. These are not observable by the test when performing only a single iteration of clear.
In your test, it is possible background maintenance runs before Clear
drops the write buffer (so it can pass sometimes). If maintenance doesn't run, orphans are left behind and subsequent iterations build up more orphans. Since Clear
will attempt to Trim n cache entries, the orphans with dupe keys will be processed ahead of other valid items that appear in the list after n items are processed. For example, let's say the cache is size 3 and contains keys [a, b, c]
, but the probation LRU ends up with orphans of key a, so contains [a, a, a, b, c]
. Trim will take n=3 candidates from probation, then attempt to remove key a
3 times. The next time around, it may have cleared all the orphans and produce a valid result, so it works intermittently.
I will fix this so that the write buffer items are not dropped. I will also implement an integrity check in the tests to validate the internal data structures are in a consistent state to prevent re-introducing this bug. Last month I added some soak tests for ConcurrentLru
(multi-threaded tests that interleave different read/write method pairs), I will also get this done for LFU and check for any other similar bugs.
from bitfaster.caching.
Update: I tested with ForegroundScheduler
, and that makes the test green of course, which means that the test doesn't reflect the real-world situation, where BackgroundThreadScheduler
supposedly never gets around to clean things up.
from bitfaster.caching.
I would have thought that calling Clear
multiple times would work, since it calls Maintenance
internally, which also is what the background scheduler does.
from bitfaster.caching.
Hey @bitfaster! 👋🏻
I think we're bumping up against the same bug. Can you confirm this also affects ConcurrentLru<K, V>
?
Is there a workaround? Looping through entries and calling TryRemove
?
We're using v2.2.1.
UPDATE: Looping with TryRemove
seems to leave the cache in a broken state as well 😅
from bitfaster.caching.
Moved repro to #402
from bitfaster.caching.
Moved repro to #402
from bitfaster.caching.
Moved repro to #402
from bitfaster.caching.
@khellang I created a new issue for ConcurrentLru here #402, and copied over all your notes.
from bitfaster.caching.
Related Issues (20)
- FastConcurrentTLru's Constructor timetolive is not precise on liunx mac platform HOT 7
- Any plans to evict expired items on the background? HOT 2
- Expiration based on a Value's property? HOT 2
- NuGet package is missing intellisense xml file HOT 1
- Use NonBlocking instead of ConcurrentDictionary HOT 1
- [Feature request] individual items expiry HOT 1
- Current time provider HOT 6
- [Feature request] Allow to pass additional factory argument to the `GetOrAdd`/`GetOrAddAsync` cache methods HOT 2
- Entry left in cache configured with WithAtomicGetOrAdd when value factory throws HOT 4
- [Feature request] Atomic TryRemove HOT 3
- [Feature request] Expire after access LRU HOT 5
- [Feature request] Add TryRemove(K, out V) overload HOT 1
- [Feature request] Add MRU cache HOT 3
- [Bug] Cold queue increases infinitely for some partitions and cache sizes HOT 3
- [Feature Request] Add TryRemove(KeyValuePair<K, V>) overload HOT 2
- Clearing ConcurrentLru leaves cache in broken state HOT 7
- `cache.Clear()` doesn't seem to be clearing entire cache HOT 6
- Is it possible to disable the eviction? HOT 2
- Doesn't look like capacity expiration/evicting is happening properly (might be specific to the initial population of the warm queue) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitfaster.caching.