<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 25 Sep 2012, at 17:07, Sanne Grinovero &lt;<a href="mailto:sanne@infinispan.org">sanne@infinispan.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On 25 September 2012 16:41, Galder Zamarreño &lt;<a href="mailto:galder@redhat.com">galder@redhat.com</a>&gt; wrote:<br><blockquote type="cite"><br>On Sep 25, 2012, at 4:51 PM, Manik Surtani &lt;<a href="mailto:manik@jboss.org">manik@jboss.org</a>&gt; wrote:<br><br><blockquote type="cite"><br>On 25 Sep 2012, at 13:48, Galder Zamarreño &lt;<a href="mailto:galder@redhat.com">galder@redhat.com</a>&gt; wrote:<br><br><blockquote type="cite"><br>On Sep 24, 2012, at 12:27 PM, Manik Surtani &lt;<a href="mailto:manik@jboss.org">manik@jboss.org</a>&gt; wrote:<br><br><blockquote type="cite"><br>On 24 Sep 2012, at 11:01, Galder Zamarreño &lt;<a href="mailto:galder@redhat.com">galder@redhat.com</a>&gt; wrote:<br><br><blockquote type="cite"><br>On Sep 21, 2012, at 3:43 PM, Sanne Grinovero &lt;<a href="mailto:sanne@infinispan.org">sanne@infinispan.org</a>&gt; wrote:<br><br><blockquote type="cite">On 20 September 2012 17:38, Andrig Miller &lt;<a href="mailto:anmiller@redhat.com">anmiller@redhat.com</a>&gt; wrote:<br><blockquote type="cite"><br><br>----- Original Message -----<br><blockquote type="cite">From: "Galder Zamarreño" &lt;<a href="mailto:galder@redhat.com">galder@redhat.com</a>&gt;<br>To: "Andrig Miller" &lt;<a href="mailto:anmiller@redhat.com">anmiller@redhat.com</a>&gt;<br>Cc: "Steve Ebersole" &lt;<a href="mailto:steve@hibernate.org">steve@hibernate.org</a>&gt;, "John O'Hara" &lt;<a href="mailto:johara@redhat.com">johara@redhat.com</a>&gt;, "Jeremy Whiting"<br>&lt;<a href="mailto:jwhiting@redhat.com">jwhiting@redhat.com</a>&gt;, "infinispan -Dev List" &lt;<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a>&gt;<br>Sent: Thursday, September 20, 2012 6:48:59 AM<br>Subject: Re: [infinispan-dev] Issue with cache blocks for local read-only cache<br><br><br>On Sep 19, 2012, at 4:20 PM, Andrig Miller &lt;<a href="mailto:anmiller@redhat.com">anmiller@redhat.com</a>&gt;<br>wrote:<br><br><blockquote type="cite">Yes, I can see how that can happen, if the data is deleted from<br>outside the application.<br></blockquote><br>^ The issue does not only happen if the data is deleted outside the<br>application. As indicated in<br><a href="https://hibernate.onjira.com/browse/HHH-3817">https://hibernate.onjira.com/browse/HHH-3817</a>, this can happen with<br>two competing transactions.<br><br><blockquote type="cite">If you cache something as READ_ONLY, and it gets deleted, that<br>doesn't fit the definition of READ_ONLY though. &nbsp;You are using the<br>wrong cache concurrency strategy.<br><br>Even that issue outlines the scenario where the collection is<br>updated, which means its not a READ_ONLY.<br></blockquote><br>I think the update is irrelevant here. The issue is related to<br>putFromLoad + remove, which both AFAIK, are allowed in READ_ONLY<br>(remember that we had the discussion on whether remove should be<br>allowed in a READ_ONLY cache:<br><a href="https://hibernate.onjira.com/browse/HHH-7350">https://hibernate.onjira.com/browse/HHH-7350</a>).<br><br></blockquote><br>Yes, remove can be done, its just update that matters to READ_ONLY. &nbsp;One thing I thought about was I thought we were using MVCC for this stuff. &nbsp;Any transaction that reads from the cache, while something is being added/removed, should be reading the read consistent image, and should never wait on a lock, correct? &nbsp;We see all the threads in our thread pool sitting in a blocked state based on this locking.<br></blockquote></blockquote><br>I'm not 100% sure which locking are you talking about, but if you're refering to the lock in <a href="https://dl.dropbox.com/u/30971563/specjent_block.png">https://dl.dropbox.com/u/30971563/specjent_block.png</a>, that's related to the 2LC integration, not Infinispan itself.<br></blockquote><br>Yes, we're analysing the 2LC impl as well as Infinispan.<br><br><blockquote type="cite">If you're talking about threads waiting for a lock somewhere else, please provide more details.<br><br>I have some short-term ideas to improve the 2LC integration code, but I wanna check with Brian first.<br><br>Long term, I think <a href="https://issues.jboss.org/browse/ISPN-506">https://issues.jboss.org/browse/ISPN-506</a> will be necessary to provide a lock-free solution to these edge cases in such way that 'newer' removes cannot be overridden by 'old' putFromLoad calls. However, I'm intrigued by the fact that JBoss Cache OL had the capability of being given a version externally, but the 2LC code for JBoss Cache OL still used this PutFromLoadValidator logic. Again, something I need to check with Brian.<br></blockquote><br>ISPN-506 will only help in the clustered case.<br></blockquote><br>^ I disagree. It might help with the edge case highlighted in <a href="https://hibernate.onjira.com/browse/HHH-3817">https://hibernate.onjira.com/browse/HHH-3817</a> which happens in a local cache.<br></blockquote><br>There is a much easier way to solve this: pessimistic locking + an eager cache.lock() command before retrieving the collection from the database. &nbsp;This will prevent the race defined in the HHH-3817.<br></blockquote><br>Hmmm, I'm not so sure about that. It's an interesting idea but let me explain what PFLV does so that the rest understand:<br><br>What PutFromLoadValidator does is the following: if cache.get() misses, it assumes there might a putFromLoad() coming. This put might never come (i.e. if the database has no data, but this will eventually be cleaned up), but it offers up a barrier in case a removal comes before the actual putFromLoad(). The effect is that if the removal comes before putFromLoad(), it will invalidate the put and when putFromLoad() comes, it won't be able to store stale things in memory. If the removal comes after putFromLoad(), then not a problem.<br></blockquote><br>Is this limited to removal of entries only? Looks like a similar<br>pattern could happen with any update.<br><br><blockquote type="cite">So, I see some problems with lock:<br><br>1. Can you lock() a non-existing key? (quickly browsed the code and couldn't say for certain…). Even if you can, 2 consecutive lock() calls for the same key from different threads would result in 2nd thread blocking. Definitely not good for a get() op.<br></blockquote><br>Good point, I hope we can lock() a non-existing key as that's useful<br>for many other cases; shouldn't be hard since we decoupled the lock<br>from the entries for the single-lock owner design.<br></blockquote><div><br></div><div>Yes we can. &nbsp;The lock is held on the key.</div><br><blockquote type="cite">Anyway, this is a lock which is going to operate on a specific key.<br>Definitely better than the global lock we're experiencing today!<br></blockquote><div><br></div><div>Yep.</div><br><blockquote type="cite">The comments in the code seem to remind a per-key lock isn't being<br>used as a deadlock could happen; can't we just reorder the keys to be<br>locked?<br><br><blockquote type="cite">2. How do you unlock the key if after a while there has not been a putFromLoad()? We have no unlock() call.<br></blockquote><br>I wouldn't lock it but put a marker in it, you could even store a<br>version in your marker.. the marker will eventually be evicted if not useful.<br></blockquote><div><br></div><div>… and the lock is released when your tx completes (successfully or not).</div><br><blockquote type="cite"><br><blockquote type="cite"><br>3. This is a solution that still requires locking. A lock-free solution, where we can capture the version when an entry is going to be deleted (via lockItem() implementation in 2LC), and we can compare it with the one from the putFromLoad() would surely be performant IMO. Btw, I've assigned <a href="https://issues.jboss.org/browse/ISPN-506">https://issues.jboss.org/browse/ISPN-506</a> to myself in order to investigate this and move towards such a solution.<br><br>Cheers,<br><br><blockquote type="cite"><br>--<br>Manik Surtani<br><a href="mailto:manik@jboss.org">manik@jboss.org</a><br>twitter.com/maniksurtani<br><br>Platform Architect, JBoss Data Grid<br>http://red.ht/data-grid<br><br>_______________________________________________<br>infinispan-dev mailing list<br>infinispan-dev@lists.jboss.org<br>https://lists.jboss.org/mailman/listinfo/infinispan-dev<br></blockquote><br><br>--<br>Galder Zamarreño<br><a href="mailto:galder@redhat.com">galder@redhat.com</a><br>twitter.com/galderz<br><br>Project Lead, Escalante<br>http://escalante.io<br><br>Engineer, Infinispan<br>http://infinispan.org<br><br><br>_______________________________________________<br>infinispan-dev mailing list<br>infinispan-dev@lists.jboss.org<br>https://lists.jboss.org/mailman/listinfo/infinispan-dev<br></blockquote><br>_______________________________________________<br>infinispan-dev mailing list<br><a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/infinispan-dev</blockquote></div><br><div apple-content-edited="true">
<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-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>