Issue with transaction

Questions, tips and tricks and techniques for scripting in Servoy

Issue with transaction

Postby Hans Nieuwenhuis » Sun Jun 13, 2010 10:15 am

Hi,

we use the following code to save data ( autosave is false ).

Code: Select all
databaseManager.startTransaction()

<pre-save code>

if (!databaseManager.saveData()) {
   _thePressedButton = plugins.dialogs.showErrorDialog('Error in first Save', 'See log', 'OK');
   _failedArray = databaseManager.getFailedRecords()
   for (var j = 0; j < _failedArray.length; j++) {
      _record = _failedArray[j];
      plugins.Log.error('Error <xxxxxxx>: ' + _record.exception);
   }
   <handle error>
   databaseManager.rollbackEditedRecords()
   databaseManager.rollbackTransaction()
   return -1
}

<post-save code>

if (!databaseManager.saveData()) {
   _thePressedButton = plugins.dialogs.showErrorDialog('Error in second Save', 'See log', 'OK');
   _failedArray = databaseManager.getFailedRecords()
   for (var j = 0; j < _failedArray.length; j++) {
      _record = _failedArray[j];
      plugins.Log.error('Error <xxxxxxx>: ' + _record.exception);
   }
   <handle error>
   databaseManager.rollbackEditedRecords()
   databaseManager.rollbackTransaction()
   return -1
}
   
if (!databaseManager.commitTransaction()) {
   _thePressedButton = plugins.dialogs.showErrorDialog('Error in commit', 'See log', 'OK');
   _failedArray = databaseManager.getFailedRecords()
   for (var j = 0; j < _failedArray.length; j++) {
      _record = _failedArray[j];
      plugins.Log.error('Error <xxxxxxx>: ' + _record.exception);
   }
   <handle error>
   databaseManager.rollbackEditedRecords()
   databaseManager.rollbackTransaction()
   return -1
}
else {
   return 0
}


sometimes a user gets an error message " 'Error in commit' " but when we look in the log file there
are no entries of failed records.

If we check the database, everything that the user edited is saved perfectly.

The only way I can reproduce this is by commenting the startTransaction.
In that case there is a commitTransaction without a startTransaction.
I the get the same error and no lines in the log.

