[Rails-core] ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates

2013-01-20 Thread ajsharp
The method is here: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L288. The method takes the in-memory attribute value and increments it by the specified amount. A safer approach (from an isolation standpoint) would be to let the database determine the

Re: [Rails-core] ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates

2013-01-23 Thread Gabriel Sobrinho
Yes, I'm thinking about that and seems there is no way to handle this in a smart way. Developers can think "from what reason I've incremented by 100 and it incremented by 300" until he figure out that was incremented by other threads too. Maybe some documentation on increment(!)/decrement(!) m

Re: [Rails-core] ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates

2013-01-23 Thread Alex Sharp
On Wed, Jan 23, 2013 at 4:41 PM, Gabriel Sobrinho wrote: >> Since I have to keep a cache column of the paid value for the debt, I have >> 25 workers (sidekiq) that can call `increment!(:paid_value, >> paid_value)` >> and it should keep the total paid value. > > [SNIP] > > Yes, I'm thinking about

Re: [Rails-core] ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates

2013-01-23 Thread Carlos Antonio da Silva
> > If this is indeed your use case, what I'm advocating here is much > simpler than that. I just want to be able to increment numeric columns > in active record without declaring them as counter cache columns. You should still be able to do that by calling increment_counter or update_counte

Re: [Rails-core] ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates

2013-01-24 Thread Gabriel Sobrinho
Carlos, I'm suggesting to document this because the increment and decrements are intended to increment and decrement instead of replace the value, like the update_attributes method does. I expect to call increment in a object and the value get incremented by the given value instead of replacin

Re: [Rails-core] ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates

2013-01-24 Thread Gabriel Sobrinho
Yes, I figured out right now that is not about concurrency safe but it's about multiple instances. I just assumed that increment will increment instead of replacing the database values, which I expect in save/update. Thanks! :) On Jan 24, 2013, at 10:10 AM, Carlos Antonio da Silva wrote: >