Skip to content

Commit

Permalink
remove log messages,
Browse files Browse the repository at this point in the history
with_ on ActiveRecord::Base
  • Loading branch information
tcurdt committed Jun 6, 2011
1 parent 914dca1 commit a49c46c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
41 changes: 20 additions & 21 deletions lib/master_slave_adapter/active_record_extensions.rb
@@ -1,13 +1,5 @@
ActiveRecord::Base.class_eval do

def reload_with_master( options = nil )
ActiveRecord::ConnectionAdapters::MasterSlaveAdapter.with_master do
reload_without_master( options )
end
end

alias_method_chain :reload, :master

class << self

# Call this method to force a block of code to use the master connection
Expand Down Expand Up @@ -51,18 +43,6 @@ def with_consistency(clock, &block)
end
end

def transaction_with_master(*args, &block)
if connection.respond_to? :transaction
connection.transaction do
transaction_without_master(*args, &block)
end
else
transaction_without_master(*args, &block)
end
end
alias_method_chain :transaction, :master


def master_slave_connection( config )
config = config.symbolize_keys
raise "You must provide a configuration for the master database - #{config.inspect}" if config[:master].blank?
Expand All @@ -87,12 +67,31 @@ def master_slave_connection( config )
ActiveRecord::ConnectionAdapters::MasterSlaveAdapter.new(config)
end

def transaction_with_master(*args, &block)
if connection.respond_to? :transaction
connection.transaction do
transaction_without_master(*args, &block)
end
else
transaction_without_master(*args, &block)
end
end
alias_method_chain :transaction, :master

def columns_with_master
ActiveRecord::ConnectionAdapters::MasterSlaveAdapter.with_master do
with_master do
columns_without_master
end
end
alias_method_chain :columns, :master

end

def reload_with_master(options = nil)
ActiveRecord::Base.with_master do
reload_without_master(options)
end
end
alias_method_chain :reload, :master

end
10 changes: 5 additions & 5 deletions lib/master_slave_adapter/adapter.rb
Expand Up @@ -152,9 +152,9 @@ def with_consistency(clock)
end

def transaction(*args)
puts "<transaction"
# puts "<transaction"
yield
puts "</transaction"
# puts "</transaction"
update_clock
end

Expand Down Expand Up @@ -187,7 +187,7 @@ def using_master?
private

def update_clock
puts " update clock"
# puts " update clock"
# update the clock, if there was problem keep using the old one
self.current_clock[0] = master_clock || self.current_clock[0]
# it's a write so from now on we use the master connection
Expand Down Expand Up @@ -245,15 +245,15 @@ def select_connection
end

def master_clock
puts " master clock"
# puts " master clock"
connection = connect_to_master
if status = connection.uncached { connection.select_one("SHOW MASTER STATUS") }
Clock.new(status['File'], status['Position'])
end
end

def slave_clock
puts " slave clock"
# puts " slave clock"
connection = connect_to_slave
if status = connection.uncached { connection.select_one("SHOW SLAVE STATUS") }
Clock.new(status['Relay_Master_Log_File'], status['Exec_Master_Log_Pos'])
Expand Down
2 changes: 1 addition & 1 deletion lib/master_slave_adapter/version.rb
@@ -1,3 +1,3 @@
module MasterSlaveAdapter
VERSION = "0.0.3"
VERSION = "0.0.4"
end
21 changes: 12 additions & 9 deletions specs/specs.rb
Expand Up @@ -75,6 +75,9 @@ def _slave

end

it "should call 'columns' on master" do
end

ActiveRecord::ConnectionAdapters::MasterSlaveAdapter::SELECT_METHODS.each do |method|

it "should send the method '#{method}' to the slave connection" do
Expand Down Expand Up @@ -334,27 +337,27 @@ def master_should_report_clock(pos)

old_clock = zero
new_clock = ActiveRecord::Base.with_consistency(old_clock) do
puts "slave: select"
# puts "slave: select"
ActiveRecord::Base.connection.send('select_all', 'testing') # slave s=0 m=0
puts "master: update"
# puts "master: update"
ActiveRecord::Base.connection.send('update', 'testing') # master s=0 m=1
puts "master: select"
# puts "master: select"
ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=1

ActiveRecord::Base.transaction do
puts "master: select"
# puts "master: select"
ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=1
puts "master: update"
# puts "master: update"
ActiveRecord::Base.connection.send('update', 'testing') # master s=0 m=1
puts "master: select"
# puts "master: select"
ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=1
end

puts "master: select"
# puts "master: select"
ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=2
puts "master: update"
# puts "master: update"
ActiveRecord::Base.connection.send('update', 'testing') # master s=0 m=3
puts "master: select"
# puts "master: select"
ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=3
end
end
Expand Down

0 comments on commit a49c46c

Please sign in to comment.