Permalink
Browse files

removed gizzmo code, moved to separate repo, pending amac approval.

  • Loading branch information...
Kyle Maxwell
Kyle Maxwell committed Jun 25, 2010
1 parent 114554c commit 784487ec282805a4e8ef04b44205a052d84a8912
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-$: << File.dirname(__FILE__) + "/../src/main/ruby"
-load "gizzmo.rb"
View
@@ -1,6 +0,0 @@
-$: << File.dirname(__FILE__)
-module Gizzard; end
-require "gizzard/consts"
-require "gizzard/thrift"
-require "gizzard/commands"
-require "gizzard/dsl"
@@ -1,57 +0,0 @@
-module Gizzard
- module Recipes
- def setup_migration_shards(source, destination)
- raise "Cannot migrate to the same shard" if source == destination
-
- write_only_shard_id = shard_id("localhost", source.table_prefix + "_migrate_write_only")
- write_only_shard = shard_info(write_only_shard_id, Consts::WRITE_ONLY_SHARD, "", "", 0)
- create_shard(write_only_shard)
- add_link(write_only_shard_id, destination)
-
- replicating_shard_id = shard_id("localhost", source.table_prefix + "_migrate_replicating")
- replicating_shard = shard_info(replicating_shard_id, Consts::REPLICATING_SHARD, "", "", 0)
- create_shard(replicating_shard)
-
- list_upward_links(source).each do |link|
- add_link(link.up_id, replicating_shard_id, link.weight)
- remove_link(link.up_id, link.down_id)
- end
-
- add_link(replicating_shard_id, source, 1)
- add_link(replicating_shard_id, write_only_shard_id, 1)
- replace_forwarding(source, replicating_shard_id)
-
- puts "Replication structure set up: #{source} => #{destination}."
- end
-
- def finish_migration(source, destination)
- replicating_shard_id = shard_id("localhost", source.table_prefix + "_migrate_replicating")
- write_only_shard_id = shard_id("localhost", source.table_prefix + "migrate_write_only")
- list_upward_links(replicating_shard_id).each do |link|
- add_link(link.up_id, destination, link.weight)
- remove_link(link.up_id, replicating_shard_id)
- end
-
- replace_forwarding(replicating_shard_id, destination)
- delete_shard(replicating_shard_id)
- delete_shard(write_only_shard_id)
- delete_shard(source_id)
- end
- end
-
- class Manager
- include DSL
- include Recipes
-
- def initialize(hostname, port = 7917)
- @client = hostname.is_a?(Gizzard::Thrift::ShardManager) ? hostname : Gizzard::Thrift::ShardManager.new(hostname, port)
- end
-
- def method_missing(method, *args, &block)
- @client.send(method, *args, &block)
- end
-
- def inspect_shard_tree(root_shard, prefix = '')
- end
- end
-end
@@ -1,150 +0,0 @@
-module Gizzard
- class Command
- include Thrift
-
- def self.run(command_name, *args)
- Gizzard.const_get("#{classify(command_name)}Command").new(*args).run
- end
-
- def self.classify(string)
- string.split(/\W+/).map{|s| s.capitalize }.join("")
- end
-
- attr_reader :service, :global_options, :argv, :command_options
- def initialize(service, global_options, argv, command_options)
- @service = service
- @global_options = global_options
- @argv = argv
- @command_options = command_options
- end
-
- def help!(message = nil)
- raise HelpNeededError, message
- end
- end
-
- class ReloadCommand < Command
- def run
- puts "Are you sure? Reloading will affect production services immediately! (Type 'yes')"
- if gets.chomp == "yes"
- service.reload_forwardings
- else
- STDERR.puts "aborted"
- end
- end
- end
-
- class LinkCommand < Command
- def run
- up_id, down_id, weight = argv
- help! if argv.length != 3
- weight = weight.to_i
- up_id = ShardId.parse(up_id)
- down_id = ShardId.parse(down_id)
- link = LinkInfo.new(up_id, down_id, weight)
- service.add_link(link.up_id, link.down_id, link.weight)
- puts link.to_unix
- end
- end
-
- class UnlinkCommand < Command
- def run
- up_id, down_id = argv
- up_id = ShardId.parse(up_id)
- down_id = ShardId.parse(down_id)
- service.remove_link(up_id, down_id)
- end
- end
-
- class UnwrapCommand < Command
- def run
- shard_ids = argv
- help! "No shards specified" if shard_ids.empty?
- shard_ids.each do |shard_id_string|
- shard_id = ShardId.parse(shard_id_string)
- service.list_upward_links(shard_id).each do |uplink|
- service.list_downward_links(shard_id).each do |downlink|
- service.add_link(uplink.up_id, downlink.down_id, uplink.weight)
- new_link = LinkInfo.new(uplink.up_id, downlink.down_id, uplink.weight)
- service.remove_link(uplink.up_id, uplink.down_id)
- service.remove_link(downlink.up_id, downlink.down_id)
- puts new_link.to_unix
- end
- end
- end
- end
- end
-
- class CreateCommand < Command
- def run
- help! if argv.length != 3
- host, table, class_name = argv
- busy = 0
- source_type = command_options.source_type || ""
- destination_type = command_options.destination_type || ""
- service.create_shard(ShardInfo.new(shard_id = ShardId.new(host, table), class_name, source_type, destination_type, busy))
- service.get_shard(shard_id)
- puts shard_id.to_unix
- end
- end
-
- class LinksCommand < Command
- def run
- shard_ids = @argv
- shard_ids.each do |shard_id_text|
- shard_id = ShardId.parse(shard_id_text)
- service.list_upward_links(shard_id).each do |link_info|
- puts link_info.to_unix
- end
- service.list_downward_links(shard_id).each do |link_info|
- puts link_info.to_unix
- end
- end
- end
- end
-
- class InfoCommand < Command
- def run
- shard_ids = @argv
- shard_ids.each do |shard_id|
- shard_info = service.get_shard(ShardId.parse(shard_id))
- puts shard_info.to_unix
- end
- end
- end
-
- class WrapCommand < Command
- def self.derive_wrapper_shard_id(shard_info, wrapping_class_name)
- prefix_prefix = wrapping_class_name.split(".").last.downcase.gsub("shard", "") + "_"
- ShardId.new(shard_info.id.hostname, prefix_prefix + shard_info.id.table_prefix)
- end
-
- def run
- class_name, *shard_ids = @argv
- help! "No shards specified" if shard_ids.empty?
- shard_ids.each do |shard_id_string|
- shard_id = ShardId.parse(shard_id_string)
- shard_info = service.get_shard(shard_id)
- service.create_shard(ShardInfo.new(wrapper_id = self.class.derive_wrapper_shard_id(shard_info, class_name), class_name, "", "", 0))
-
- existing_links = service.list_upward_links(shard_id)
- service.add_link(wrapper_id, shard_id, 1)
- existing_links.each do |link_info|
- service.add_link(link_info.up_id, wrapper_id, link_info.weight)
- service.remove_link(link_info.up_id, link_info.down_id)
- end
- puts wrapper_id.to_unix
- end
- end
- end
-
- class FindCommand < Command
- def run
- help!("host is a required option") unless command_options.shard_host
- service.shards_for_hostname(command_options.shard_host).each do |shard|
- next if command_options.shard_type && shard.class_name !~ Regexp.new(command_options.shard_type)
- puts shard.id.to_unix
- end
- end
- end
-end
@@ -1,6 +0,0 @@
-module Gizzard
- module Consts
- WRITE_ONLY_SHARD = "com.twitter.gizzard.shards.WriteOnlyShard"
- REPLICATING_SHARD = "com.twitter.gizzard.shards.ReplicatingShard"
- end
-end
@@ -1,13 +0,0 @@
-module Gizzard
- module DSL
- [:shard_id, :shard_info, :link_info, :shard_migration, :forwarding].each do |method|
- struct_class = method.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
- module_eval "def #{method}(*args); Thrift::#{struct_class}.new(*args) end"
- end
-
- def shard(hostname, table_prefix, *rest)
- id = shard_id(hostname, table_prefix)
- shard_info(id, *rest)
- end
- end
-end
@@ -1,123 +0,0 @@
-#!/usr/bin/env ruby
-require 'vendor/thrift_client/simple'
-
-module Gizzard
- module Thrift
- T = ThriftClient::Simple
-
- def self.struct(*args)
- T::StructType.new(*args)
- end
-
- ShardException = T.make_exception(:ShardException,
- T::Field.new(:description, T::STRING, 1)
- )
-
- ShardId = T.make_struct(:ShardId,
- T::Field.new(:hostname, T::STRING, 1),
- T::Field.new(:table_prefix, T::STRING, 2)
- )
-
- class ShardId
- def inspect
- "#{hostname}/#{table_prefix}"
- end
-
- alias_method :to_unix, :inspect
-
- def self.parse(string)
- new(*string.split("/"))
- end
- end
-
- ShardInfo = T.make_struct(:ShardInfo,
- T::Field.new(:id, struct(ShardId), 1),
- T::Field.new(:class_name, T::STRING, 2),
- T::Field.new(:source_type, T::STRING, 3),
- T::Field.new(:destination_type, T::STRING, 4),
- T::Field.new(:busy, T::I32, 5)
- )
-
- class ShardInfo
- def busy?
- busy && busy > 0
- end
-
- def inspect(short = false)
- "#{id.inspect}" + (busy? ? " (BUSY)" : "")
- end
-
- def to_unix
- [id.to_unix, class_name, busy? ? "busy" : "unbusy"].join("\t")
- end
- end
-
- LinkInfo = T.make_struct(:LinkInfo,
- T::Field.new(:up_id, struct(ShardId), 1),
- T::Field.new(:down_id, struct(ShardId), 2),
- T::Field.new(:weight, T::I32, 3)
- )
-
- class LinkInfo
- def inspect
- "#{up_id.inspect} -> #{down_id.inspect}" + (weight == 1 ? "" : " <#{weight}>")
- end
-
- def to_unix
- [up_id.to_unix, down_id.to_unix, weight].join("\t")
- end
-
- end
-
- ShardMigration = T.make_struct(:ShardMigration,
- T::Field.new(:source_id, struct(ShardId), 1),
- T::Field.new(:destination_id, struct(ShardId), 2)
- )
-
- Forwarding = T.make_struct(:Forwarding,
- T::Field.new(:table_id, T::I32, 1),
- T::Field.new(:base_id, T::I64, 2),
- T::Field.new(:shard_id, struct(ShardId), 3)
- )
-
- class Forwarding
- #FIXME table_id is not human-readable
- def inspect
- "[#{table_id}] #{base_id.to_s(16)} -> #{shard_id.inspect}"
- end
- end
-
- class ShardManager < T::ThriftService
- thrift_method :create_shard, void, field(:shard, struct(ShardInfo), 1), :throws => exception(ShardException)
- thrift_method :delete_shard, void, field(:id, struct(ShardId), 1)
- thrift_method :get_shard, struct(ShardInfo), field(:id, struct(ShardId), 1)
-
- thrift_method :add_link, void, field(:up_id, struct(ShardId), 1), field(:down_id, struct(ShardId), 2), field(:weight, i32, 3)
- thrift_method :remove_link, void, field(:up_id, struct(ShardId), 1), field(:down_id, struct(ShardId), 2)
-
- thrift_method :list_upward_links, list(struct(LinkInfo)), field(:id, struct(ShardId), 1)
- thrift_method :list_downward_links, list(struct(LinkInfo)), field(:id, struct(ShardId), 1)
-
- thrift_method :get_child_shards_of_class, list(struct(ShardInfo)), field(:parent_id, struct(ShardId), 1), field(:class_name, string, 2)
-
- thrift_method :mark_shard_busy, void, field(:id, struct(ShardId), 1), field(:busy, i32, 2)
- thrift_method :copy_shard, void, field(:source_id, struct(ShardId), 1), field(:destination_id, struct(ShardId), 2)
-
- thrift_method :set_forwarding, void, field(:forwarding, struct(Forwarding), 1)
- thrift_method :replace_forwarding, void, field(:old_id, struct(ShardId), 1), field(:new_id, struct(ShardId), 2)
-
- thrift_method :get_forwarding, struct(Forwarding), field(:table_id, i32, 1), field(:base_id, i64, 2)
- thrift_method :get_forwarding_for_shard, struct(Forwarding), field(:shard_id, struct(ShardId), 1)
-
- thrift_method :get_forwardings, list(struct(Forwarding))
- thrift_method :reload_forwardings, void
-
- thrift_method :find_current_forwarding, struct(ShardInfo), field(:table_id, i32, 1), field(:id, i64, 2)
-
- thrift_method :shards_for_hostname, list(struct(ShardInfo)), field(:hostname, string, 1)
- thrift_method :get_busy_shards, list(struct(ShardInfo))
-
- thrift_method :rebuild_schema, void
- end
- end
-end
Oops, something went wrong.

0 comments on commit 784487e

Please sign in to comment.