<div class="gmail_extra"><div class="gmail_quote">On Thu, Nov 22, 2012 at 3:31 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 style="word-wrap:break-word"><br><div><div class="im"><div>On 22 Nov 2012, at 10:16, Dan Berindei wrote:</div><br><blockquote type="cite"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 22, 2012 at 11:53 AM, Galder Zamarreņo <span dir="ltr">&lt;<a href="mailto:galder@redhat.com" target="_blank">galder@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><br>
On Nov 21, 2012, at 4:49 PM, Mircea Markus &lt;<a href="mailto:mmarkus@redhat.com" target="_blank">mmarkus@redhat.com</a>&gt; wrote:<br>
<br>
&gt; Hi,<br>
&gt;<br>
&gt; Part of fixing ISPN-2435, I need to significantly change DistributionInterceptor which at the moment is a very complex pice of code. Building the fix on top of it is extremely difficult and error prone, so I need to refactor it a bit before moving forward.<br>


&gt; One such refactoring is about changing the way the async operations are handled (e.g. putAsync()). At the moment all the interceptor calls happen in user&#39;s thread, but two remote calls which are invoked with futures and aggregated:<br>


&gt; the L1 invalidation and the actual distribution call. The code for handling this future aggregation is rather complicated and spreads over multiple classes (RpcManager, L1Manager, ReplicationInterceptor, DistributionInterceptor), so the simple alternative solution I have in mind is to build an asycPut on top of a syncPut and wrap it in a future:<br>


&gt;<br>
&gt; CacheImpl:putAsync(k,v) {<br>
&gt;     final InvocationContext ic = createInvocatinonContextInCallerThread(); //this is for class loading purpose<br>
&gt;     return asyncPoolExecutor.submit(new Callable() {<br>
&gt;          public Object call() {<br>
&gt;              return put(k,v, ic); //this is the actual sync put<br>
&gt;          }<br>
&gt;     }<br>
&gt; }<br>
&gt;<br>
&gt; This would significantly simplify several components ( no references to network/aggregated futures in RpcManager, L1Manager, ReplicationInterceptor, DistributionInterceptor).<br>
<br>
</div>^ At first glance, that&#39;s how I&#39;d have implemented this feature, but Manik went down the route of wrapping in futures only those operations that went remote.<br>
<br>
Maybe he was worried about ctx switch cost? Or maybe about ownership of locks when these are acquired in a separate thread from the actual caller thread?<br></blockquote><div><br>Speaking of locks, does putAsync make sense in a transactional context?</div>
</div></div></blockquote></div>Good point, I don&#39;t think async operation should work in the context of transaction: that would mean having two threads(the async operation thread and the &#39;main&#39; thread) working on the same javax.transaction.Transaction object concurrently which is something not supported by most TM afaik, and something we don&#39;t support internally. </div>
<div><div class="h5"><div><br></div></div></div></div></blockquote><div><br>I&#39;m not sure, but I think it is supported now - the only things happening on a different thread only care about the cache&#39;s transaction, and not about the TM transaction.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="h5"><div><blockquote type="cite"><div class="gmail_extra">
<div class="gmail_quote"><div>
<br>There may be another backwards compatibility issue here, with listeners that expect to be called on the caller&#39;s thread (e.g. to use the TM transaction that&#39;s stored in a thread-local).<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><br>
&gt; Possible issues:<br>
&gt; - caller&#39;s class loader - the class loader is aggregated in the InvocationContext, so as long as we build the class loader in caller&#39;s thread we should be fine<br>
<br>
</div>^ To be precise, we don&#39;t build a class loaders. I guess you&#39;re refering at building the invocation context.<br>
<br>
These days we&#39;re more tight wrt the classloader used, avoiding the reliance on the TCCL, so I think we&#39;re in a safer position.<br>
<div><br>
&gt; - IsMarshallableInterceptor is used with async marshalling, in order to notify the user when objects added to the cache are not serializable. With the approach I suggested, for async calls only (e.g. putAsync) this notification would not happen in caller&#39;s thread, but async on future.get(). I really don&#39;t expect users to rely on this functionality, but something that would change never the less.<br>


<br>
</div>^ I don&#39;t think this is crucial. You need to call future.get() to find out if things worked correctly or not, regardless of cause.<br>
<div><br>
&gt; - anything else you can think of?<br>
&gt;<br>
&gt; I know this is a significant change at this stage in the project, so I really tried to go without it - but that resulted in spaghetti code taking a lot of time to patch. So instead of spending that time to code a complex hack I&#39;d rather go for the simple and nice solution and add more unit tests to prove it works.<br>


<br>
</div>^ Have you done some experimenting already?<br>
<br>
Cheers,<br>
<div><br>
&gt;<br>
&gt; Cheers,<br>
&gt; --<br>
&gt; Mircea Markus<br>
&gt; Infinispan lead (<a href="http://www.infinispan.org/" target="_blank">www.infinispan.org</a>)<br>
&gt;<br>
&gt;<br></div></blockquote></div></div></blockquote></div></div></div></div></blockquote></div><br></div>