Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ø dowtime migrations - rubyconf 2015

ø dowtime migrations - rubyconf 2015

Migrações em zero downtime com ruby.

Nesta apresentação mostro um pouco do mindset na RD para o rollout de novas features ou migrações sem downtime.

Jônatas Davi Paganini

September 12, 2015
Tweet

More Decks by Jônatas Davi Paganini

Other Decks in Technology

Transcript

  1. 99,9% 99,5% 99,0% 98,6% 98,0% 97,0% 99,99% 00:43:00 03:36:00 07:12:00

    10:00:00 14:24:00 21:36:00 00:04:32 Availability
  2. Update 0.3 Person.select("id,first_name,last_name").find_in_batches do |people| People.transaction do people.each do |person|

    person.update_attribute "full_name", "#{person.first_name} #{person.last_name}" end end end
  3. Update 0.4 Person.where(full_name: nil).select("id,first_name,last_name").find_in_batches do |people| People.transaction do people.each do

    |person| person.update_attribute "full_name", "#{person.first_name} #{person.last_name}" end end end
  4. Update 0.5 update_sql = "UPDATE people set full_name =" Person.where(full_name:

    nil).select("id,first_name,last_name").find_in_batches do |people| People.transaction do people.each(ActiveRecord::Base.connection_config[:pool]) do |person| ActiveRecord::Base.connection_pool.with_connection do |conn| set_full_name = conn.quote("#{person.first_name} #{person.last_name}") conn.execute("#{update_sql} #{set_full_name} where id = #{person.id} ") end end end end
  5. Rollout class Rollout def enabled?(feature, context) redis.sismember(feature, context) rescue Redis::BaseError

    false end def enable(feature, context) redis.sadd(feature) end def disable(feature, context) redis.srem(feature) end private def redis Redis::Namespace.new("rollout", redis: $redis) end end
  6. ?