You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Jeff Roberts <je...@yahoo.com> on 2005/11/30 14:35:09 UTC
Throttled
I have encountered what I believe to be a bug in the TransactionManager class. It appears to me that the commit() method should be doing a txThrottle.decrement(). A slight change to the end() method is required as well to prevent too many decrement() calls.
I have fixed the code and verified that it works, but wanted to make sure that what I found is in fact a bug and not misuse of the TransactionManager.
I have a long running job and am using iBatis. This job does numerous startTransaction(), commitTransaction() iterations. What is happening, is that each of my startTransaction() calls increments the throttle through the begin() method on TransactionManager. When I commit, I would expect this to decrement the throttle, but it doesn't. Eventually, my code iterates enough times that it increments the throttle and I end up in a wait that never ends.
If it is deemed a bug, I'm happy to submit my fix through Jira. For clarification, here is what I did to fix the problem.
Class com.ibatis.sqlmap.engine.transaction.TransactionManager
First, I modified the commit method as shown below. I've commented the line that I added.
public void commit(SessionScope session) throws SQLException, TransactionException {
Transaction trans = session.getTransaction();
TransactionState state = session.getTransactionState();
if (state == TransactionState.STATE_USER_PROVIDED) {
throw new TransactionException("TransactionManager could not commit. " +
"A user provided connection is currently being used by this session. " +
"You must call the commit() method of the Connection directly. " +
"The calling .setUserConnection (null) will clear the user provided transaction.");
} else if (state != TransactionState.STATE_STARTED) {
throw new TransactionException("TransactionManager could not commit. No transaction is started.");
}
if (session.isCommitRequired() || forceCommit) {
trans.commit();
session.setCommitRequired(false);
}
// Added by XWIRE
txThrottle.decrement();
session.setTransactionState(TransactionState.STATE_COMMITTED);
}
I also had to edit the end() method as well as show below. Again, this change is commented.
public void end(SessionScope session) throws SQLException, TransactionException {
Transaction trans = session.getTransaction();
TransactionState state = session.getTransactionState();
if (state == TransactionState.STATE_USER_PROVIDED) {
throw new TransactionException("TransactionManager could not end this transaction. " +
"A user provided connection is currently being used by this session. " +
"You must call the rollback() method of the Connection directly. " +
"The calling .setUserConnection (null) will clear the user provided transaction.");
}
try {
if (trans != null) {
try {
if (state != TransactionState.STATE_COMMITTED) {
if (session.isCommitRequired() || forceCommit) {
trans.rollback();
session.setCommitRequired(false);
}
}
} finally {
trans.close();
}
}
} finally {
// XWIRE - Added second condition to make sure throttle is not decremented if the transaction is already committed.
if (state != TransactionState.STATE_ENDED && state != TransactionState.STATE_COMMITTED ) {
txThrottle.decrement();
}
session.setTransaction(null);
session.setTransactionState(TransactionState.STATE_ENDED);
}
}
Thanks,
Jeff Roberts
---------------------------------
Yahoo! DSL Something to write home about. Just $16.99/mo. or less
Re: Throttled
Posted by Jeff Roberts <je...@yahoo.com>.
Clinton,
I'll do as you suggest and attach the file.
Thanks for your help.
Jeff
--- Clinton Begin <cl...@gmail.com> wrote:
> I believe the fix you've made this time (i.e. commit
> in started or committed
> state) is acceptable, and probably something we
> could include in the base.
>
> Can you open a JIRA "bug" and attach your modified
> file?
>
> Thanks much,
>
> Clinton
>
> On 11/30/05, Jeff Roberts
> <je...@yahoo.com> wrote:
> >
> > Clinton,
> > Thank you for the instructions. I changed my code
> to
> > do as you suggest, that is issue one start and
> > multiple commits, followed by an end. However, on
> the
> > second commit, I get an exception (shown below).
> >
> >
> com.ibatis.common.jdbc.exception.NestedSQLException:
> > Could not commit transaction. Cause:
> >
>
com.ibatis.sqlmap.engine.transaction.TransactionException:
> > TransactionManager could not commit. No
> transaction
> > is started.
> >
> > In looking at the commit method in
> TransactionManager,
> > it's clear why this happened. A commit is only
> > allowed if the Transaction state is STATE_STARTED.
> > See below:
> >
> > public void commit(SessionScope session) throws
> > SQLException, TransactionException {
> > Transaction trans = session.getTransaction();
> > TransactionState state =
> > session.getTransactionState();
> > if (state ==
> TransactionState.STATE_USER_PROVIDED)
> > {
> > throw new
> > TransactionException("TransactionManager could not
> > commit. " +
> > "A user provided connection is currently
> > being used by this session. " +
> > "You must call the commit() method of
> the
> > Connection directly. " +
> > "The calling .setUserConnection (null)
> will
> > clear the user provided transaction.");
> > } else if (state !=
> > TransactionState.STATE_STARTED) {
> > throw new
> > TransactionException("TransactionManager could not
> > commit. No transaction is started.");
> > }
> > if (session.isCommitRequired() || forceCommit)
> {
> > trans.commit();
> > session.setCommitRequired(false);
> > }
> >
> >
>
session.setTransactionState(TransactionState.STATE_COMMITTED);
> > }
> >
> >
> > When the first commit was issued, it worked
> properly
> > and set the Transaction state to STATE_COMMITTED.
> If
> > you don't want to decrement the throttle inside of
> > commit, I assume the remedy would be to change the
> > commit method to allow a commit if the Transaction
> > state is either STATE_STARTED or STATE_COMMITTED.
> >
> > I've changed the code and verified that this
> works,
> > but not sure if this is the solution you would
> advise.
> > In a previous note, you advised calling start,
> > commit, end in sequence, iteratively. I may be
> > mistaken, but thought that calling end released
> the
> > connection. If that is the case, I'd rather not
> do it
> > that way as I loop in my code many times and would
> > rather not release and re-acquire connections
> > repeatedly.
> >
> > Thank you,
> > Jeff Roberts
> >
> > --- Clinton Begin <cl...@gmail.com> wrote:
> >
> > > PS: You should be able to call commit multiple
> > > times, without re-calling
> > > start...that should allow you to do what you
> want.
> > > (i.e. don't call start
> > > multiple times).
> > >
> > > On 11/30/05, Clinton Begin
> <cl...@gmail.com>
> > > wrote:
> > > >
> > > >
> > > > Jeff,
> > > >
> > > > Commit should not be decrementing the
> throttle.
> > > Instead,
> > > > .endTransaction() should be called for every
> call
> > > to .startTransaction().
> > > >
> > > > Even if commit is called, end should be called
> > > too.
> > > >
> > > > Cheers,
> > > > Clinton
> > > >
> > > > On 11/30/05, Jeff Roberts
> > > <je...@yahoo.com> wrote:
> > > > >
> > > > > I have encountered what I believe to be a
> bug
> > > in the TransactionManager
> > > > > class. It appears to me that the commit()
> > > method should be doing a
> > > > > txThrottle.decrement(). A slight change to
> the
> > > end() method is required
> > > > > as well to prevent too many decrement()
> calls.
> > > > >
> > > > > I have fixed the code and verified that it
> > > works, but wanted to make
> > > > > sure that what I found is in fact a bug and
> not
> > > misuse of the
> > > > > TransactionManager.
> > > > >
> > > > > I have a long running job and am using
> iBatis.
> > > This job does numerous
> > > > > startTransaction(), commitTransaction()
> > > iterations. What is happening, is
> > > > > that each of my startTransaction() calls
> > > increments the throttle through the
> > > > > begin() method on TransactionManager. When
> I
> > > commit, I would expect this to
> > > > > decrement the throttle, but it doesn't.
> > > Eventually, my code iterates enough
> > > > > times that it increments the throttle and I
> end
> > > up in a wait that never
> > > > > ends.
> > > > >
> > > > > If it is deemed a bug, I 'm happy to submit
> my
> > > fix through Jira. For
> > > > > clarification, here is what I did to fix the
> > > problem.
> > > > >
> > > > > Class
> > >
> >
>
com.ibatis.sqlmap.engine.transaction.TransactionManager
> > > > >
> > > > > First, I modified the commit method as shown
> > > below. I've commented the
> > > > > line that I added.
> > > > >
> > > > > public void commit(SessionScope session)
> throws
> > > SQLException,
> > > > > TransactionException {
> > > > > Transaction trans =
> > > session.getTransaction();
> > > > > TransactionState state =
> > > session.getTransactionState();
> > > > > if (state ==
> > > TransactionState.STATE_USER_PROVIDED) {
> > > > > throw new
> > > TransactionException("TransactionManager could
> not
> > > > > commit. " +
> > > > > "A user provided connection is
> > > currently being used by this
> > > > > session. " +
> > > > > "You must call the commit() method
> of
>
=== message truncated ===
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Re: Throttled
Posted by Clinton Begin <cl...@gmail.com>.
I believe the fix you've made this time (i.e. commit in started or committed
state) is acceptable, and probably something we could include in the base.
Can you open a JIRA "bug" and attach your modified file?
Thanks much,
Clinton
On 11/30/05, Jeff Roberts <je...@yahoo.com> wrote:
>
> Clinton,
> Thank you for the instructions. I changed my code to
> do as you suggest, that is issue one start and
> multiple commits, followed by an end. However, on the
> second commit, I get an exception (shown below).
>
> com.ibatis.common.jdbc.exception.NestedSQLException:
> Could not commit transaction. Cause:
> com.ibatis.sqlmap.engine.transaction.TransactionException:
> TransactionManager could not commit. No transaction
> is started.
>
> In looking at the commit method in TransactionManager,
> it's clear why this happened. A commit is only
> allowed if the Transaction state is STATE_STARTED.
> See below:
>
> public void commit(SessionScope session) throws
> SQLException, TransactionException {
> Transaction trans = session.getTransaction();
> TransactionState state =
> session.getTransactionState();
> if (state == TransactionState.STATE_USER_PROVIDED)
> {
> throw new
> TransactionException("TransactionManager could not
> commit. " +
> "A user provided connection is currently
> being used by this session. " +
> "You must call the commit() method of the
> Connection directly. " +
> "The calling .setUserConnection (null) will
> clear the user provided transaction.");
> } else if (state !=
> TransactionState.STATE_STARTED) {
> throw new
> TransactionException("TransactionManager could not
> commit. No transaction is started.");
> }
> if (session.isCommitRequired() || forceCommit) {
> trans.commit();
> session.setCommitRequired(false);
> }
>
> session.setTransactionState(TransactionState.STATE_COMMITTED);
> }
>
>
> When the first commit was issued, it worked properly
> and set the Transaction state to STATE_COMMITTED. If
> you don't want to decrement the throttle inside of
> commit, I assume the remedy would be to change the
> commit method to allow a commit if the Transaction
> state is either STATE_STARTED or STATE_COMMITTED.
>
> I've changed the code and verified that this works,
> but not sure if this is the solution you would advise.
> In a previous note, you advised calling start,
> commit, end in sequence, iteratively. I may be
> mistaken, but thought that calling end released the
> connection. If that is the case, I'd rather not do it
> that way as I loop in my code many times and would
> rather not release and re-acquire connections
> repeatedly.
>
> Thank you,
> Jeff Roberts
>
> --- Clinton Begin <cl...@gmail.com> wrote:
>
> > PS: You should be able to call commit multiple
> > times, without re-calling
> > start...that should allow you to do what you want.
> > (i.e. don't call start
> > multiple times).
> >
> > On 11/30/05, Clinton Begin <cl...@gmail.com>
> > wrote:
> > >
> > >
> > > Jeff,
> > >
> > > Commit should not be decrementing the throttle.
> > Instead,
> > > .endTransaction() should be called for every call
> > to .startTransaction().
> > >
> > > Even if commit is called, end should be called
> > too.
> > >
> > > Cheers,
> > > Clinton
> > >
> > > On 11/30/05, Jeff Roberts
> > <je...@yahoo.com> wrote:
> > > >
> > > > I have encountered what I believe to be a bug
> > in the TransactionManager
> > > > class. It appears to me that the commit()
> > method should be doing a
> > > > txThrottle.decrement(). A slight change to the
> > end() method is required
> > > > as well to prevent too many decrement() calls.
> > > >
> > > > I have fixed the code and verified that it
> > works, but wanted to make
> > > > sure that what I found is in fact a bug and not
> > misuse of the
> > > > TransactionManager.
> > > >
> > > > I have a long running job and am using iBatis.
> > This job does numerous
> > > > startTransaction(), commitTransaction()
> > iterations. What is happening, is
> > > > that each of my startTransaction() calls
> > increments the throttle through the
> > > > begin() method on TransactionManager. When I
> > commit, I would expect this to
> > > > decrement the throttle, but it doesn't.
> > Eventually, my code iterates enough
> > > > times that it increments the throttle and I end
> > up in a wait that never
> > > > ends.
> > > >
> > > > If it is deemed a bug, I 'm happy to submit my
> > fix through Jira. For
> > > > clarification, here is what I did to fix the
> > problem.
> > > >
> > > > Class
> >
> com.ibatis.sqlmap.engine.transaction.TransactionManager
> > > >
> > > > First, I modified the commit method as shown
> > below. I've commented the
> > > > line that I added.
> > > >
> > > > public void commit(SessionScope session) throws
> > SQLException,
> > > > TransactionException {
> > > > Transaction trans =
> > session.getTransaction();
> > > > TransactionState state =
> > session.getTransactionState();
> > > > if (state ==
> > TransactionState.STATE_USER_PROVIDED) {
> > > > throw new
> > TransactionException("TransactionManager could not
> > > > commit. " +
> > > > "A user provided connection is
> > currently being used by this
> > > > session. " +
> > > > "You must call the commit() method of
> > the Connection
> > > > directly. " +
> > > > "The calling .setUserConnection (null)
> > will clear the user
> > > > provided transaction.");
> > > > } else if (state !=
> > TransactionState.STATE_STARTED) {
> > > > throw new
> > TransactionException("TransactionManager could not
> > > > commit. No transaction is started.");
> > > > }
> > > > if (session.isCommitRequired() ||
> > forceCommit) {
> > > > trans.commit();
> > > > session.setCommitRequired(false);
> > > > }
> > > > // Added by XWIRE
> > > > txThrottle.decrement();
> > > >
> >
> session.setTransactionState(TransactionState.STATE_COMMITTED);
> > > > }
> > > >
> > > >
> > > > I also had to edit the end() method as well as
> > show below. Again, this
> > > > change is commented.
> > > >
> > > >
> > > > public void end(SessionScope session) throws
> > SQLException,
> > > > TransactionException {
> > > > Transaction trans =
> > session.getTransaction();
> > > > TransactionState state =
> > session.getTransactionState();
> > > >
> > > > if (state ==
> > TransactionState.STATE_USER_PROVIDED) {
> > > > throw new
> > TransactionException("TransactionManager could not
> > end
> > > > this transaction. " +
> > > > "A user provided connection is
> > currently being used by this
> > > > session. " +
> > > > "You must call the rollback() method
> > of the Connection
> > > > directly. " +
> > > > "The calling .setUserConnection (null)
> > will clear the user
> > > > provided transaction.");
> > > > }
> > > >
> > > > try {
> > > > if (trans != null) {
> > > > try {
> > > > if (state !=
> > TransactionState.STATE_COMMITTED) {
> > > > if (session.isCommitRequired() ||
> > forceCommit) {
> > > > trans.rollback();
> > > > session.setCommitRequired(false);
> > > > }
> > > > }
> > > > } finally {
> > > > trans.close();
> > > > }
> > > > }
> > > > } finally {
> > > >
> > > > // XWIRE - Added second condition to make
> > sure throttle is not
> > > > decremented if the transaction is already
> > committed.
> > > > if (state != TransactionState.STATE_ENDED
> > && state !=
> > > > TransactionState.STATE_COMMITTED ) {
> > > > txThrottle.decrement();
> > > > }
> > > >
> > > > session.setTransaction(null);
> > > > session.setTransactionState
> > (TransactionState.STATE_ENDED);
> > > > }
> > > > }
> > > >
> > > >
> > > > Thanks,
> > > > Jeff Roberts
> > > >
> > > > ------------------------------
> > > > Yahoo!
> >
> DSL<
> http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=37474/*http://promo.yahoo.com/broadband/+%0D%0A
> >Something
> > to write home about. Just $16.99/mo. or less
> > > >
> > > >
> > >
> >
>
>
>
>
> __________________________________________
> Yahoo! DSL – Something to write home about.
> Just $16.99/mo. or less.
> dsl.yahoo.com
>
>
Re: Throttled
Posted by Jeff Roberts <je...@yahoo.com>.
Clinton,
Thank you for the instructions. I changed my code to
do as you suggest, that is issue one start and
multiple commits, followed by an end. However, on the
second commit, I get an exception (shown below).
com.ibatis.common.jdbc.exception.NestedSQLException:
Could not commit transaction. Cause:
com.ibatis.sqlmap.engine.transaction.TransactionException:
TransactionManager could not commit. No transaction
is started.
In looking at the commit method in TransactionManager,
it's clear why this happened. A commit is only
allowed if the Transaction state is STATE_STARTED.
See below:
public void commit(SessionScope session) throws
SQLException, TransactionException {
Transaction trans = session.getTransaction();
TransactionState state =
session.getTransactionState();
if (state == TransactionState.STATE_USER_PROVIDED)
{
throw new
TransactionException("TransactionManager could not
commit. " +
"A user provided connection is currently
being used by this session. " +
"You must call the commit() method of the
Connection directly. " +
"The calling .setUserConnection (null) will
clear the user provided transaction.");
} else if (state !=
TransactionState.STATE_STARTED) {
throw new
TransactionException("TransactionManager could not
commit. No transaction is started.");
}
if (session.isCommitRequired() || forceCommit) {
trans.commit();
session.setCommitRequired(false);
}
session.setTransactionState(TransactionState.STATE_COMMITTED);
}
When the first commit was issued, it worked properly
and set the Transaction state to STATE_COMMITTED. If
you don't want to decrement the throttle inside of
commit, I assume the remedy would be to change the
commit method to allow a commit if the Transaction
state is either STATE_STARTED or STATE_COMMITTED.
I've changed the code and verified that this works,
but not sure if this is the solution you would advise.
In a previous note, you advised calling start,
commit, end in sequence, iteratively. I may be
mistaken, but thought that calling end released the
connection. If that is the case, I'd rather not do it
that way as I loop in my code many times and would
rather not release and re-acquire connections
repeatedly.
Thank you,
Jeff Roberts
--- Clinton Begin <cl...@gmail.com> wrote:
> PS: You should be able to call commit multiple
> times, without re-calling
> start...that should allow you to do what you want.
> (i.e. don't call start
> multiple times).
>
> On 11/30/05, Clinton Begin <cl...@gmail.com>
> wrote:
> >
> >
> > Jeff,
> >
> > Commit should not be decrementing the throttle.
> Instead,
> > .endTransaction() should be called for every call
> to .startTransaction().
> >
> > Even if commit is called, end should be called
> too.
> >
> > Cheers,
> > Clinton
> >
> > On 11/30/05, Jeff Roberts
> <je...@yahoo.com> wrote:
> > >
> > > I have encountered what I believe to be a bug
> in the TransactionManager
> > > class. It appears to me that the commit()
> method should be doing a
> > > txThrottle.decrement(). A slight change to the
> end() method is required
> > > as well to prevent too many decrement() calls.
> > >
> > > I have fixed the code and verified that it
> works, but wanted to make
> > > sure that what I found is in fact a bug and not
> misuse of the
> > > TransactionManager.
> > >
> > > I have a long running job and am using iBatis.
> This job does numerous
> > > startTransaction(), commitTransaction()
> iterations. What is happening, is
> > > that each of my startTransaction() calls
> increments the throttle through the
> > > begin() method on TransactionManager. When I
> commit, I would expect this to
> > > decrement the throttle, but it doesn't.
> Eventually, my code iterates enough
> > > times that it increments the throttle and I end
> up in a wait that never
> > > ends.
> > >
> > > If it is deemed a bug, I 'm happy to submit my
> fix through Jira. For
> > > clarification, here is what I did to fix the
> problem.
> > >
> > > Class
>
com.ibatis.sqlmap.engine.transaction.TransactionManager
> > >
> > > First, I modified the commit method as shown
> below. I've commented the
> > > line that I added.
> > >
> > > public void commit(SessionScope session) throws
> SQLException,
> > > TransactionException {
> > > Transaction trans =
> session.getTransaction();
> > > TransactionState state =
> session.getTransactionState();
> > > if (state ==
> TransactionState.STATE_USER_PROVIDED) {
> > > throw new
> TransactionException("TransactionManager could not
> > > commit. " +
> > > "A user provided connection is
> currently being used by this
> > > session. " +
> > > "You must call the commit() method of
> the Connection
> > > directly. " +
> > > "The calling .setUserConnection (null)
> will clear the user
> > > provided transaction.");
> > > } else if (state !=
> TransactionState.STATE_STARTED) {
> > > throw new
> TransactionException("TransactionManager could not
> > > commit. No transaction is started.");
> > > }
> > > if (session.isCommitRequired() ||
> forceCommit) {
> > > trans.commit();
> > > session.setCommitRequired(false);
> > > }
> > > // Added by XWIRE
> > > txThrottle.decrement();
> > >
>
session.setTransactionState(TransactionState.STATE_COMMITTED);
> > > }
> > >
> > >
> > > I also had to edit the end() method as well as
> show below. Again, this
> > > change is commented.
> > >
> > >
> > > public void end(SessionScope session) throws
> SQLException,
> > > TransactionException {
> > > Transaction trans =
> session.getTransaction();
> > > TransactionState state =
> session.getTransactionState();
> > >
> > > if (state ==
> TransactionState.STATE_USER_PROVIDED) {
> > > throw new
> TransactionException("TransactionManager could not
> end
> > > this transaction. " +
> > > "A user provided connection is
> currently being used by this
> > > session. " +
> > > "You must call the rollback() method
> of the Connection
> > > directly. " +
> > > "The calling .setUserConnection (null)
> will clear the user
> > > provided transaction.");
> > > }
> > >
> > > try {
> > > if (trans != null) {
> > > try {
> > > if (state !=
> TransactionState.STATE_COMMITTED) {
> > > if (session.isCommitRequired() ||
> forceCommit) {
> > > trans.rollback();
> > > session.setCommitRequired(false);
> > > }
> > > }
> > > } finally {
> > > trans.close();
> > > }
> > > }
> > > } finally {
> > >
> > > // XWIRE - Added second condition to make
> sure throttle is not
> > > decremented if the transaction is already
> committed.
> > > if (state != TransactionState.STATE_ENDED
> && state !=
> > > TransactionState.STATE_COMMITTED ) {
> > > txThrottle.decrement();
> > > }
> > >
> > > session.setTransaction(null);
> > > session.setTransactionState
> (TransactionState.STATE_ENDED);
> > > }
> > > }
> > >
> > >
> > > Thanks,
> > > Jeff Roberts
> > >
> > > ------------------------------
> > > Yahoo!
>
DSL<http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=37474/*http://promo.yahoo.com/broadband/+%0D%0A>Something
> to write home about. Just $16.99/mo. or less
> > >
> > >
> >
>
__________________________________________
Yahoo! DSL Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com
Re: Throttled
Posted by Clinton Begin <cl...@gmail.com>.
PS: You should be able to call commit multiple times, without re-calling
start...that should allow you to do what you want. (i.e. don't call start
multiple times).
On 11/30/05, Clinton Begin <cl...@gmail.com> wrote:
>
>
> Jeff,
>
> Commit should not be decrementing the throttle. Instead,
> .endTransaction() should be called for every call to .startTransaction().
>
> Even if commit is called, end should be called too.
>
> Cheers,
> Clinton
>
> On 11/30/05, Jeff Roberts <je...@yahoo.com> wrote:
> >
> > I have encountered what I believe to be a bug in the TransactionManager
> > class. It appears to me that the commit() method should be doing a
> > txThrottle.decrement(). A slight change to the end() method is required
> > as well to prevent too many decrement() calls.
> >
> > I have fixed the code and verified that it works, but wanted to make
> > sure that what I found is in fact a bug and not misuse of the
> > TransactionManager.
> >
> > I have a long running job and am using iBatis. This job does numerous
> > startTransaction(), commitTransaction() iterations. What is happening, is
> > that each of my startTransaction() calls increments the throttle through the
> > begin() method on TransactionManager. When I commit, I would expect this to
> > decrement the throttle, but it doesn't. Eventually, my code iterates enough
> > times that it increments the throttle and I end up in a wait that never
> > ends.
> >
> > If it is deemed a bug, I 'm happy to submit my fix through Jira. For
> > clarification, here is what I did to fix the problem.
> >
> > Class com.ibatis.sqlmap.engine.transaction.TransactionManager
> >
> > First, I modified the commit method as shown below. I've commented the
> > line that I added.
> >
> > public void commit(SessionScope session) throws SQLException,
> > TransactionException {
> > Transaction trans = session.getTransaction();
> > TransactionState state = session.getTransactionState();
> > if (state == TransactionState.STATE_USER_PROVIDED) {
> > throw new TransactionException("TransactionManager could not
> > commit. " +
> > "A user provided connection is currently being used by this
> > session. " +
> > "You must call the commit() method of the Connection
> > directly. " +
> > "The calling .setUserConnection (null) will clear the user
> > provided transaction.");
> > } else if (state != TransactionState.STATE_STARTED) {
> > throw new TransactionException("TransactionManager could not
> > commit. No transaction is started.");
> > }
> > if (session.isCommitRequired() || forceCommit) {
> > trans.commit();
> > session.setCommitRequired(false);
> > }
> > // Added by XWIRE
> > txThrottle.decrement();
> > session.setTransactionState(TransactionState.STATE_COMMITTED);
> > }
> >
> >
> > I also had to edit the end() method as well as show below. Again, this
> > change is commented.
> >
> >
> > public void end(SessionScope session) throws SQLException,
> > TransactionException {
> > Transaction trans = session.getTransaction();
> > TransactionState state = session.getTransactionState();
> >
> > if (state == TransactionState.STATE_USER_PROVIDED) {
> > throw new TransactionException("TransactionManager could not end
> > this transaction. " +
> > "A user provided connection is currently being used by this
> > session. " +
> > "You must call the rollback() method of the Connection
> > directly. " +
> > "The calling .setUserConnection (null) will clear the user
> > provided transaction.");
> > }
> >
> > try {
> > if (trans != null) {
> > try {
> > if (state != TransactionState.STATE_COMMITTED) {
> > if (session.isCommitRequired() || forceCommit) {
> > trans.rollback();
> > session.setCommitRequired(false);
> > }
> > }
> > } finally {
> > trans.close();
> > }
> > }
> > } finally {
> >
> > // XWIRE - Added second condition to make sure throttle is not
> > decremented if the transaction is already committed.
> > if (state != TransactionState.STATE_ENDED && state !=
> > TransactionState.STATE_COMMITTED ) {
> > txThrottle.decrement();
> > }
> >
> > session.setTransaction(null);
> > session.setTransactionState (TransactionState.STATE_ENDED);
> > }
> > }
> >
> >
> > Thanks,
> > Jeff Roberts
> >
> > ------------------------------
> > Yahoo! DSL<http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=37474/*http://promo.yahoo.com/broadband/+%0D%0A>Something to write home about. Just $16.99/mo. or less
> >
> >
>
Re: Throttled
Posted by Clinton Begin <cl...@gmail.com>.
Jeff,
Commit should not be decrementing the throttle. Instead, .endTransaction()
should be called for every call to .startTransaction().
Even if commit is called, end should be called too.
Cheers,
Clinton
On 11/30/05, Jeff Roberts <je...@yahoo.com> wrote:
>
> I have encountered what I believe to be a bug in the TransactionManager
> class. It appears to me that the commit() method should be doing a
> txThrottle.decrement(). A slight change to the end() method is required
> as well to prevent too many decrement() calls.
>
> I have fixed the code and verified that it works, but wanted to make sure
> that what I found is in fact a bug and not misuse of the TransactionManager.
>
> I have a long running job and am using iBatis. This job does numerous
> startTransaction(), commitTransaction() iterations. What is happening, is
> that each of my startTransaction() calls increments the throttle through the
> begin() method on TransactionManager. When I commit, I would expect this to
> decrement the throttle, but it doesn't. Eventually, my code iterates enough
> times that it increments the throttle and I end up in a wait that never
> ends.
>
> If it is deemed a bug, I 'm happy to submit my fix through Jira. For
> clarification, here is what I did to fix the problem.
>
> Class com.ibatis.sqlmap.engine.transaction.TransactionManager
>
> First, I modified the commit method as shown below. I've commented the
> line that I added.
>
> public void commit(SessionScope session) throws SQLException,
> TransactionException {
> Transaction trans = session.getTransaction();
> TransactionState state = session.getTransactionState();
> if (state == TransactionState.STATE_USER_PROVIDED) {
> throw new TransactionException("TransactionManager could not
> commit. " +
> "A user provided connection is currently being used by this
> session. " +
> "You must call the commit() method of the Connection directly.
> " +
> "The calling .setUserConnection (null) will clear the user
> provided transaction.");
> } else if (state != TransactionState.STATE_STARTED) {
> throw new TransactionException("TransactionManager could not
> commit. No transaction is started.");
> }
> if (session.isCommitRequired() || forceCommit) {
> trans.commit();
> session.setCommitRequired(false);
> }
> // Added by XWIRE
> txThrottle.decrement();
> session.setTransactionState(TransactionState.STATE_COMMITTED);
> }
>
>
> I also had to edit the end() method as well as show below. Again, this
> change is commented.
>
>
> public void end(SessionScope session) throws SQLException,
> TransactionException {
> Transaction trans = session.getTransaction();
> TransactionState state = session.getTransactionState();
>
> if (state == TransactionState.STATE_USER_PROVIDED) {
> throw new TransactionException("TransactionManager could not end
> this transaction. " +
> "A user provided connection is currently being used by this
> session. " +
> "You must call the rollback() method of the Connection
> directly. " +
> "The calling .setUserConnection (null) will clear the user
> provided transaction.");
> }
>
> try {
> if (trans != null) {
> try {
> if (state != TransactionState.STATE_COMMITTED) {
> if (session.isCommitRequired() || forceCommit) {
> trans.rollback();
> session.setCommitRequired(false);
> }
> }
> } finally {
> trans.close();
> }
> }
> } finally {
>
> // XWIRE - Added second condition to make sure throttle is not
> decremented if the transaction is already committed.
> if (state != TransactionState.STATE_ENDED && state !=
> TransactionState.STATE_COMMITTED ) {
> txThrottle.decrement();
> }
>
> session.setTransaction(null);
> session.setTransactionState(TransactionState.STATE_ENDED);
> }
> }
>
>
> Thanks,
> Jeff Roberts
>
> ------------------------------
> Yahoo! DSL<http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=37474/*http://promo.yahoo.com/broadband/+%0D%0A>Something to write home about. Just $16.99/mo. or less
>
>