Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add --fnv option to lookup.

  • Loading branch information...
commit 710fd887f0af67529277777101061212c333d6e2 1 parent 5f870d6
Robey Pointer authored
View
3  lib/gizzard.rb
@@ -1,4 +1,5 @@
$: << File.dirname(__FILE__)
module Gizzard; end
require "gizzard/thrift"
-require "gizzard/commands"
+require "gizzard/commands"
+require "gizzard/hash"
View
16 lib/gizzard/commands.rb
@@ -229,7 +229,7 @@ def run
end
end
end
-
+
class RepairCommand < ShardCommand
def run
args = @argv.dup.map{|a| a.split(/\s+/)}.flatten
@@ -297,7 +297,7 @@ def run
memo[id.hostname] << id
memo
end
-
+
additional_hosts.each do |host|
by_host[host] ||= NamedArray.new(host)
end
@@ -417,9 +417,15 @@ def run
class LookupCommand < ShardCommand
def run
- table_id, source_id = @argv
- help!("Requires table id and source id") unless table_id && source_id
- shard = service.find_current_forwarding(table_id.to_i, source_id.to_i)
+ table_id, source = @argv
+ help!("Requires table id and source") unless table_id && source
+ case @command_options.hash_function
+ when :fnv
+ source_id = Hash.fnv1a_64(source)
+ else
+ source_id = source.to_i
+ end
+ shard = service.find_current_forwarding(table_id.to_i, source_id)
output shard.id.to_unix
end
end
View
13 lib/gizzard/hash.rb
@@ -0,0 +1,13 @@
+module Gizzard
+ module Hash
+ def self.fnv1a_64(data)
+ prime = 1099511628211
+ rv = 0xcbf29ce484222325
+ data.each_byte do |byte|
+ rv = ((rv ^ (byte.ord & 0xff)) * prime) & 0xffffffffffffffff
+ end
+ # trim to 60 bits for gizzard.
+ rv & 0x0fffffffffffffff
+ end
+ end
+end
View
9 lib/gizzmo.rb
@@ -9,7 +9,8 @@ class HelpNeededError < RuntimeError; end
DOC_STRINGS = {
"create" => "Create shard(s) of a given Java/Scala class. If you don't know the list of available classes, you can just try a bogus class, and the exception will include a list of valid classes.",
"wrap" => "Wrapping creates a new (virtual, e.g. blocking, replicating, etc.) shard, and relinks SHARD_ID_TO_WRAP's parent links to run through the new shard.",
- "inject" => "Inject jobs (as literal json) into the server. Jobs can be linefeed-terminated from stdin, or passed as arguments. Priority is server-defined, but typically lower numbers (like 1) are lower priority."
+ "inject" => "Inject jobs (as literal json) into the server. Jobs can be linefeed-terminated from stdin, or passed as arguments. Priority is server-defined, but typically lower numbers (like 1) are lower priority.",
+ "lookup" => "Lookup the shard id that holds the record for a given table / source_id."
}
ORIGINAL_ARGV = ARGV.dup
@@ -169,8 +170,12 @@ def separators(opts, string)
separators(opts, DOC_STRINGS["unlink"])
end,
'lookup' => OptionParser.new do |opts|
- opts.banner = "Usage: #{zero} lookup TABLE_ID SOURCE_ID"
+ opts.banner = "Usage: #{zero} lookup [options] TABLE_ID SOURCE"
separators(opts, DOC_STRINGS["lookup"])
+
+ opts.on("--fnv", "Use FNV1A_64 hash on source") do
+ subcommand_options.hash_function = :fnv
+ end
end,
'copy' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} copy SOURCE_SHARD_ID DESTINATION_SHARD_ID"
Please sign in to comment.
Something went wrong with that request. Please try again.