Transaction timeout

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Transaction timeout

joël Winteregg-2
Hi all,

I'm trying to set a TransactionTimeout as follow:
transactionManager = TransactionManagerServices.getTransactionManager();
transactionManager.setTransactionTimeout(300);

But it doesn't seems to work as expected. 60 sec after the transaction
start, I get the following exception:
bitronix.tm.internal.BitronixRollbackException: transaction timed out
and has been rolled back
at bitronix.tm.BitronixTransaction.commit(BitronixTransaction.java:126)
at
bitronix.tm.BitronixTransactionManager.commit(BitronixTransactionManager.java:95)

Should I maybe set the Timeout as follow ?
http://docs.codehaus.org/display/BTM/Configuration#Configuration-Timerssettings

Should it be set using a property file ?

Many thanks in advance.

Regards,

Joël


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

Ludovic Orban
Administrator
Hi,

What is the exact sequence you used to set the transaction's timeout ? Using BitronixTransactionManager.setTransactionTimeout() should work as defined by the JTA spec.

If you do this:

btm = TransactionManagerServices.getTransactionManager();
btm.setTransactionTimeout(300);
btm.beginTransaction();

the transaction should time out after 300 seconds. On the other hand, doing this:

btm = TransactionManagerServices.getTransactionManager();
btm.beginTransaction();
btm.setTransactionTimeout(300);

will use the default transaction timeout which when not set, defaults to 60 seconds and the next ones started on this thread will time out after 300 seconds.

This is a bit confusing but the JTA spec mandates this strange behavior.

Please check if you felt in that common trap. If not, please send me a debug trace of the BTM logs showing the reproduction of this mis-behavior so I can look deeper at what is going wrong.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

joël Winteregg-2
Hi Ludovic,

Thanks for you answer !

Yes, I'm exactly doing as follow:
>
> btm = TransactionManagerServices.getTransactionManager();
> btm.setTransactionTimeout(300);
> btm.beginTransaction();
>
> the transaction should time out after 300 seconds.

But my transaction seems to be much shorter than 300 sec ;-)

>
> Please check if you felt in that common trap. If not, please send me a debug
> trace of the BTM logs showing the reproduction of this mis-behavior so I can
> look deeper at what is going wrong.

Okay, here is the interesting part of the stacktrace...

Caused by: bitronix.tm.internal.BitronixSystemException: transaction
timed out
at
bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:44)
at
bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:59)
... 23 more


I will activate some more debug on BTM... Will let you know what I get !

Many thanks for your help,


Joël




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

joël Winteregg-2
Hello ludovic,

I produced the error using DEBUG logging on BTM. The attached file
provide traces around the timeout problem...

I think the following explain my problem ! I'm starting BTM transaction
manager and then setting its transaction timeout before starting
Hibernate...
In the following logs, we can see that Hibernate Datasource binding
(which occur after BTM timeout setting) initialize again the timeout
using BTM default value...

So I think I will just set transaction timeout before EACH new
transaction.begin() and not only during
TransactionManagerServices.getTransactionManager() which is only done
once into my constructor. Is this conclusion right ?


2008-06-06 18:44:36,776 DEBUG [bitronix.tm.BitronixTransactionManager]
[main] changing current thread context to a ThreadContext with
transaction null, default timeout 60s
2008-06-06 18:44:36,776 DEBUG [bitronix.tm.internal.ThreadContext]
[main] changing default timeout of thread context to 300s
2008-06-06 18:44:36,846 DEBUG [bitronix.tm.timer.TaskScheduler] [main]
scheduling pool shrinking task on an XAPool of resource jdbc/hibernate
with 0 connection(s) (0 still available) for Fri Jun 06 18:45:36 CE
ST 2008
2008-06-06 18:44:36,846 DEBUG [bitronix.tm.timer.TaskScheduler] [main]
removing task by an XAPool of resource jdbc/hibernate with 0
connection(s) (0 still available)
2008-06-06 18:44:36,846 DEBUG [bitronix.tm.timer.TaskScheduler] [main]
scheduled a PoolShrinkingTask scheduled for Fri Jun 06 18:45:36 CEST
2008 on an XAPool of resource jdbc/hibernate with 0 connection(s) (0
still available), total task(s) queued: 1
2008-06-06 18:44:36,856 DEBUG [bitronix.tm.resource.common.XAPool]
[main] setting vendor property 'url' to
'jdbc:postgresql://127.0.0.1/realtimestats'
2008-06-06 18:44:38,271 DEBUG [bitronix.tm.BitronixTransactionManager]
[Timer-0] changing current thread context to a ThreadContext with
transaction null, default timeout 60s
2008-06-06 18:44:38,271 DEBUG [bitronix.tm.timer.TaskScheduler]
[Timer-0] scheduling transaction timeout task on a Bitronix Transaction
with GTRID [3139322E3136382E322E35300000011A5EC3F5FD00000000],
status=NO_
TRANSACTION, 0 resource(s) enlisted (started Fri Jun 06 18:44:38 CEST
2008) for Fri Jun 06 18:45:38 CEST 2008
2008-06-06 18:44:38,272 DEBUG [bitronix.tm.timer.TaskScheduler]
[Timer-0] removing task by a Bitronix Transaction with GTRID
[3139322E3136382E322E35300000011A5EC3F5FD00000000],
status=NO_TRANSACTION, 0 resourc
e(s) enlisted (started Fri Jun 06 18:44:38 CEST 2008)
2008-06-06 18:44:38,272 DEBUG [bitronix.tm.timer.TaskScheduler]
[Timer-0] scheduled a TransactionTimeoutTask on a Bitronix Transaction
with GTRID [3139322E3136382E322E35300000011A5EC3F5FD00000000],
status=NO_T
RANSACTION, 0 resource(s) enlisted (started Fri Jun 06 18:44:38 CEST
2008) scheduled for Fri Jun 06 18:45:38 CEST 2008, total task(s) queued:
2


