makara icon indicating copy to clipboard operation
makara copied to clipboard

Does not rollback transaction

Open palexvs opened this issue 7 years ago • 1 comments

Makara gracefully handles exceptions, in the result, it does not rollback transactions on a master when the master goes into reboot.

I have 1 master and 1 slave MySQL (5.7) servers Sometimes I update/upgrade/downgrade the slave, so I added custom connection_error_matchers to handle slave's reboot gracefully and switch on master without errors:

      - '/Server shutdown in progress/' # Do not fail on reboot
      - '/Unknown MySQL server host/' # Can be thrown on replica re-creation

But in the result, Makara suppress the same errors on the master during write transaction and I get an inconsistent database:

  1. transaction starts
  2. an application (Rails 5.1.4, Ruby 2.4.2) writes some data to the master
  3. the master reboots and rollback all not finished transactions
  4. Makara suppress the exception and waits till the master come back
  5. the application writes the second part of data
  6. the application finishes the transaction without any errors, but the database has just the second part of data

Example:

rails console
> Visitor.transaction do
>   puts Visitor.create!.id
>   sleep 10 # restart the master server 
>   puts Visitor.create!.id
> end
   (0.7ms)  SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci,  @@SESSION.sql_mode = 'TRADITIONAL',  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (0.4ms)  SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci,  @@SESSION.sql_mode = 'TRADITIONAL',  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
  [master/1] (0.2ms)  BEGIN
  [master/1] SQL (0.4ms)  INSERT INTO `visitors` (`uuidb`, `created_at`, `updated_at`) VALUES ('AAAA', '...', '...')
19
  [master/1] SQL (0.7ms)  INSERT INTO `visitors` (`uuidb`, `created_at`, `updated_at`) VALUES ('BBBB', '...', '...')
   (0.3ms)  SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci,  @@SESSION.sql_mode = 'TRADITIONAL',  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
  [master/1] SQL (5.9ms)  INSERT INTO `visitors` (`uuidb`, `created_at`, `updated_at`) VALUES ('BBBB', '...', '...')
19
  [master/1] (0.2ms)  COMMIT

Is there a way do not suppress errors on a master?

palexvs avatar Jan 25 '18 01:01 palexvs

@bleonard I hope this should fix the issue. travis-ci is red now, so I did not try to write tests

palexvs avatar Jan 26 '18 23:01 palexvs