Class: Gizzard::RepairTablesCommand

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

#concrete_leaves(tree) ⇒ Object



581
582
583
584
585
586
587
588
# File 'lib/gizzard/commands.rb', line 581

def concrete_leaves(tree)
  list = []
  list << tree.info.id if tree.children.empty? && !tree.info.class_name.include?("BlackHoleShard")
  tree.children.each do |child|
    list += concrete_leaves(child)
  end
  list
end

#runObject



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/gizzard/commands.rb', line 558

def run
  require_tables

  table_ids = global_options.tables
  manifest = manager.manifest(*table_ids)
  num_copies = command_options.num_copies || 100
  shard_sets = []
  manifest.trees.values.each do |tree|
    shard_sets << concrete_leaves(tree)
  end
  shard_sets.each do |shard_ids|
    while  manager.get_busy_shards().size > num_copies
      sleep 1
    end
    puts "Repairing " + shard_ids.map {|s| s.to_unix }.join(",")
    manager.copy_shard(shard_ids)
  end

  while manager.get_busy_shards().size > 0
    sleep 5
  end
end