Thanks in advance !

Joël


On Fri, 2008-06-06 at 15:01 +0200, joël Winteregg wrote:

> Hi Ludovic,
>
> Thanks for you answer !
>
> Yes, I'm exactly doing as follow:
> >
> > btm = TransactionManagerServices.getTransactionManager();
> > btm.setTransactionTimeout(300);
> > btm.beginTransaction();
> >
> > the transaction should time out after 300 seconds.
>
> But my transaction seems to be much shorter than 300 sec ;-)
>
> >
> > Please check if you felt in that common trap. If not, please send me a debug
> > trace of the BTM logs showing the reproduction of this mis-behavior so I can
> > look deeper at what is going wrong.
>
> Okay, here is the interesting part of the stacktrace...
>
> Caused by: bitronix.tm.internal.BitronixSystemException: transaction
> timed out
> at
> bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:44)
> at
> bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:59)
> ... 23 more
>
>
> I will activate some more debug on BTM... Will let you know what I get !
>
> Many thanks for your help,
>
>
> Joël
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

btm.log (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

Ludovic Orban
Administrator
Hi,

This is correct: TransactionManager.setTransactionTimeout() does not change the default timeout value globally but only for future transactions that will be executed on the current thread. It is a bit awkward but that's what the JTA spec says.

So the only way to ensure a transaction will get the correct timeout is to set transaction timeout before each TransactionManager.begin() call exactly as you observed.

At least this problem forced you to look at the debug logs. I hope you find them readable and useful.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

joël Winteregg-2
Hello,

>
> This is correct: TransactionManager.setTransactionTimeout() does not change
> the default timeout value globally but only for future transactions that
> will be executed on the current thread. It is a bit awkward but that's what
> the JTA spec says.
>

Ah, okay ! Thanks for the input. But the TransactionManager returned by
TransactionManagerServices.getTransactionManager() could be used for
several queries (I mean it is thread safe), not as an Hibernate
Session ?

> So the only way to ensure a transaction will get the correct timeout is to
> set transaction timeout before each TransactionManager.begin() call exactly
> as you observed.
>

Okay, great ! Thanks again for your help...


> At least this problem forced you to look at the debug logs. I hope you find
> them readable and useful.

As I quickly get 800 Mb of logs with BTM as DEBUG, I mostly used grep,
etc. to find needed keywords ;-)

Enjoy your week-end !

Joël


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

Ludovic Orban
Administrator
Hi,

The TransactionManager object returned by TransactionManagerServices.getTransactionManager() actually is a singleton and is fully thread safe.

It is up to you to store it somewhere or to call TransactionManagerServices.getTransactionManager() each time you need it, that doesn't matter.

Another recommendation: unless you have requirements that forces you to use the TransactionManager interface (like transaction suspension), I would advise you to rely on the UserTransaction one instead.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Transaction timeout

joël Winteregg-2
Re,

Thanks for the info !
Okay, I'm now using UserTransaction reference instead of
BitronixTransactionManager...

See you soon,


Joël

On Fri, 2008-06-06 at 12:23 -0700, Ludovic Orban wrote:

> Hi,
>
> The TransactionManager object returned by
> TransactionManagerServices.getTransactionManager() actually is a singleton
> and is fully thread safe.
>
> It is up to you to store it somewhere or to call
> TransactionManagerServices.getTransactionManager() each time you need it,
> that doesn't matter.
>
> Another recommendation: unless you have requirements that forces you to use
> the TransactionManager interface (like transaction suspension), I would
> advise you to rely on the UserTransaction one instead.
>
> Ludovic


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email