Class: Gizzard::RemovePartitionCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/gizzard/commands.rb

Instance Attribute Summary

Attributes inherited from Command

#argv, #buffer, #command_options, #global_options, #job_injector, #manager

Instance Method Summary collapse

Methods inherited from Command

classify, #confirm!, #get_base_name, #help!, #initialize, make_job_injector, make_manager, #output, #require_tables, #require_template_options, run

Constructor Details

This class inherits a constructor from Gizzard::Command

Instance Method Details

#runObject



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gizzard/commands.rb', line 998

def run
  require_tables

  scheduler_options = command_options.scheduler_options || {}
  manifest          = manager.manifest(*global_options.tables)
  copy_wrapper      = scheduler_options[:copy_wrapper]
  be_quiet          = global_options.force && command_options.quiet
  transformations   = {}

  scheduler_options[:quiet] = be_quiet

  puts "Note: All partitions will be weighted evenly." unless be_quiet

  dest_templates_and_weights = manifest.templates.inject({}) do |h, (template, forwardings)|
    h[template] = ShardTemplate::DEFAULT_WEIGHT; h
  end

  @argv.each do |template_s|
    t     = ShardTemplate.parse(template_s)

    dest_templates_and_weights.delete(t)
  end

  transformations = global_options.tables.inject({}) do |all, table|
    trees      = manifest.trees.reject {|(f, s)| f.table_id != table }
    rebalancer = Rebalancer.new(trees, dest_templates_and_weights, copy_wrapper)

    all.update(rebalancer.transformations) {|t,a,b| a.merge b }
  end

  if transformations.empty?
    puts "Nothing to do!"
    exit
  end

  base_name = get_base_name(transformations)

  unless be_quiet
    transformations.each do |transformation, trees|
      puts transformation.inspect
      puts "Applied to #{trees.length} shards"
      #trees.keys.sort.each {|f| puts "  #{f.inspect}" }
    end
    puts ""
  end

  confirm!

  Gizzard.schedule! manager,
                    base_name,
                    transformations,
                    scheduler_options
end