Class: Gizzard::Migrator
- Inherits:
-
Object
- Object
- Gizzard::Migrator
- Defined in:
- lib/gizzard/migrator.rb
Constant Summary collapse
- BALANCE_TOLERANCE =
1
Instance Attribute Summary collapse
-
#configured_templates ⇒ Object
readonly
Returns the value of attribute configured_templates.
-
#existing_map ⇒ Object
readonly
Returns the value of attribute existing_map.
-
#existing_templates ⇒ Object
readonly
Returns the value of attribute existing_templates.
-
#new_templates ⇒ Object
readonly
populated via derive_changes.
-
#similar_templates ⇒ Object
readonly
populated via derive_changes.
-
#total_shards ⇒ Object
readonly
Returns the value of attribute total_shards.
-
#unchanged_templates ⇒ Object
readonly
populated via derive_changes.
-
#unrecognized_templates ⇒ Object
readonly
populated via derive_changes.
Instance Method Summary collapse
- #cleanup!(nameserver) ⇒ Object
- #copy!(nameserver) ⇒ Object
-
#initialize(existing_map, config_templates, default_total_shards, config) ⇒ Migrator
constructor
A new instance of Migrator.
- #prepare!(nameserver) ⇒ Object
- #transformations ⇒ Object
- #wait_for_copies(nameserver) ⇒ Object
Constructor Details
#initialize(existing_map, config_templates, default_total_shards, config) ⇒ Migrator
Returns a new instance of Migrator.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gizzard/migrator.rb', line 23 def initialize(existing_map, config_templates, default_total_shards, config) @configured_templates = config_templates @existing_map = existing_map @existing_templates = existing_map.keys @total_shards = @existing_map.values.map { |a| a.length }.inject { |a, b| a + b } || default_total_shards @config = config derive_changes end |
Instance Attribute Details
#configured_templates ⇒ Object (readonly)
Returns the value of attribute configured_templates.
18 19 20 |
# File 'lib/gizzard/migrator.rb', line 18 def configured_templates @configured_templates end |
#existing_map ⇒ Object (readonly)
Returns the value of attribute existing_map.
18 19 20 |
# File 'lib/gizzard/migrator.rb', line 18 def existing_map @existing_map end |
#existing_templates ⇒ Object (readonly)
Returns the value of attribute existing_templates.
18 19 20 |
# File 'lib/gizzard/migrator.rb', line 18 def existing_templates @existing_templates end |
#new_templates ⇒ Object (readonly)
populated via derive_changes
21 22 23 |
# File 'lib/gizzard/migrator.rb', line 21 def new_templates @new_templates end |
#similar_templates ⇒ Object (readonly)
populated via derive_changes
21 22 23 |
# File 'lib/gizzard/migrator.rb', line 21 def similar_templates @similar_templates end |
#total_shards ⇒ Object (readonly)
Returns the value of attribute total_shards.
18 19 20 |
# File 'lib/gizzard/migrator.rb', line 18 def total_shards @total_shards end |
#unchanged_templates ⇒ Object (readonly)
populated via derive_changes
21 22 23 |
# File 'lib/gizzard/migrator.rb', line 21 def unchanged_templates @unchanged_templates end |
#unrecognized_templates ⇒ Object (readonly)
populated via derive_changes
21 22 23 |
# File 'lib/gizzard/migrator.rb', line 21 def unrecognized_templates @unrecognized_templates end |
Instance Method Details
#cleanup!(nameserver) ⇒ Object
46 47 48 |
# File 'lib/gizzard/migrator.rb', line 46 def cleanup!(nameserver) transformations.each {|t| t.cleanup! nameserver, @config } end |
#copy!(nameserver) ⇒ Object
38 39 40 |
# File 'lib/gizzard/migrator.rb', line 38 def copy!(nameserver) transformations.each {|t| t.copy! nameserver, @config } end |
#prepare!(nameserver) ⇒ Object
34 35 36 |
# File 'lib/gizzard/migrator.rb', line 34 def prepare!(nameserver) transformations.each {|t| t.prepare! nameserver, @config } end |
#transformations ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gizzard/migrator.rb', line 50 def transformations return @transformations if @transformations # no changes return @transformations = [] if similar_templates.empty? and unrecognized_templates.empty? and new_templates.empty? configured_map = configured_templates.inject({}) {|h, t| h.update t => [] } @transformations = [] if existing_templates.empty? # no forwardings exist, we must populate the forwarding index. forwardings = generate_new_forwardings(total_shards) # add the new shard ids to a member of the configured map. will # be rebalanced later. configured_map.values.first.concat forwardings.values @transformations << ForwardingTransformation.new(@config.table_id, forwardings.inject({}) {|f, (b, e)| f.update b => @config.shard_name(e) }) end # map the unchanged templates straight over move_unchanged(existing_map, configured_map) # map similar templates over to their new versions move_similar(existing_map, configured_map) # move shards from unrecognized templates to new templates (or # existing ones) move_unrecognized_to_new(existing_map, configured_map) # rebalance rebalance_shards(configured_map) # transformation generation @transformations = generate_transformations(existing_map, configured_map) + @transformations end |
#wait_for_copies(nameserver) ⇒ Object
42 43 44 |
# File 'lib/gizzard/migrator.rb', line 42 def wait_for_copies(nameserver) transformations.each {|t| t.wait_for_copies nameserver, @config } end |