Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
06/19/06 22:48:51 (4 years ago)
Author:
bitsweat
Message:

r4644@asus: jeremy | 2006-06-16 14:57:03 -0700
locking
r4645@asus: jeremy | 2006-06-17 12:41:30 -0700
missing reply fixture
r4646@asus: jeremy | 2006-06-19 13:05:23 -0700
Use a per-thread (rather than global) transaction mutex so you may execute concurrent transactions on separate connections.
r4647@asus: jeremy | 2006-06-19 13:07:23 -0700
PostgreSQL: introduce allow_concurrency option which determines whether to use blocking or asynchronous #execute. Adapters with blocking #execute will deadlock Ruby threads. The default value is ActiveRecord::Base.allow_concurrency.
r4648@asus: jeremy | 2006-06-19 13:08:40 -0700
Pass the default allow_concurrency when instantiating new connections.
r4649@asus: jeremy | 2006-06-19 13:11:12 -0700
Break out concurrent transaction tests and run them for PostgreSQLAdapter only (need to fork or system('some_test_script') for the other adapters)
r4650@asus: jeremy | 2006-06-19 13:42:48 -0700
Row locking. Provide a locking clause with the :lock finder option or true for the default "FOR UPDATE".
r4661@asus: jeremy | 2006-06-19 15:36:51 -0700
excise the junk mutex

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/transactions.rb

    r4312 r4460  
    55module ActiveRecord 
    66  module Transactions # :nodoc: 
    7     TRANSACTION_MUTEX = Mutex.new 
    8  
    97    class TransactionError < ActiveRecordError # :nodoc: 
    108    end 
     
    8078      def transaction(*objects, &block) 
    8179        previous_handler = trap('TERM') { raise TransactionError, "Transaction aborted" } 
    82         lock_mutex 
    83          
     80        increment_open_transactions 
     81 
    8482        begin 
    8583          objects.each { |o| o.extend(Transaction::Simple) } 
     
    9492          raise 
    9593        ensure 
    96           unlock_mutex 
     94          decrement_open_transactions 
    9795          trap('TERM', previous_handler) 
    9896        end 
    9997      end 
    100        
    101       def lock_mutex#:nodoc: 
    102         Thread.current['open_transactions'] ||= 0 
    103         TRANSACTION_MUTEX.lock if Thread.current['open_transactions'] == 0 
    104         Thread.current['start_db_transaction'] = (Thread.current['open_transactions'] == 0) 
    105         Thread.current['open_transactions'] += 1 
    106       end 
    107        
    108       def unlock_mutex#:nodoc: 
    109         Thread.current['open_transactions'] -= 1 
    110         TRANSACTION_MUTEX.unlock if Thread.current['open_transactions'] == 0 
    111       end 
     98 
     99      private 
     100        def increment_open_transactions #:nodoc: 
     101          open = Thread.current['open_transactions'] ||= 0 
     102          Thread.current['start_db_transaction'] = open.zero? 
     103          Thread.current['open_transactions'] = open + 1 
     104        end 
     105 
     106        def decrement_open_transactions #:nodoc: 
     107          Thread.current['open_transactions'] -= 1 
     108        end 
    112109    end 
    113110