<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 16 May 2013, at 15:04, Dan Berindei &lt;<a href="mailto:dan.berindei@gmail.com">dan.berindei@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div><div><div><div><div><div><div><div><div>Hi guys<br><br></div>I'm working on an intermittent failure in NodeMoveAPIPessimisticTest and I think I've come across what I think is underspecified behaviour in AtomicHashMap.<br>

<br></div>Say we have two transactions, tx1 and tx2, and they both work with the same atomic map in a pessimistic cache:<br><br></div>1. tx1: am1 = AtomicMapLookup.get(cache, key)<br></div>2. tx2: am2 = AtomicMapLookup.get(cache, key)<br>

</div>3. tx1: am1.put(subkey1, value1) // locks the map<br></div>4. tx2: am2.get(subkey1) // returns null<br></div>5. tx1: commit // the map is now {subkey1=value1}<br></div>6. tx2: am2.put(subkey2, value2) // locks the map<br>

</div>7. tx2: commit // the map is now {subkey2=value2}<br><div><br><div><div>It's not clear to me from the AtomicMap/AtomicHashMap javadoc if this is ok or if it's a bug...<br></div></div></div></div></blockquote><div><br></div><div>If optimistic, step 7 should fail with a write skew check. &nbsp;If pessimistic, step 2 would *usually* block assuming that another thread is updating the map, but since neither tx1 or tx2 has started updating the map yet, neither has a write lock on the map. &nbsp;So that succeeds. &nbsp;I'm not sure if this is any different from not using an atomic map:</div><div><br></div><div>1. &nbsp;tx1: cache.get(k, v); // reads into tx context</div><div>2. &nbsp;tx2: cache.get(k, v);</div><div>3. &nbsp;tx1: cache.put(k, v + 1 );</div><div>4. &nbsp;tx1: commit</div><div>5. &nbsp;tx2: cache.put(k, v + 1 );</div><div>6. &nbsp;tx2: commit</div><div><br></div><div>here as well, if using optimistic, step 6 will fail with a WSC but if pessimistic this will work (since tx2 only requested a write lock after tx1 committed/released its write lock).</div><br><blockquote type="cite"><div dir="ltr"><div><div><div>Note that today the map is overwritten by tx2 even without step 4 ("tx2: am2.get(subkey1)"). I'm pretty sure that's a bug and I fixed it locally by using the FORCE_WRITE_LOCK in AtomicHashMapProxy.getDeltaMapForWrite.&nbsp;</div><div>

<br>However, when the Tree API moves a node it first checks for the existence of the destination node, which means NodeMoveAPIPessimisticTest is still failing. I'm not sure if I should fix that by forcing a write lock for all AtomicHashMap reads, for all TreeCache reads, or only in TreeCache.move().<br></div></div></div></div></blockquote><div><br></div>I think only in TreeCache.move()</div><div><br></div><div><br></div><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></body></html>