<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 17, 2013 at 1:59 PM, Mircea Markus <span dir="ltr">&lt;<a href="mailto:mmarkus@redhat.com" target="_blank">mmarkus@redhat.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On 17 May 2013, at 07:35, Dan Berindei &lt;<a href="mailto:dan.berindei@gmail.com">dan.berindei@gmail.com</a>&gt; wrote:<br>
<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Thu, May 16, 2013 at 8:27 PM, Mircea Markus &lt;<a href="mailto:mmarkus@redhat.com">mmarkus@redhat.com</a>&gt; wrote:<br>
&gt;<br>
&gt; On 16 May 2013, at 15:04, Dan Berindei &lt;<a href="mailto:dan.berindei@gmail.com">dan.berindei@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Hi guys<br>
&gt; &gt;<br>
&gt; &gt; I&#39;m working on an intermittent failure in NodeMoveAPIPessimisticTest and I think I&#39;ve come across what I think is underspecified behaviour in AtomicHashMap.<br>
&gt; &gt;<br>
&gt; &gt; Say we have two transactions, tx1 and tx2, and they both work with the same atomic map in a pessimistic cache:<br>
&gt; &gt;<br>
&gt; &gt; 1. tx1: am1 = AtomicMapLookup.get(cache, key)<br>
&gt; &gt; 2. tx2: am2 = AtomicMapLookup.get(cache, key)<br>
&gt; &gt; 3. tx1: am1.put(subkey1, value1) // locks the map<br>
&gt; &gt; 4. tx2: am2.get(subkey1) // returns null<br>
&gt; &gt; 5. tx1: commit // the map is now {subkey1=value1}<br>
&gt; &gt; 6. tx2: am2.put(subkey2, value2) // locks the map<br>
&gt; &gt; 7. tx2: commit // the map is now {subkey2=value2}<br>
&gt; &gt;<br>
&gt; &gt; It&#39;s not clear to me from the AtomicMap/AtomicHashMap javadoc if this is ok or if it&#39;s a bug...<br>
&gt; as a user I find that a bit confusing so I think tx2 should merge stuff in the AtomiMap.<br>
&gt; Id be curious to hear Manik(author) and Sanne&#39;s (user) opinion on this.<br>
&gt;<br>
&gt;<br>
&gt; Merging should work with pessimistic locking, but I don&#39;t think we could do it with optimistic locking and write skew check enabled: we only do the write skew check for the whole map.<br>
</div>if the WSC is enabled, then the 2nd transaction should fail: tx2 reads the version at 2. and at 7. The WSC should forbid it to commit, so I we shouldn&#39;t have this problem at all.<br></blockquote><div><br></div>

<div style>Right, the 2nd transaction must fail with WSC enabled, so we can&#39;t implement merging.</div><div style><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div class="im">&gt; Would it be worth making this change if it meant making the behaviour of AtomicHashMap more complex?<br>
</div>how more complex? If it&#39;s not a quick fix (2h) I&#39;d say no as this is more of a nice to have/no user requires this functionality ATM.<br></blockquote><div><br></div><div style>The behaviour of AtomicMap will be more complex because we&#39;re adding a bit of functionality that only works with pessimistic locking. Or maybe with optimistic locking as well, only not when write skew check is enabled.</div>

<div style><br></div><div style>This is definitely not a 2h fix. As you can see, it&#39;s taking more than 2h just to figure out what needs to change :)</div><div style>What other options do we have? Leave it as it is and document the limitation?</div>

<div style><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">&gt;<br>
&gt; On the other hand, I believe FineGrainedAtomicHashMap doesn&#39;t do separate write skew checks for each key in the map either, so users probably have to deal with this difference between pessimistic and optimistic locking already.<br>


</div>For FGAM I think the WSC should be performed on a per FGAM&#39;s key basis, and not for the whole map.<br></blockquote><div><br></div><div style>I agree, but I think implementing fine-grained WSC will be tricky. I&#39;ll create a feature request in JIRA.</div>

<div style><br></div><div style><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im HOEnZb">&gt;<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt; Note that today the map is overwritten by tx2 even without step 4 (&quot;tx2: am2.get(subkey1)&quot;). I&#39;m pretty sure that&#39;s a bug and I fixed it locally by using the FORCE_WRITE_LOCK in AtomicHashMapProxy.getDeltaMapForWrite.<br>


&gt; &gt;<br>
&gt; &gt; 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&#39;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>


&gt; &gt;<br>
&gt;<br>
&gt; I tried using the FORCE_WRITE_LOCKS flag for all TreeCache reads. This seems to work fine, and move() doesn&#39;t throw any exceptions in pessimistic mode any more. In optimistic mode, it doesn&#39;t change anything, and concurrent moves still fail with WriteSkewException. The only downside is the performance, having extra locks will certainly slow things down.<br>


&gt;<br>
</div><div class="HOEnZb"><div class="h5">&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
Cheers,<br>
--<br>
Mircea Markus<br>
Infinispan lead (<a href="http://www.infinispan.org" target="_blank">www.infinispan.org</a>)<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br></div></div>