Problem:
Every time we make a put the code in BucketRegion.searchAndLock and
BucketRegion.removeAndNotifyKeys locks (synchronized) on a hash map, the
allKeysMap, to checkout the key to be modified and prevent anyone else from
updating at the same time. This area of the code gets a lot of contention,
especially if the same keys are getting checked out.
Deeper Problem:
In trying to fix this, I would like to use a different data structure, like a
ConcurrentHashMap but am running across a problem. It seems that when we want
to put a single item, we end up calling the same code that putAll calls, and we
just wrap the single key in an array. It further seems that the entire
allKeysMap is synchronized because we want to lock multiple keys at the same
time and do the putAll ‘atomically.’
Question
Is there any reason that putAll needs to lock all the keys and insert at the
same-ish time. Could putAll be turned into something that looked like:
public void putAll(entries)
for(Entry entry: entries)
put(entry.key, entry.value)
Or is it important that they all happen together? Does putAll guarantee some
kind of transactional properties?
An analogy
Imagine a restaurant (our hash map) that has a bunch of tables built for 1
person (think classroom chairs with a pull out desk). PutAll is like coming to
this restaurant and asking for a table for four people. Now someone has to go,
find four tables, pull them together, etc…you know how it goes.
Any help is appreciated.
Thanks,
Murtuza
https://issues.apache.org/jira/browse/GEODE-6637