neo4j/neo4j — pull request #1208 by tinwelint (2013-09-19 12:47:17+00:00)
Title: Removed lock striping when loading nodes/relationships

Previously, loading a node or relationships had the loading code wrapped in a lock, striped on the key
where there were an arbitrary number of stripes. The lock would prevent multiple threads to load the
same entity at the same time, or more specifically prevent multiple threads to put two versions of the
same entity into the cache at the same time.

So without the lock there can be thread T1 loading an entity into an entity object E1 at the same time
as thread T2 loading the same entity into another entity object E2. E1 and E2 represent the same entity E.
This race would have one of the threads win and have its version put in the cache last,
the other overwritten. Consider the similarities of that race with cache eviction coming into play,
where T1 loads E1 and puts it in cache and returns it. After that and before T2 comes in
and wants that same entity there has been an eviction of E1. T2 would then load E2 and
put into cache resulting in two "live" versions of E. It seems that having the lock would merely
reduce the chance for this happening, not prevent it.

There doesn't seem to be any reason as to why having two versions of the same entity object would cause
problems (keep in mind that there will only be one version in the cache). Also, the overhead of locking
grows with the number of threads/cores to eventually become a bottle neck.

Based on that the locking was removed.

Also, to support this the Cache#put contract and method signature has
changed to return any existing element with the same ID instead of
overwriting what's there.

co-author: Johan Svensson, @johan-neo