How can this happen (the code above always starts the transaction and the startTransaction command has no return code.

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby rgansevles » Mon Jun 14, 2010 9:31 am

Hans,

Could it be that in some situations, there is already a transaction?
In that case databaseManager.startTransaction() does nothing.

You can use hasTransaction() before startTransaction() to check.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Issue with transaction

Postby Hans Nieuwenhuis » Mon Jun 14, 2010 9:56 am

Hi Rob,

I'll put in a hasTransaction line to test that.

But if there already is a transaction, and startTansaction does nothing,
then commitTransaction should commit the existing transaction or not ?

B.t.w. there are now two users who get this message sometimes ( most of the time it's oke).

Can a user only have 1 transaction open ( in our case there is never more then 1 )
Can you explain how does this mechanism work ?

We use the same code that we used with 4.1.x and there we never had this issue !!

Regards,

Hans
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby rgansevles » Mon Jun 14, 2010 10:08 am

Servoy does not support nested transactions, so I guess following sequence may happen in your case:

start tx1
work 1
start tx2 // does nothing
work 2
commit tx2 // commits work 1 and 2
commit tx1 // fails, no transaction

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Issue with transaction

Postby Hans Nieuwenhuis » Mon Jun 14, 2010 10:29 am

Rob,

As I said it never happened in 4.x.
We do not use nested transactions ( as far as i know )
But i'll put in a debug line with the hasTransaction and then i'll get back to you.

Thanks,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby Hans Nieuwenhuis » Thu Jun 17, 2010 9:01 am

Hi, we added 4 lines of debug ( logwrite ) code to our save method.

Code: Select all
plugins.Log.debug('trans1 = ' + databaseManager.hasTransaction());
databaseManager.startTransaction()
plugins.Log.debug('trans2 = ' + databaseManager.hasTransaction());      

<pre-save code>

if (!databaseManager.saveData()) {
   _thePressedButton = plugins.dialogs.showErrorDialog('Error in first Save', 'See log', 'OK');
   _failedArray = databaseManager.getFailedRecords()
   for (var j = 0; j < _failedArray.length; j++) {
      _record = _failedArray[j];
      plugins.Log.error('Error <xxxxxxx>: ' + _record.exception);
   }
   <handle error>
   databaseManager.rollbackEditedRecords()
   databaseManager.rollbackTransaction()
   return -1
}

<post-save code>

if (!databaseManager.saveData()) {
   _thePressedButton = plugins.dialogs.showErrorDialog('Error in second Save', 'See log', 'OK');
   _failedArray = databaseManager.getFailedRecords()
   for (var j = 0; j < _failedArray.length; j++) {
      _record = _failedArray[j];
      plugins.Log.error('Error <xxxxxxx>: ' + _record.exception);
   }
   <handle error>
   databaseManager.rollbackEditedRecords()
   databaseManager.rollbackTransaction()
   return -1
}
   
plugins.Log.debug('trans3 = ' + databaseManager.hasTransaction());   
if (!databaseManager.commitTransaction()) {
   _thePressedButton = plugins.dialogs.showErrorDialog('Error in commit', 'See log', 'OK');
   _failedArray = databaseManager.getFailedRecords()
   for (var j = 0; j < _failedArray.length; j++) {
      _record = _failedArray[j];
      plugins.Log.error('Error <xxxxxxx>: ' + _record.exception);
   }
   <handle error>
   databaseManager.rollbackEditedRecords()
   databaseManager.rollbackTransaction()
   return -1
}
else {
   application.output('Succesfull commmitTransaction');
}
      
plugins.Log.debug('trans4 = ' + databaseManager.hasTransaction());


as expected in the logfile most of the time we see the following sequence of logwrites :

IBISMain DEBUG 2010-06-16 14:45:14.401: trans1 = false
IBISMain DEBUG 2010-06-16 14:45:14.401: trans2 = true
IBISMain DEBUG 2010-06-16 14:45:14.417: trans3 = true
IBISMain DEBUG 2010-06-16 14:45:14.417: trans4 = false

But when the user gets the error 'Error in commit', 'See log':

The seuqence is as follows ( so number 4 is missing )

IBISMain DEBUG 2010-06-16 15:08:12.251: trans1 = false
IBISMain DEBUG 2010-06-16 15:08:12.251: trans2 = true
IBISMain DEBUG 2010-06-16 15:08:12.423: trans3 = true

AND there are no failed records in the log.

??? What could be the issue ?? ( again we never hat this issue with 3.x or 4.x )

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby Hans Nieuwenhuis » Mon Jun 21, 2010 10:19 am

Can one of the Servoyans have a look at this.

We keep getting this error a few times a day.

How can I find out what is happening ?

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby rgansevles » Tue Jun 22, 2010 4:37 pm

Hans,

databasemanager.commitTransaction does a saveData() before committing in the database.
If the saveData fails (for example because a field in the UI has invalid data), the commit will not continue.

You can add a saveData() before the commit and check its results, so we can see if that is what caused it.
The extra saveData is harmless in case it is successful, the commit won't have edited records to save so it will continue with the commit.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Issue with transaction

Postby Hans Nieuwenhuis » Tue Jun 22, 2010 6:19 pm

Hi Rob,

as you can see in the code there is a savedata before the commit.

And the savedata is always succesfull !!

Or do You mean something else ??

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby rgansevles » Wed Jun 23, 2010 1:54 pm

Weird,

Do you have after/before insert/update triggers that may create new edited records during the previous saveData(), which in the commit() cannot be saved?

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Issue with transaction

Postby Hans Nieuwenhuis » Wed Jun 23, 2010 4:46 pm

We do have them, but as You can see in the code, after these pre/post methods a save is performed.

B.t.w. next week Sanneke will be at our site and i'll look into this issue with her.

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby Hans Nieuwenhuis » Wed Aug 04, 2010 4:12 pm

Hi,

we still did'nt find the cause of this issue.
We tought it was related to another issue. That issue was resolved but the "commit" error stayed.

The application is used by 8 inhouse users and the error occurs several times a week
with different users.
Again : the commit returns a FALSE, but there are no failed records.

We are sure that it never happened with this solution in 4.x, it started with 5.1.

We are also pretty sure it happens when textarea's are edited, but it is not reproducable.

Does this last info give anyone a clou what to look for ??

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby jcompagner » Thu Aug 05, 2010 11:02 am

dont you have anything in the log?

If hasTransaction() is still true, and saveData() also was true just before you say commit()
then there are no records that did go wrong, but really the actual commit didnt work.
But those should be reported in the error log/java console.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Issue with transaction

Postby Hans Nieuwenhuis » Mon Sep 13, 2010 12:31 pm

Hi Johan,

We put in an extra savedata just before the commitTransaction.

When te error occurs, the saveData is succesfull, but the committransaction returns false !!
There are no failed records.
There are no errors in the log file.
All data seems to be saved correctly.

The error occurs several times a day per user.

The users think it happens when they have been editing a textarea ( varchar2(3700))
but there not sure.

about 1 in 20 fail ( my estimation) .

Please advise how to proceed to get to the root cause of this issue !!


ADD. Info :
1) this morning the error occurred when editing a regular textfield. So the hint about textareas is incorrect.
2) I do not expect it has any influence, but just before the commitTransaction there is a releasAllLocks statement.



Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: Issue with transaction

Postby jcompagner » Mon Sep 13, 2010 1:32 pm

are these web or smart clients?
because you talk about a log file. which file are you looking at? Or are you just testing and getting this in the developer?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Next

Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests

cron