flare-tools 0.1.4 → 0.4.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Flare-tools.txt +0 -0
- data/History.txt +114 -2
- data/LICENSE +21 -0
- data/Manifest.txt +65 -8
- data/README.txt +356 -0
- data/Rakefile +90 -25
- data/Tutorial.txt +370 -0
- data/bin/flare-admin +6 -0
- data/bin/flare-argv0 +6 -0
- data/bin/flare-deploy +6 -0
- data/bin/flare-keychecker +6 -0
- data/bin/flare-part +6 -0
- data/bin/flare-ping +6 -0
- data/bin/flare-stats +4 -10
- data/bin/flare-zkadmin +6 -0
- data/lib/flare/net/connection.rb +98 -0
- data/lib/flare/test/cluster.rb +140 -0
- data/lib/flare/test/daemon.rb +144 -0
- data/lib/flare/test/node.rb +62 -0
- data/lib/flare/tools.rb +18 -16
- data/lib/flare/tools/cli.rb +32 -0
- data/lib/flare/tools/cli/activate.rb +106 -0
- data/lib/flare/tools/cli/balance.rb +83 -0
- data/lib/flare/tools/cli/cli_util.rb +77 -0
- data/lib/flare/tools/cli/deploy.rb +170 -0
- data/lib/flare/tools/cli/down.rb +85 -0
- data/lib/flare/tools/cli/dump.rb +219 -0
- data/lib/flare/tools/cli/dumpkey.rb +117 -0
- data/lib/flare/tools/cli/flare_admin.rb +81 -0
- data/lib/flare/tools/cli/flare_argv0.rb +60 -0
- data/lib/flare/tools/cli/flare_keychecker.rb +106 -0
- data/lib/flare/tools/cli/flare_zkadmin.rb +226 -0
- data/lib/flare/tools/cli/index.rb +54 -0
- data/lib/flare/tools/cli/list.rb +93 -0
- data/lib/flare/tools/cli/master.rb +143 -0
- data/lib/flare/tools/cli/part.rb +100 -0
- data/lib/flare/tools/cli/ping.rb +81 -0
- data/lib/flare/tools/cli/reconstruct.rb +164 -0
- data/lib/flare/tools/cli/remove.rb +119 -0
- data/lib/flare/tools/cli/restore.rb +180 -0
- data/lib/flare/tools/cli/slave.rb +125 -0
- data/lib/flare/tools/cli/stats.rb +229 -122
- data/lib/flare/tools/cli/sub_command.rb +73 -0
- data/lib/flare/tools/cli/summary.rb +97 -0
- data/lib/flare/tools/cli/threads.rb +78 -0
- data/lib/flare/tools/cli/verify.rb +202 -0
- data/lib/flare/tools/client.rb +267 -0
- data/lib/flare/tools/cluster.rb +319 -0
- data/lib/flare/tools/common.rb +196 -0
- data/lib/flare/tools/index_server.rb +51 -0
- data/lib/flare/tools/node.rb +162 -0
- data/lib/flare/tools/stats.rb +75 -0
- data/lib/flare/tools/zk_util.rb +28 -0
- data/lib/flare/util.rb +34 -0
- data/lib/flare/util/bwlimit.rb +132 -0
- data/lib/flare/util/command_line.rb +79 -0
- data/lib/flare/util/conf.rb +71 -0
- data/lib/flare/util/constant.rb +25 -0
- data/lib/flare/util/conversion.rb +26 -0
- data/lib/flare/util/default_logger.rb +52 -0
- data/lib/flare/util/exception.rb +19 -0
- data/lib/flare/util/filesystem.rb +30 -0
- data/lib/flare/util/flared_conf.rb +33 -0
- data/lib/flare/util/flarei_conf.rb +32 -0
- data/lib/flare/util/hash_function.rb +32 -0
- data/lib/flare/util/interruption.rb +70 -0
- data/lib/flare/util/key_resolver.rb +67 -0
- data/lib/flare/util/log4r_logger.rb +79 -0
- data/lib/flare/util/logger.rb +40 -0
- data/lib/flare/util/logging.rb +84 -0
- data/lib/flare/util/result.rb +53 -0
- data/test/test/experimental/cache_test.rb +113 -0
- data/test/test/experimental/key_distribution_test.rb +38 -0
- data/test/test/experimental/keychecker_test.rb +60 -0
- data/test/test/experimental/list_test.rb +108 -0
- data/test/test/extra/replication_test.rb +184 -0
- data/test/test/integration/cli_test.rb +348 -0
- data/test/test/integration/dump_expired_test.rb +103 -0
- data/test/test/integration/dump_test.rb +128 -0
- data/test/test/integration/index_server_test.rb +35 -0
- data/test/test/integration/node_test.rb +78 -0
- data/test/test/integration/partition_test.rb +235 -0
- data/test/test/integration/proxy_test.rb +54 -0
- data/test/test/integration/stats_test.rb +79 -0
- data/test/test/system/flare_admin_test.rb +191 -0
- data/test/test/unit/bwlimit_test.rb +52 -0
- data/test/test/unit/cluster_test.rb +96 -0
- data/test/test/unit/daemon_test.rb +30 -0
- data/test/test/unit/logger_test.rb +46 -0
- data/test/test/unit/tools_test.rb +25 -0
- data/test/test/unit/util_test.rb +70 -0
- metadata +239 -84
- data/README.rdoc +0 -83
- data/bin/flare-partition-setting +0 -12
- data/lib/flare/tools/cli/partition_setting.rb +0 -86
- data/lib/flare/tools/core.rb +0 -189
- data/lib/flare/tools/logger.rb +0 -31
- data/test/test_flare-tools.rb +0 -11
- data/test/test_helper.rb +0 -3
data/bin/flare-admin
ADDED
data/bin/flare-argv0
ADDED
data/bin/flare-deploy
ADDED
data/bin/flare-part
ADDED
data/bin/flare-ping
ADDED
data/bin/flare-stats
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
2
|
# -*- coding: utf-8; -*-
|
3
|
-
# Author:: kgws (http://d.hatena.ne.jp/kgws/)
|
4
|
-
# Copyright:: Copyright (c) 2010- kgws.
|
5
|
-
# License:: This program is licenced under the same licence as kgws.
|
6
|
-
#
|
7
|
-
# $--- flare-partition-setting - [ by Ruby ] $
|
8
|
-
# vim: foldmethod=marker tabstop=2 shiftwidth=2
|
9
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
|
10
|
-
require 'flare/tools/cli/stats'
|
11
3
|
|
12
|
-
|
4
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)+"/../lib"
|
5
|
+
|
6
|
+
require 'flare/tools/cli/flare_argv0.rb'
|
data/bin/flare-zkadmin
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# -*- coding: utf-8; -*-
|
2
|
+
# Authors:: Kiyoshi Ikehara <kiyoshi.ikehara@gree.net>
|
3
|
+
# Copyright:: Copyright (C) GREE, Inc. 2011.
|
4
|
+
# License:: MIT-style
|
5
|
+
|
6
|
+
require 'timeout'
|
7
|
+
require 'socket'
|
8
|
+
require 'flare/util'
|
9
|
+
require 'flare/util/logging'
|
10
|
+
require 'flare/util/result'
|
11
|
+
require 'flare/util/bwlimit'
|
12
|
+
|
13
|
+
#
|
14
|
+
module Flare
|
15
|
+
module Net
|
16
|
+
|
17
|
+
# == Description
|
18
|
+
#
|
19
|
+
class Connection
|
20
|
+
include Flare::Util::Logging
|
21
|
+
include Flare::Util::Result
|
22
|
+
|
23
|
+
def initialize(host, port, uplink_limit = nil, downlink_limit = nil)
|
24
|
+
@host = host
|
25
|
+
@port = port
|
26
|
+
@socket = TCPSocket.open(host, port)
|
27
|
+
@last_sent = ""
|
28
|
+
@sent_size = 0
|
29
|
+
@received_size = 0
|
30
|
+
@uplink_limit = Flare::Util::Bwlimit.new(uplink_limit)
|
31
|
+
@downlink_limit = Flare::Util::Bwlimit.new(downlink_limit)
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :host, :port
|
35
|
+
attr_reader :sent_size, :received_size
|
36
|
+
|
37
|
+
def close
|
38
|
+
@socket.close unless @socket.closed?
|
39
|
+
end
|
40
|
+
|
41
|
+
def closed?
|
42
|
+
@socket.closed?
|
43
|
+
end
|
44
|
+
|
45
|
+
def reconnect
|
46
|
+
if @socket.closed?
|
47
|
+
@socket = nil
|
48
|
+
@socket = TCPSocket.open(@host, @port)
|
49
|
+
end
|
50
|
+
@socket
|
51
|
+
end
|
52
|
+
|
53
|
+
def send(cmd)
|
54
|
+
if $DEBUG
|
55
|
+
puts "--> server=[#{self}] cmd=[#{cmd.chomp}]"
|
56
|
+
end
|
57
|
+
size = cmd.size
|
58
|
+
@sent_size += size
|
59
|
+
@socket.write cmd
|
60
|
+
@last_sent = cmd
|
61
|
+
@uplink_limit.inc size
|
62
|
+
@uplink_limit.wait
|
63
|
+
end
|
64
|
+
|
65
|
+
def last_sent
|
66
|
+
@last_sent
|
67
|
+
end
|
68
|
+
|
69
|
+
def getline
|
70
|
+
ret = @socket.gets
|
71
|
+
return nil if ret.nil?
|
72
|
+
if $DEBUG
|
73
|
+
puts "<-- #{ret.chomp}"
|
74
|
+
end
|
75
|
+
size = ret.size
|
76
|
+
@received_size += size
|
77
|
+
@downlink_limit.inc size
|
78
|
+
@downlink_limit.wait
|
79
|
+
ret
|
80
|
+
end
|
81
|
+
|
82
|
+
def read(length = nil)
|
83
|
+
ret = @socket.read(length)
|
84
|
+
return nil if ret.nil?
|
85
|
+
size = ret.size
|
86
|
+
@received_size += size
|
87
|
+
@downlink_limit.inc size
|
88
|
+
@downlink_limit.wait
|
89
|
+
ret
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
"#{@host}:#{@port}"
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# -*- coding: utf-8; -*-
|
2
|
+
# Authors:: Kiyoshi Ikehara <kiyoshi.ikehara@gree.net>
|
3
|
+
# Copyright:: Copyright (C) GREE, Inc. 2011.
|
4
|
+
# License:: MIT-style
|
5
|
+
|
6
|
+
require 'uri'
|
7
|
+
require 'flare/tools'
|
8
|
+
require 'flare/test/daemon'
|
9
|
+
require 'flare/test/node'
|
10
|
+
|
11
|
+
#
|
12
|
+
module Flare
|
13
|
+
module Test
|
14
|
+
|
15
|
+
# == Description
|
16
|
+
#
|
17
|
+
class Cluster
|
18
|
+
include Flare::Tools::Common
|
19
|
+
|
20
|
+
def initialize(name, option = {})
|
21
|
+
if ENV.has_key?("FLARE_INDEX_DB") && !option.has_key?("index-db")
|
22
|
+
option["index-db"] = ENV["FLARE_INDEX_DB"]
|
23
|
+
end
|
24
|
+
|
25
|
+
if option.has_key?("index-db")
|
26
|
+
uri = URI.parse(option["index-db"])
|
27
|
+
if uri.scheme == "zookeeper"
|
28
|
+
z = ::Zookeeper.new("#{uri.host}:#{uri.port}")
|
29
|
+
Flare::Tools::ZkUtil.clear_nodemap z, uri.path
|
30
|
+
z.close
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
daemon = Daemon.instance
|
35
|
+
@indexport = daemon.assign_port
|
36
|
+
@workdir = Dir.pwd+"/work"
|
37
|
+
@datadir = [@workdir, "#{name}.#{@indexport}"].join('/')
|
38
|
+
@nodes = {}
|
39
|
+
|
40
|
+
@indexname = "localhost"
|
41
|
+
@index_pid = daemon.invoke_flarei(name, {
|
42
|
+
'server-name' => @indexname,
|
43
|
+
'server-port' => @indexport,
|
44
|
+
'data-dir' => @datadir,
|
45
|
+
}.merge(option))
|
46
|
+
@flare_xml = [@datadir, "flare.xml"].join('/')
|
47
|
+
sleep 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def indexname
|
51
|
+
@indexname
|
52
|
+
end
|
53
|
+
|
54
|
+
def indexport
|
55
|
+
@indexport
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_node(name, config = {}, executable = Daemon::Flared)
|
59
|
+
daemon = Daemon.instance
|
60
|
+
serverport = daemon.assign_port
|
61
|
+
|
62
|
+
datadir = [@datadir, "#{name}.#{serverport}"].join('.')
|
63
|
+
|
64
|
+
servername = "localhost"
|
65
|
+
pid = daemon.invoke_flared(name, {
|
66
|
+
'index-server-name' => @indexname,
|
67
|
+
'index-server-port' => @indexport,
|
68
|
+
'server-name' => servername,
|
69
|
+
'server-port' => serverport,
|
70
|
+
'data-dir' => datadir,
|
71
|
+
}.merge(config), executable)
|
72
|
+
hostname_port = "#{servername}:#{serverport}"
|
73
|
+
node = @nodes[hostname_port] = Node.new(hostname_port, pid)
|
74
|
+
node
|
75
|
+
end
|
76
|
+
|
77
|
+
def shutdown
|
78
|
+
daemon = Daemon.instance
|
79
|
+
daemon.shutdown
|
80
|
+
end
|
81
|
+
|
82
|
+
def nodes
|
83
|
+
@nodes.values
|
84
|
+
end
|
85
|
+
|
86
|
+
def wait_for_ready
|
87
|
+
Flare::Tools::IndexServer.open(indexname, indexport, 10) do |s|
|
88
|
+
wait_for_servers(s)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def prepare_master_and_slaves(nodes, partition = 0)
|
93
|
+
Flare::Tools::IndexServer.open(indexname, indexport, 10) do |s|
|
94
|
+
slaves = nodes.dup
|
95
|
+
master = slaves.shift
|
96
|
+
|
97
|
+
# master
|
98
|
+
s.set_role(master.hostname, master.port, 'master', 1, partition)
|
99
|
+
wait_for_master_construction(s, "#{master.hostname}:#{master.port}", 10)
|
100
|
+
s.set_state(master.hostname, master.port, 'active')
|
101
|
+
|
102
|
+
# slave
|
103
|
+
slaves.each do |n|
|
104
|
+
s.set_role(n.hostname, n.port, 'slave', 1, partition)
|
105
|
+
wait_for_slave_construction(s, "#{n.hostname}:#{n.port}", 10, true)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def prepare_data(node, prefix, count)
|
111
|
+
Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
|
112
|
+
fmt = "#{prefix}%010.10d"
|
113
|
+
(0...count).each do |i|
|
114
|
+
n.set(fmt % i, "All your base are belong to us.")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def clear_data(node)
|
120
|
+
Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
|
121
|
+
n.flush_all
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def exist?(node)
|
126
|
+
return Flare::Tools::IndexServer.open(indexname, indexport, 10) do |s|
|
127
|
+
nodes_stats = s.stats_nodes
|
128
|
+
nodes_stats.has_key? node
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def index
|
133
|
+
open(@flare_xml) do |f|
|
134
|
+
f.read
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# -*- coding: utf-8; -*-
|
2
|
+
# Authors:: Kiyoshi Ikehara <kiyoshi.ikehara@gree.net>
|
3
|
+
# Copyright:: Copyright (C) GREE, Inc. 2011.
|
4
|
+
# License:: MIT-style
|
5
|
+
|
6
|
+
require 'timeout'
|
7
|
+
require 'singleton'
|
8
|
+
require 'thread'
|
9
|
+
|
10
|
+
require 'flare/util/flarei_conf'
|
11
|
+
require 'flare/util/flared_conf'
|
12
|
+
|
13
|
+
#
|
14
|
+
module Flare
|
15
|
+
module Test
|
16
|
+
class Daemon
|
17
|
+
include Singleton
|
18
|
+
|
19
|
+
Flarei = "/usr/local/bin/flarei"
|
20
|
+
Flared = "/usr/local/bin/flared"
|
21
|
+
|
22
|
+
FlareiVersion = `#{Flarei} -v`.chomp.split(' ')[-1]
|
23
|
+
FlaredVersion = `#{Flared} -v`.chomp.split(' ')[-1]
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@flared = []
|
27
|
+
@flarei = []
|
28
|
+
@port = 20000+rand(10000)
|
29
|
+
@port_mutex = Mutex.new
|
30
|
+
@tempfiles = []
|
31
|
+
Kernel.at_exit {
|
32
|
+
Flare::Test::Daemon.instance.shutdown
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def shutdown
|
37
|
+
STDERR.print "killing..."
|
38
|
+
(@flared+@flarei).each do |pid|
|
39
|
+
STDERR.print " #{pid}"
|
40
|
+
begin
|
41
|
+
timeout(10) do
|
42
|
+
Process.kill :TERM, pid
|
43
|
+
Process.waitpid pid
|
44
|
+
end
|
45
|
+
rescue Errno::ESRCH
|
46
|
+
STDERR.print "?"
|
47
|
+
rescue TimeoutError => e
|
48
|
+
Process.kill :KILL, pid
|
49
|
+
Process.waitpid pid
|
50
|
+
STDERR.print "*"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
STDERR.print "\n"
|
54
|
+
Process.waitall
|
55
|
+
@flared.clear
|
56
|
+
@flarei.clear
|
57
|
+
@tempfiles.each do |datadir|
|
58
|
+
deleteall(datadir)
|
59
|
+
end
|
60
|
+
@tempfiles.clear
|
61
|
+
end
|
62
|
+
|
63
|
+
def required_version? required_version
|
64
|
+
version = FlareiVersion.split('.').map {|i| i.to_i}
|
65
|
+
(0...required_version.size).each do |i|
|
66
|
+
n = if i < version.size then version[i] else 0 end
|
67
|
+
return true if n > required_version[i]
|
68
|
+
return false if n < required_version[i]
|
69
|
+
end
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
def assign_port
|
74
|
+
port = 0
|
75
|
+
@port_mutex.synchronize do
|
76
|
+
port = @port
|
77
|
+
@port += 1
|
78
|
+
end
|
79
|
+
port
|
80
|
+
end
|
81
|
+
|
82
|
+
def invoke_flarei(name, config, executable = Flarei)
|
83
|
+
config["key-hash-algorithm"] = "crc32" if required_version? [1, 0, 15]
|
84
|
+
config = Flare::Util::FlareiConf.new(config)
|
85
|
+
conf = "/tmp/flarei.#{name}.#{config.server_port}.conf"
|
86
|
+
open(conf, "w") do |f|
|
87
|
+
f.puts config.to_s
|
88
|
+
end
|
89
|
+
pid = fork
|
90
|
+
if pid.nil?
|
91
|
+
deleteall(config.data_dir)
|
92
|
+
Dir.mkdir(config.data_dir)
|
93
|
+
begin
|
94
|
+
exec executable, "-f", conf
|
95
|
+
rescue
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
else
|
99
|
+
@flarei << pid
|
100
|
+
@tempfiles << config.data_dir
|
101
|
+
@tempfiles << conf
|
102
|
+
end
|
103
|
+
pid
|
104
|
+
end
|
105
|
+
|
106
|
+
def invoke_flared(name, config, executable = Flared)
|
107
|
+
config = Flare::Util::FlaredConf.new(config)
|
108
|
+
conf = "/tmp/flared.#{name}.#{config.server_port}.conf"
|
109
|
+
open(conf, "w") do |f|
|
110
|
+
f.puts config.to_s
|
111
|
+
end
|
112
|
+
pid = fork
|
113
|
+
if pid.nil?
|
114
|
+
deleteall(config.data_dir)
|
115
|
+
Dir.mkdir(config.data_dir)
|
116
|
+
begin
|
117
|
+
exec executable, "-f", conf
|
118
|
+
rescue
|
119
|
+
exit 1
|
120
|
+
end
|
121
|
+
else
|
122
|
+
@flared << pid
|
123
|
+
@tempfiles << config.data_dir
|
124
|
+
@tempfiles << conf
|
125
|
+
end
|
126
|
+
pid
|
127
|
+
end
|
128
|
+
|
129
|
+
def deleteall(delthem)
|
130
|
+
return unless FileTest.exist?(delthem)
|
131
|
+
if FileTest.directory?(delthem)
|
132
|
+
Dir.foreach(delthem) do |file|
|
133
|
+
next if /^\.+$/ =~ file
|
134
|
+
deleteall(delthem.sub(/\/+$/,"") + "/" + file)
|
135
|
+
end
|
136
|
+
Dir.rmdir(delthem) rescue ""
|
137
|
+
else
|
138
|
+
File.delete(delthem)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|