Tuesday 15 April 2014

Track non-deterministic MySQL errors in Perl -


I have a single thread perl script running on the host-shared server, which mainly executes the following code: / P>

  My $ O_dbh = DBI- & gt; Connect ("dbi: mysql: dbname = dbname", "abc", "xxx", {raiseError => 1}); $ O_dbh- & gt; Start_work (); My $ O_sth1 = $ O_dbh- & gt; Prepare ('SELECT COUNT (*) mytable WHERE any = 5'); $ O_sth1- & gt; Executed (); My @ result1 = $ O_sth1- & gt; Fetchrow_array (); My $ old value = $ result 1 [0]; $ O_sth1- & gt; Finish (); My $ O_sth2 = $ O_dbh- & gt; Prepare ('Include Meritable Value (any)) (5)'); $ O_sth2- & gt; Executed (); $ O_sth1- & gt; Executed (); My @ result2 = $ O_sth1- & gt; Fetchrow_array (); My new new value = $ result 2 [0]; If ($ oldValue + 1 == $ new value) {$ O_dbh- & gt; Commit (); } And {$ O_dbh- & gt; Rollback (); Die "why? New = $ new value, old = $ old value"; }   

Some time (& lt; 1%) code runs in rollback case and fails I can not reproduce this error on my local system. MySQL 5 is database.

  create table 'mytable` (`id` int (11) No tap auto_increment,` any' int (11) zero zero '', primary key (`ID`) Engine = InnoDB default charge = UTF8;   

How can I track this error? Any help will be very much appreciated.

The count of your database is running with the default settings, and I'm amazed that your SELECT ever returns two different values.

It says

If the level of transaction isolation is repetitive (the default level), all relevant reads within the same transaction, in that transaction Reads the first read snapshot. After doing current transactions and issuing new questions, you can get an innovation snapshot for your questions.

Therefore, if the default read repetition is in isolation level effect, I hope all queries come back to the data corresponding to the state of the database at the time of the first query Will go

However, it seems like it can help

With goodbye committed segregation level, every compatible reads within a transaction set and reads its latest snapshot. .

I think you should try

  $ O_dbh - & gt; Taxes ('SET session transaction segregation level was read');   

Immediately after connecting, and see if it fixes things for you.

However, you should make sure that either handle the disconnect database after this transaction or return it to the previous isolation level. Otherwise you will start getting incompatible results.

No comments:

Post a Comment