[infinispan-dev] Async API

Jonathan Halliday jonathan.halliday at redhat.com
Thu Oct 27 11:32:31 EDT 2016


On 27/10/16 16:00, Radim Vansa wrote:
> On 10/27/2016 10:49 AM, Jonathan Halliday wrote:
>> On 27/10/16 09:36, Radim Vansa wrote:
>>
>>> So it's probably a question to Narayana guys if you can suspend a
>>> transaction in one thread and resume it in two threads.
>> yes you can.  Where it gets hairy is ensuring all the threads are done
>> before you commit. By default we warn rather than block, though there is
>> a (non-standard) plugin api to register your own handler for it.
>
> Warn/block what exactly? Any thread could commit the tx, and it commits
> that for all threads - I understand that it can be complex on the user
> side, but how can TM know that there's a thread that's still working on
> the transaction (do you expect that all other threads than the
> committing one will suspend the transaction when these are done?).

If it is suspended then by definition it is not currently working on the 
tx, though it may not be done.  We don't really care about those so much 
as we care about the ones that are NOT suspended, since nasty things 
happen to them if the tx context changes under their feet.  e.g. JDBC 
connections that switch from jta-tx-enlisted to autonomous-autocommit 
without warning, which means the SQL running on them ain't going to do 
what the thread expects.  We track which threads are active (i.e. 
associated, not suspended) in a tx and warn if you commit whilst it's 
greater than just the calling thread. But to prevent the aforementioned 
issue, warning is insufficient - you need to block the commit by waiting 
on the other thread(s) doing a tx suspend, or fail immediately with an 
exception.  A variation on this applies even in the synchronous api, 
since the tx timeout/rollback is on a background thread, so a long 
running transaction can be killed and leave the single business logic 
thread in an unexpected tx context. libraries such as hibernate do their 
best to narrow the timing window, but it's still there.

> Btw., is there any API to just fork the tx? (rather than suspending and
> resuming) Can you just resume a non-suspended transaction acquired by
> tm.getTransaction() in another thread?

yes.

Jonathan.


> Thanks!
>
> Radim
>
>>
>> Jonathan.
>>
>>
>
>

-- 
Registered in England and Wales under Company Registration No. 03798903 
Directors: Michael Cunningham, Michael ("Mike") O'Neill, Eric Shander


More information about the infinispan-dev mailing list