Skip to content

Instantly share code, notes, and snippets.

@primiti
Created April 30, 2013 19:05
Show Gist options
  • Save primiti/5491089 to your computer and use it in GitHub Desktop.
Save primiti/5491089 to your computer and use it in GitHub Desktop.
Test for warehouse deadlock updating dimensions.
# Change deadlock retry to log exceptions
DeadlockRetry;
module DeadlockRetry
class << self
def suppress_deadlock
yield
rescue ActiveRecord::StatementInvalid => ex
if !DEADLOCK_ERROR_MESSAGES.any? { |msg| ex.message.include?(msg) }
raise
else
puts "deadlock!"
end
end
end
end
# this is just the dimension update code from warehouse.
def update_all_dimensions(attributes)
dimension_generator = Warehouse::Base::Dimension::Generator.new attributes
Warehouse::CallFactShard.shards.first.all_dimensions.each do |dim|
DeadlockRetry.transaction(connection) { dimension_generator.dimension_id( dim ) }
end
end
# Run
def run
event_attributes = Warehouse::CallFact.call_event_attributes(Call.last)
1000.times do
puts ( Benchmark.realtime { Warehouse::CallFact.update_all_dimensions(event_attributes) } )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment