<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Guys, after investigating&nbsp;<a href="https://issues.jboss.org/browse/ISPN-2381">https://issues.jboss.org/browse/ISPN-2381</a>&nbsp;and&nbsp;<a href="https://github.com/infinispan/infinispan/pull/1382">https://github.com/infinispan/infinispan/pull/1382</a>, I've discovered a pretty nasty race condition in our per-entry lock containers (whether OwnableReentrantLocks or JDK locks for non-transactional caches).<div><br></div><div>The problem is that we maintain a lock map, and any given request can acquire a lock, if a lock doesn't exist for a given key, create the lock and acquire it, and when done, release the lock and remove it from the lock map. &nbsp;There's lots of room for races to occur. &nbsp;The current impl uses a ConcurrentMap, where concurrent operations on the map are used to make sure locks are not overwritten. &nbsp;But still, since the process of creating, acquiring and adding the lock to the lock map needs to be atomic, and not just atomic but also safe with regards to competing threads (say, an old owner) releasing the lock and removing it from the map (also atomic), I think a concurrent map isn't good enough anymore.</div><div><br></div><div>The sledgehammer approach is to synchronise on this map for these two operations, but that causes all sorts of suckage. &nbsp;Ideally, I'd just hold on to the segment lock for the duration of these operations, but these aren't exposed. &nbsp;Extending CHM to expose methods like&nbsp;acquireLockAndGet() and&nbsp;unlockAndRemove() would work perfectly, but again a lot of CHM internals are private or package protected.</div><div><br></div><div>So my options are: completely re-implement a CHM-like structure, like we've done for BCHM, or perhaps think of a new, specialised structure to contain locks. &nbsp;In terms of contract, I just need a fast way to look up a value under given a key, efficient put and remove as well. &nbsp;It should be thread-safe (naturally), and allow for an atomic operation (like "get, do work, put").</div><div><br></div><div>Any interesting new data structures on peoples' minds?</div><div><br></div><div>Cheers</div><div>Manik<br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Manik Surtani</div><div><a href="mailto:manik@jboss.org">manik@jboss.org</a></div><div><a href="http://twitter.com/maniksurtani">twitter.com/maniksurtani</a></div><div><br></div><div><div>Platform Architect, JBoss Data Grid</div><div><a href="http://red.ht/data-grid">http://red.ht/data-grid</a></div></div></div></span></div></span></div></span>
</div>
<br></div></body></html>