Repository navigation
#170 Cache server loose track of client known keys on concurrent fetch and invalidate - #173
Conversation
|
@diegosalvi @eolivelli thoughts on this? Using an actual lock would be impractical since we would need a lock for every key, or some kind of lock pool. |
| private final CacheClientStatisticsMXBean statisticsMXBean; | ||
| private final CacheClientStatusMXBean statusMXBean; | ||
| private EntrySerializer entrySerializer = new JDKEntrySerializer(); | ||
| private Set<RawString> lockedKeys = new HashSet<>(); |
| } | ||
|
|
||
| private void locallyLockKey(RawString key) { | ||
| synchronized (lockedKeys) { |
There was a problem hiding this comment.
aren't we serialising all the operations of the client ? we are not locking "per-key" here
IIRC in BlazingCache we already have good utilities for per-key locking, at least in the server
There was a problem hiding this comment.
It it serializing the whole server but just for the access at the lockedKeys set. Waiting threads won't block other to enter the serialization block and they will block only if can't add an element in lockedKeys
There was a problem hiding this comment.
We can use the server KeyedLockManager, but it will need some refactor (methods are package protected and ask for a clientId param which is never used)
There was a problem hiding this comment.
Idk if it's worth it. Even with that we will still serialize the lock creation/retrieval since all operations are guarded by a general lock
| } | ||
|
|
||
| private void locallyLockKey(RawString key) { | ||
| synchronized (lockedKeys) { |
There was a problem hiding this comment.
It it serializing the whole server but just for the access at the lockedKeys set. Waiting threads won't block other to enter the serialization block and they will block only if can't add an element in lockedKeys
8182bec to
9ad377f
Compare
|
@eolivelli PTAL when you can |
This PR aims to fix the bug #170 caused by concurrent fetches and invalidations.
Server-side we already have locks in place so an invalidate request for a given key can't be run concurrently to a fetch for the same key. The problem arises client-side, where the fetch code checks if fetch is still valid before actually storing the value.
The solution proposed here is to take a "lock" on the key whenever the fetch/invalidate actually tries to finish its cycle by consuming/removing the fetch from the runningFetches list and storing/removing the key from the local cache.
This patch picks up from @diegosalvi branch were he added a reproducer test
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.