Git Product home page Git Product logo

deadlock_retry's People

Contributors

dhh avatar jamis avatar kbrock avatar mnaberez avatar mperham avatar tomhughes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

deadlock_retry's Issues

Silent failures in transaction when no PROCESS privilege

We recently found that we were dropping parts of transactions on the floor. The symptom was this error message

Deadlock detected on retry 1, restarting transaction
Cannot log innodb status: Mysql::Error: Access denied; you need the PROCESS privilege for this operation: show innodb status

Whilst the error is rescued it would still mess up the transaction and, more importantly, would do so silently.

We fixed it by introducing a config option which controlled whether log_innodb_status was called or not (it's off by default) - a better solution may be to check for privileges somehow but it looks like that's not trivial and may introduce performance problems.

deadlock retry fails to save record that raises a deadlock in after hooks

If a deadlock occurs in an after commit hook for a record deadlock_retry will retry the commit but issues an "UPDATE" instead of an "INSERT" statement, resulting in the record never being saved even though calling #save returns true. This is easily demonstrated with the following code:

require 'deadlock_retry'

class MyTest < ActiveRecord::Base

  after_create :deadlock_error
  after_commit :puts_after_commit, :on => :create

  def deadlock_error
    unless @errored
      @errored = true
      raise ActiveRecord::StatementInvalid.new("Deadlock found when trying to get lock")
    end
    return
  end

  def puts_after_commit
    puts "After Commit"
  end
end

my_test = MyTest.new(:name => "Testing")

if my_test.save
  MyTest.find(my_test.id)
end

This will have the following output:

> my_test = MyTest.new(:name => "Testing")
=> #<MyTest id: nil, name: "Testing"> 
> if my_test.save
?>     MyTest.find(my_test.id)
?>   end

After Commit
ActiveRecord::RecordNotFound: Couldn't find MyTest with ID=1
from /Users/dimas/.rvm/gems/ree-1.8.7-2011.03/gems/activerecord-3.0.11/lib/active_record/relation/finder_methods.rb:306:in `find_one'
from /Users/dimas/.rvm/gems/ree-1.8.7-2011.03/gems/activerecord-3.0.11/lib/active_record/relation/finder_methods.rb:291:in `find_with_ids'
from /Users/dimas/.rvm/gems/ree-1.8.7-2011.03/gems/activerecord-3.0.11/lib/active_record/relation/finder_methods.rb:107:in `find'
from /Users/dimas/.rvm/gems/ree-1.8.7-2011.03/gems/activerecord-3.0.11/lib/active_record/base.rb:444:in `__send__'
from /Users/dimas/.rvm/gems/ree-1.8.7-2011.03/gems/activerecord-3.0.11/lib/active_record/base.rb:444:in `find'
from (irb):22

And if you look at the log you'll see:

SQL (0.1ms)  BEGIN
SQL (1.9ms)  describe `my_tests`
AREL (0.2ms)  INSERT INTO `my_tests` (`name`) VALUES ('Testing')
SQL (0.5ms)  ROLLBACK
Deadlock detected on retry 1, restarting transaction
SQL (3.3ms)  BEGIN
AREL (0.3ms)  UPDATE `my_tests` SET `name` = 'Testing' WHERE `my_tests`.`id` = 1
SQL (0.1ms)  COMMIT
MyTest Load (0.2ms)  SELECT `my_tests`.* FROM `my_tests` WHERE `my_tests`.`id` = 1 LIMIT 1

timeout not retried in ActiveRecord::Base.update_counters

It looks like deadlock_retry only wraps transactions, but "Lock wait timeout exceeded" errors can also be raised from update commands, which are not always wrapped in a transaction. ActiveRecord::Base.update_counters is one such case.

New gem release?

Any chance of a new release of the gem with the latest edits in?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.