1

I need some advise.

What is the best thing to do when there is a Rollback after starting a transaction?

  • Execute the rest of the website
  • Kill the complete website, and display an error message.

Thanks!

Pete B.
  • 3,188
  • 6
  • 25
  • 38
Jordy
  • 4,719
  • 11
  • 47
  • 81
  • Is there any in depth resource on that topic ? The pattern I usually see is 1) The developer does not anything about transactions 2) The developper just write commit/rollback without thinking 3) One day the developer hopefully notices that the DBMS he/she is using is not transactional (i.e. MyISAM). It seems to be that too few people actually know how to deal with transactions rollbacks. – Gzorg Jan 31 '17 at 09:56

2 Answers2

0

It really depends on what you want to do.

However:

  • You don't want to just put a raw error message in front of the user, it should be meaningful.
  • The meaningful message, should have the same look and feel of the rest of your page, and not just a white page with black writing.
  • It should include some kind of navigation, so the user can recover from the error.
  • If it is a form, that the user will presumably re-try then as much data as possible should be still in the form not to duplicate work.
Pete B.
  • 3,188
  • 6
  • 25
  • 38
  • Thanks, well I'm thinking about completely stop the website from running (exit();) because then I know the database will not be messed up! – Jordy Jul 17 '13 at 19:11
  • 2
    @Jordy on the contrary, the transaction should keep the database from being in an inconsistent state so you shouldn't need to `exit()` right away. At least tell the end user something happened. – Steven V Jul 17 '13 at 19:12
  • This is the problem I'm dealing with. Hope you can help me! http://stackoverflow.com/questions/17708401/optimize-transactions-in-my-files – Jordy Jul 17 '13 at 19:20
0

It really depends on why the MySQL ROLLBACK statement was issued. The application had a reason for issuing it, so the application should have a code path for that set of conditions.

Normally, a ROLLBACK is called when some condition has made it impossible to continue forward. So, this is normally done as an abort. "Kill the complete website" sounds a bit drastic. If this transaction was a result of some user interaction, the polite thing to do would be to present a message to the user "A problem was encountered with your request, please try again later." (There's no reason to present a stack trace to the user.)

And the application should log the details of the error condition into the log, including the identity of the user and some sort of transaction id, the stack trace, and any other relevant information, for analysis.

spencer7593
  • 106,611
  • 15
  • 112
  • 140
  • This is the problem I'm dealing with. Hope you can help me! http://stackoverflow.com/questions/17708401/optimize-transactions-in-my-files – Jordy Jul 17 '13 at 19:19