ls4 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/COPYING +661 -0
- data/ChangeLog +9 -0
- data/NOTICE +8 -0
- data/README.rdoc +61 -0
- data/bin/ls4-cs +3 -0
- data/bin/ls4-ds +3 -0
- data/bin/ls4-gw +3 -0
- data/bin/ls4-standalone +3 -0
- data/bin/ls4cmd +3 -0
- data/bin/ls4ctl +3 -0
- data/bin/ls4rpc +3 -0
- data/bin/ls4stat +3 -0
- data/bin/ls4top +3 -0
- data/lib/ls4/command/cmd.rb +241 -0
- data/lib/ls4/command/cs.rb +190 -0
- data/lib/ls4/command/ctl.rb +278 -0
- data/lib/ls4/command/ds.rb +335 -0
- data/lib/ls4/command/gw.rb +256 -0
- data/lib/ls4/command/rpc.rb +172 -0
- data/lib/ls4/command/standalone.rb +318 -0
- data/lib/ls4/command/stat.rb +244 -0
- data/lib/ls4/command/top.rb +291 -0
- data/lib/ls4/default.rb +26 -0
- data/lib/ls4/lib/cclog.rb +220 -0
- data/lib/ls4/lib/ebus.rb +553 -0
- data/lib/ls4/lib/vbcode.rb +228 -0
- data/lib/ls4/logic/fault_detector.rb +212 -0
- data/lib/ls4/logic/membership.rb +253 -0
- data/lib/ls4/logic/node.rb +66 -0
- data/lib/ls4/logic/okey.rb +45 -0
- data/lib/ls4/logic/tsv_data.rb +81 -0
- data/lib/ls4/logic/weight.rb +166 -0
- data/lib/ls4/service/balance.rb +62 -0
- data/lib/ls4/service/base.rb +29 -0
- data/lib/ls4/service/bus.rb +37 -0
- data/lib/ls4/service/config.rb +63 -0
- data/lib/ls4/service/config_cs.rb +33 -0
- data/lib/ls4/service/config_ds.rb +56 -0
- data/lib/ls4/service/config_gw.rb +42 -0
- data/lib/ls4/service/data_client.rb +122 -0
- data/lib/ls4/service/data_server.rb +168 -0
- data/lib/ls4/service/data_server_url.rb +83 -0
- data/lib/ls4/service/gateway.rb +375 -0
- data/lib/ls4/service/gateway_ro.rb +91 -0
- data/lib/ls4/service/gw_http.rb +821 -0
- data/lib/ls4/service/heartbeat.rb +182 -0
- data/lib/ls4/service/log.rb +81 -0
- data/lib/ls4/service/master_select.rb +148 -0
- data/lib/ls4/service/mds.rb +292 -0
- data/lib/ls4/service/mds_cache.rb +294 -0
- data/lib/ls4/service/mds_cache_mem.rb +63 -0
- data/lib/ls4/service/mds_cache_memcached.rb +65 -0
- data/lib/ls4/service/mds_ha.rb +176 -0
- data/lib/ls4/service/mds_memcache.rb +209 -0
- data/lib/ls4/service/mds_tc.rb +508 -0
- data/lib/ls4/service/mds_tt.rb +472 -0
- data/lib/ls4/service/membership.rb +331 -0
- data/lib/ls4/service/process.rb +90 -0
- data/lib/ls4/service/rpc.rb +50 -0
- data/lib/ls4/service/rpc_cs.rb +101 -0
- data/lib/ls4/service/rpc_ds.rb +96 -0
- data/lib/ls4/service/rpc_gw.rb +255 -0
- data/lib/ls4/service/rts.rb +94 -0
- data/lib/ls4/service/rts_file.rb +76 -0
- data/lib/ls4/service/rts_memory.rb +55 -0
- data/lib/ls4/service/slave.rb +132 -0
- data/lib/ls4/service/stat.rb +91 -0
- data/lib/ls4/service/stat_cs.rb +25 -0
- data/lib/ls4/service/stat_ds.rb +40 -0
- data/lib/ls4/service/stat_gw.rb +25 -0
- data/lib/ls4/service/storage.rb +116 -0
- data/lib/ls4/service/storage_dir.rb +201 -0
- data/lib/ls4/service/sync.rb +206 -0
- data/lib/ls4/service/time_check.rb +80 -0
- data/lib/ls4/service/ulog.rb +159 -0
- data/lib/ls4/service/ulog_file.rb +398 -0
- data/lib/ls4/service/ulog_memory.rb +53 -0
- data/lib/ls4/service/weight.rb +134 -0
- data/lib/ls4/version.rb +5 -0
- data/test/01_add_get_remove.rt +84 -0
- data/test/02_read.rt +61 -0
- data/test/03_getd_readd.rt +69 -0
- data/test/04_version_time.rt +170 -0
- data/test/05_version_name.rt +161 -0
- data/test/06_http_get_set_remove_1.rt +119 -0
- data/test/07_http_get_set_remove_2.rt +116 -0
- data/test/08_read_only_time.rt +177 -0
- data/test/09_read_only_name.rt +173 -0
- data/test/10_http_get_set_remove_3.rt +73 -0
- data/test/11_mds_cache_memcached.rt +88 -0
- data/test/12_mds_cache_local_memory.rt +86 -0
- data/test/13_memcache_mds.rt +84 -0
- data/test/14_delete.rt +63 -0
- data/test/15_standalone.rt +71 -0
- data/test/chukan.rb +516 -0
- data/test/common.rb +250 -0
- data/test/load_test.rb +79 -0
- data/test/load_test_offload.rb +86 -0
- metadata +295 -0
@@ -0,0 +1,278 @@
|
|
1
|
+
#
|
2
|
+
# LS4
|
3
|
+
# Copyright (C) 2010-2011 FURUHASHI Sadayuki
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Affero General Public License as
|
7
|
+
# published by the Free Software Foundation, either version 3 of the
|
8
|
+
# License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
#
|
18
|
+
require 'msgpack/rpc'
|
19
|
+
require 'pp'
|
20
|
+
|
21
|
+
def usage
|
22
|
+
puts "Usage: #{File.basename($0)} <cs address[:port]> <command> [options]"
|
23
|
+
puts "command:"
|
24
|
+
puts " nodes show list of nodes"
|
25
|
+
puts " stat show statistics of nodes"
|
26
|
+
puts " remove_node <nid> remove a node from a replica-set"
|
27
|
+
puts " locate <key> show which servers store the key"
|
28
|
+
puts " weight show list of replica-sets"
|
29
|
+
puts " set_weight <rsid> <weight> change a weight of a replica-set"
|
30
|
+
puts " mds show MDS uri"
|
31
|
+
puts " set_mds <expr> set MDS uri"
|
32
|
+
puts " mds_cache show MDS cache uri"
|
33
|
+
puts " set_mds_cache <expr> set MDS cache uri"
|
34
|
+
puts " items show stored number of objects"
|
35
|
+
puts " version show software version of nodes"
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
if ARGV.length < 2
|
40
|
+
usage
|
41
|
+
end
|
42
|
+
|
43
|
+
$net = MessagePack::RPC::SessionPool.new
|
44
|
+
addr = ARGV.shift
|
45
|
+
host, port = addr.split(':', 2)
|
46
|
+
port = port.to_i
|
47
|
+
port = 18700 if port == 0
|
48
|
+
$addr = [host,port]#Address.new(host, port)
|
49
|
+
|
50
|
+
cmd = ARGV.shift
|
51
|
+
|
52
|
+
def cmd_args(n)
|
53
|
+
if n < 0
|
54
|
+
return ARGV
|
55
|
+
end
|
56
|
+
usage if ARGV.length != n
|
57
|
+
ARGV.map! {|ar| ar == '-' ? $stdin.read : ar }
|
58
|
+
if n == 1
|
59
|
+
ARGV[0]
|
60
|
+
else
|
61
|
+
ARGV
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def call(klass, *args)
|
66
|
+
#start = Time.now
|
67
|
+
|
68
|
+
s = $net.get_session(*$addr)
|
69
|
+
s.timeout = 20
|
70
|
+
result = s.call(*args)
|
71
|
+
if klass && result
|
72
|
+
result = klass.new.from_msgpack(result)
|
73
|
+
end
|
74
|
+
|
75
|
+
#finish = Time.now
|
76
|
+
#puts "#{finish - start} sec."
|
77
|
+
|
78
|
+
result
|
79
|
+
end
|
80
|
+
|
81
|
+
Node = Struct.new('Node', :nid, :address, :name, :rsids, :location)
|
82
|
+
|
83
|
+
def get_nodes
|
84
|
+
call(nil, :stat, 'nodes').map {|nid,address,name,rsids,location|
|
85
|
+
address = MessagePack::RPC::Address.load(address)
|
86
|
+
Node.new(nid, address, name, rsids, location)
|
87
|
+
}.sort_by {|node|
|
88
|
+
node.nid
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_node_map
|
93
|
+
map = {}
|
94
|
+
call(nil, :stat, 'nodes').each {|nid,address,name,rsids|
|
95
|
+
address = MessagePack::RPC::Address.load(address)
|
96
|
+
map[nid] = [address, name, rsids]
|
97
|
+
}
|
98
|
+
map
|
99
|
+
end
|
100
|
+
|
101
|
+
def each_node(&block)
|
102
|
+
get_nodes.map {|node|
|
103
|
+
result = yield($net.get_session(node.address), node)
|
104
|
+
[node, result]
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
case cmd
|
109
|
+
when 'nodes'
|
110
|
+
cmd_args(0)
|
111
|
+
|
112
|
+
fault_nids = call(nil, :stat, 'fault')
|
113
|
+
|
114
|
+
NODES_FORMAT = "%3s %15s %23s %23s %7s %10s"
|
115
|
+
puts NODES_FORMAT % %w[nid name address location rsid state]
|
116
|
+
|
117
|
+
each_node {|s,node|
|
118
|
+
rsids = node.rsids.sort.join(',')
|
119
|
+
state = fault_nids.include?(node.nid) ? 'FAULT' : 'active'
|
120
|
+
puts NODES_FORMAT % [node.nid, node.name, node.address, node.location, rsids, state]
|
121
|
+
}
|
122
|
+
|
123
|
+
when 'remove_node'
|
124
|
+
nid_s = cmd_args(1)
|
125
|
+
nid = nid_s.to_i
|
126
|
+
if nid.to_s != nid_s
|
127
|
+
raise "invalid nid: #{nid}"
|
128
|
+
end
|
129
|
+
pp call(nil, :remove_node, nid)
|
130
|
+
|
131
|
+
when 'weight'
|
132
|
+
cmd_args(0)
|
133
|
+
REPLSET_FORMAT = "%4s %8s %10s %s"
|
134
|
+
puts REPLSET_FORMAT % %w[rsid weight nids names]
|
135
|
+
node_map = get_node_map
|
136
|
+
rsid_replset = call(nil, :stat, 'replset').sort_by {|rsid,(nids,weight)|
|
137
|
+
if nids.empty?
|
138
|
+
rsid += (2<<16)
|
139
|
+
end
|
140
|
+
rsid
|
141
|
+
}
|
142
|
+
rsid_replset.each {|rsid,(nids,weight)|
|
143
|
+
names = nids.map {|nid| node_map[nid][1] }.join(',')
|
144
|
+
nids = nids.sort.join(',')
|
145
|
+
puts REPLSET_FORMAT % [rsid, weight, nids, names]
|
146
|
+
}
|
147
|
+
|
148
|
+
when 'set_weight'
|
149
|
+
rsid_s, weight_s = cmd_args(2)
|
150
|
+
rsid = rsid_s.to_i
|
151
|
+
weight = weight_s.to_i
|
152
|
+
if rsid.to_s != rsid_s
|
153
|
+
raise "invalid rsid: #{rsid}"
|
154
|
+
end
|
155
|
+
if weight.to_s != weight_s
|
156
|
+
raise "invalid weight: #{weight}"
|
157
|
+
end
|
158
|
+
pp call(nil, :set_replset_weight, rsid, weight)
|
159
|
+
|
160
|
+
when 'reset_weight'
|
161
|
+
rsid_s = cmd_args(1)
|
162
|
+
rsid = rsid_s.to_i
|
163
|
+
if rsid.to_s != rsid_s
|
164
|
+
raise "invalid rsid: #{rsid}"
|
165
|
+
end
|
166
|
+
pp call(nil, :reset_replset_weight, rsid)
|
167
|
+
|
168
|
+
when 'mds'
|
169
|
+
cmd_args(0)
|
170
|
+
uri = call(nil, :get_mds_uri)
|
171
|
+
puts uri
|
172
|
+
|
173
|
+
when 'set_mds'
|
174
|
+
uri = cmd_args(1)
|
175
|
+
pp call(nil, :set_mds_uri, uri)
|
176
|
+
|
177
|
+
when 'mds_cache'
|
178
|
+
cmd_args(0)
|
179
|
+
uri = call(nil, :get_mds_cache_uri)
|
180
|
+
if !uri || uri.empty?
|
181
|
+
puts "null"
|
182
|
+
else
|
183
|
+
puts uri
|
184
|
+
end
|
185
|
+
|
186
|
+
when 'set_mds_cache'
|
187
|
+
uri = cmd_args(1)
|
188
|
+
pp call(nil, :set_mds_cache_uri, uri)
|
189
|
+
|
190
|
+
when 'stat', 'status'
|
191
|
+
STAT_FORMAT = "%4s %15s %10s %10s %10s %10s %30s"
|
192
|
+
puts STAT_FORMAT % %w[nid name uptime #read #write #delete time]
|
193
|
+
each_node {|s,node|
|
194
|
+
f_uptime = s.call_async(:stat, 'uptime') rescue nil
|
195
|
+
f_read = s.call_async(:stat, 'cmd_read') rescue nil
|
196
|
+
f_write = s.call_async(:stat, 'cmd_write') rescue nil
|
197
|
+
f_delete = s.call_async(:stat, 'cmd_delete') rescue nil
|
198
|
+
f_time = s.call_async(:stat, 'time') rescue nil
|
199
|
+
[f_uptime, f_read, f_write, f_delete, f_time]
|
200
|
+
}.each {|node,(f_uptime,f_read,f_write,f_delete,f_time)|
|
201
|
+
uptime = f_uptime.get rescue nil
|
202
|
+
read = f_read.get rescue nil
|
203
|
+
write = f_write.get rescue nil
|
204
|
+
delete = f_delete.get rescue nil
|
205
|
+
time = f_time.get rescue nil
|
206
|
+
time &&= Time.at(time).localtime
|
207
|
+
puts STAT_FORMAT % [node.nid, node.name, uptime, read, write, delete, time]
|
208
|
+
}
|
209
|
+
|
210
|
+
when 'items'
|
211
|
+
ITEMS_FORMAT = "%4s %15s %10s %10s"
|
212
|
+
puts ITEMS_FORMAT % %w[nid name rsid #items]
|
213
|
+
|
214
|
+
map = {}
|
215
|
+
each_node {|s,node|
|
216
|
+
f_items = s.call_async(:stat, 'db_items')
|
217
|
+
f_items
|
218
|
+
}.each {|node,f_items|
|
219
|
+
items = f_items.get rescue nil
|
220
|
+
rsids = node.rsids.sort.join(',')
|
221
|
+
puts ITEMS_FORMAT % [node.nid, node.name, rsids, items]
|
222
|
+
|
223
|
+
items ||= 0
|
224
|
+
node.rsids.each {|rsid|
|
225
|
+
if !map[rsid] || map[rsid] < items
|
226
|
+
map[rsid] = items
|
227
|
+
end
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
total = map.values.inject(0) {|r,n| r + n }
|
232
|
+
puts "total: #{total}"
|
233
|
+
|
234
|
+
when 'version'
|
235
|
+
VERSION_FORMAT = "%4s %15s %10s %10s"
|
236
|
+
puts VERSION_FORMAT % %w[nid name pid version]
|
237
|
+
|
238
|
+
each_node {|s,node|
|
239
|
+
f_pid = s.call_async(:stat, 'pid')
|
240
|
+
f_version = s.call_async(:stat, 'version')
|
241
|
+
[f_pid, f_version]
|
242
|
+
}.each {|node,(f_pid,f_version)|
|
243
|
+
pid = f_pid.get rescue nil
|
244
|
+
version = f_version.get rescue nil
|
245
|
+
puts VERSION_FORMAT % [node.nid, node.name, pid, version]
|
246
|
+
}
|
247
|
+
|
248
|
+
when 'locate'
|
249
|
+
key = cmd_args(1)
|
250
|
+
|
251
|
+
nodes = get_nodes
|
252
|
+
|
253
|
+
gwnode = nodes.first
|
254
|
+
vers = $net.get_session(*gwnode.address).call(:util_locate, key)
|
255
|
+
|
256
|
+
if vers.empty?
|
257
|
+
$stderr.puts "not found."
|
258
|
+
exit 0
|
259
|
+
end
|
260
|
+
|
261
|
+
NODE_FORMAT = " > %-15s nid=%-3s %23s %23s"
|
262
|
+
|
263
|
+
vers.each {|(key,vtime,rsid),vname|
|
264
|
+
time = Time.at(vtime)
|
265
|
+
puts "vtime=[#{time}] vname=#{vname.inspect}\trsid=#{rsid}:"
|
266
|
+
nodes.each {|node|
|
267
|
+
if node.rsids.include?(rsid)
|
268
|
+
puts NODE_FORMAT % [node.name, node.nid, node.address, node.location]
|
269
|
+
end
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
else
|
274
|
+
puts "unknown command #{cmd}"
|
275
|
+
puts ""
|
276
|
+
usage
|
277
|
+
end
|
278
|
+
|
@@ -0,0 +1,335 @@
|
|
1
|
+
#
|
2
|
+
# LS4
|
3
|
+
# Copyright (C) 2010-2011 FURUHASHI Sadayuki
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Affero General Public License as
|
7
|
+
# published by the Free Software Foundation, either version 3 of the
|
8
|
+
# License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Affero General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Affero General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
#
|
18
|
+
require 'msgpack/rpc'
|
19
|
+
require 'digest/md5'
|
20
|
+
require 'digest/sha1'
|
21
|
+
require 'csv'
|
22
|
+
require 'fileutils'
|
23
|
+
require 'cgi'
|
24
|
+
require 'ls4/lib/cclog'
|
25
|
+
require 'ls4/lib/ebus'
|
26
|
+
require 'ls4/lib/vbcode'
|
27
|
+
require 'ls4/logic/tsv_data'
|
28
|
+
require 'ls4/logic/weight'
|
29
|
+
require 'ls4/logic/fault_detector'
|
30
|
+
require 'ls4/logic/membership'
|
31
|
+
require 'ls4/logic/node'
|
32
|
+
require 'ls4/logic/okey'
|
33
|
+
require 'ls4/service/base'
|
34
|
+
require 'ls4/service/bus'
|
35
|
+
require 'ls4/service/process'
|
36
|
+
require 'ls4/service/rpc'
|
37
|
+
require 'ls4/service/rpc_gw'
|
38
|
+
require 'ls4/service/rpc_ds'
|
39
|
+
require 'ls4/service/stat'
|
40
|
+
require 'ls4/service/stat_gw'
|
41
|
+
require 'ls4/service/stat_ds'
|
42
|
+
require 'ls4/service/config'
|
43
|
+
require 'ls4/service/config_gw'
|
44
|
+
require 'ls4/service/config_ds'
|
45
|
+
require 'ls4/service/data_server'
|
46
|
+
require 'ls4/service/data_server_url'
|
47
|
+
require 'ls4/service/data_client'
|
48
|
+
require 'ls4/service/mds'
|
49
|
+
require 'ls4/service/mds_ha'
|
50
|
+
require 'ls4/service/mds_tt'
|
51
|
+
require 'ls4/service/mds_memcache'
|
52
|
+
require 'ls4/service/mds_cache'
|
53
|
+
require 'ls4/service/mds_cache_mem'
|
54
|
+
require 'ls4/service/mds_cache_memcached'
|
55
|
+
require 'ls4/service/gateway'
|
56
|
+
require 'ls4/service/gateway_ro'
|
57
|
+
require 'ls4/service/gw_http'
|
58
|
+
require 'ls4/service/sync'
|
59
|
+
require 'ls4/service/heartbeat'
|
60
|
+
require 'ls4/service/weight'
|
61
|
+
require 'ls4/service/balance'
|
62
|
+
require 'ls4/service/master_select'
|
63
|
+
require 'ls4/service/membership'
|
64
|
+
require 'ls4/service/rts'
|
65
|
+
require 'ls4/service/rts_file'
|
66
|
+
require 'ls4/service/rts_memory'
|
67
|
+
require 'ls4/service/slave'
|
68
|
+
require 'ls4/service/storage'
|
69
|
+
require 'ls4/service/storage_dir'
|
70
|
+
require 'ls4/service/ulog'
|
71
|
+
require 'ls4/service/ulog_file'
|
72
|
+
require 'ls4/service/ulog_memory'
|
73
|
+
require 'ls4/service/time_check'
|
74
|
+
require 'ls4/service/log'
|
75
|
+
require 'ls4/default'
|
76
|
+
require 'ls4/version'
|
77
|
+
require 'optparse'
|
78
|
+
|
79
|
+
include LS4
|
80
|
+
|
81
|
+
conf = DSConfigService.init
|
82
|
+
|
83
|
+
op = OptionParser.new
|
84
|
+
|
85
|
+
(class<<self;self;end).module_eval do
|
86
|
+
define_method(:usage) do |msg|
|
87
|
+
puts op.to_s
|
88
|
+
puts "error: #{msg}" if msg
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
listen_host = '0.0.0.0'
|
94
|
+
listen_port = nil
|
95
|
+
|
96
|
+
read_only_gw = false
|
97
|
+
|
98
|
+
op.on('-c', '--cs ADDRESS', "address of config server (required)") do |addr|
|
99
|
+
host, port = addr.split(':',2)
|
100
|
+
port = port.to_i
|
101
|
+
port = CS_DEFAULT_PORT if port == 0
|
102
|
+
conf.cs_address = Address.new(host, port)
|
103
|
+
end
|
104
|
+
|
105
|
+
op.on('-i', '--nid ID', Integer, "unieque node id (required)") do |nid|
|
106
|
+
conf.self_nid = nid
|
107
|
+
end
|
108
|
+
|
109
|
+
op.on('-n', '--name NAME', "human-readable node name (required)") do |name|
|
110
|
+
conf.self_name = name
|
111
|
+
end
|
112
|
+
|
113
|
+
op.on('-a', '--address ADDRESS[:PORT]', "address of this node (required)") do |addr|
|
114
|
+
host, port = addr.split(':',2)
|
115
|
+
port = port.to_i
|
116
|
+
if port != 0
|
117
|
+
listen_port = port
|
118
|
+
else
|
119
|
+
port = DS_DEFAULT_PORT
|
120
|
+
end
|
121
|
+
conf.self_address = Address.new(host, port)
|
122
|
+
end
|
123
|
+
|
124
|
+
op.on('-l', '--listen HOST[:PORT]', "listen address") do |addr|
|
125
|
+
if addr.include?(':')
|
126
|
+
host, port = addr.split(':',2)
|
127
|
+
port = port.to_i
|
128
|
+
if port != 0
|
129
|
+
listen_port = port
|
130
|
+
end
|
131
|
+
listen_host = host
|
132
|
+
else
|
133
|
+
listen_host = addr
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
op.on('-g', '--rsid IDs', "replica-set IDs to join (required)") do |ids|
|
138
|
+
conf.self_rsids = ids.split(',').map {|id| id.to_i }
|
139
|
+
end
|
140
|
+
|
141
|
+
op.on('-L', '--location STRING', "location of this node") do |str|
|
142
|
+
conf.self_location = str
|
143
|
+
end
|
144
|
+
|
145
|
+
op.on('-s', '--store PATH', "path to storage directory (required)") do |path|
|
146
|
+
conf.storage_path = path
|
147
|
+
end
|
148
|
+
|
149
|
+
op.on('-u', '--ulog PATH', "path to update log directory") do |path|
|
150
|
+
conf.ulog_path = path
|
151
|
+
end
|
152
|
+
|
153
|
+
op.on('-r', '--rts PATH', "path to relay timestamp directory") do |path|
|
154
|
+
conf.rts_path = path
|
155
|
+
end
|
156
|
+
|
157
|
+
op.on('-t', '--http PORT', "http listen port") do |addr|
|
158
|
+
if addr.include?(':')
|
159
|
+
host, port = addr.split(':',2)
|
160
|
+
port = port.to_i
|
161
|
+
else
|
162
|
+
host = '0.0.0.0'
|
163
|
+
port = addr.to_i
|
164
|
+
end
|
165
|
+
conf.http_gateway_address = Address.new(host, port)
|
166
|
+
end
|
167
|
+
|
168
|
+
op.on('--http-error-page PATH', 'path to eRuby template file') do |path|
|
169
|
+
conf.http_gateway_error_template_file = path
|
170
|
+
end
|
171
|
+
|
172
|
+
op.on('--http-redirect-port PORT', Integer) do |port|
|
173
|
+
conf.http_redirect_port = port
|
174
|
+
end
|
175
|
+
|
176
|
+
op.on('--http-redirect-path FORMAT') do |format|
|
177
|
+
conf.http_redirect_path_format = format
|
178
|
+
end
|
179
|
+
|
180
|
+
op.on('-R', '--read-only', "read-only mode", TrueClass) do |b|
|
181
|
+
read_only_gw = b
|
182
|
+
end
|
183
|
+
|
184
|
+
op.on('-N', '--read-only-name NAME', "read-only mode using the version name") do |name|
|
185
|
+
read_only_gw = true
|
186
|
+
conf.read_only_version = name
|
187
|
+
end
|
188
|
+
|
189
|
+
op.on('-T', '--read-only-time TIME', "read-only mode using the time", Integer) do |time|
|
190
|
+
read_only_gw = true
|
191
|
+
conf.read_only_version = time
|
192
|
+
end
|
193
|
+
|
194
|
+
op.on('--fault_store PATH', "path to fault status file") do |path|
|
195
|
+
conf.fault_path = path
|
196
|
+
end
|
197
|
+
|
198
|
+
op.on('--membership_store PATH', "path to membership status file") do |path|
|
199
|
+
conf.membership_path = path
|
200
|
+
end
|
201
|
+
|
202
|
+
op.on('-o', '--log PATH') do |path|
|
203
|
+
conf.log_path = path
|
204
|
+
end
|
205
|
+
|
206
|
+
op.on('-v', '--verbose', "show debug messages", TrueClass) do |b|
|
207
|
+
$log.level = 1 if b
|
208
|
+
end
|
209
|
+
|
210
|
+
op.on('--trace', "show debug and trace messages", TrueClass) do |b|
|
211
|
+
$log.level = 0 if b
|
212
|
+
end
|
213
|
+
|
214
|
+
op.on('--color-log', "force to enable color log", TrueClass) do |b|
|
215
|
+
$log.enable_color
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
begin
|
220
|
+
op.parse!(ARGV)
|
221
|
+
|
222
|
+
if ARGV.length != 0
|
223
|
+
raise "unknown option: #{ARGV[0].dump}"
|
224
|
+
end
|
225
|
+
|
226
|
+
unless conf.self_nid
|
227
|
+
raise "--nid option is required"
|
228
|
+
end
|
229
|
+
|
230
|
+
unless conf.self_name
|
231
|
+
raise "--name option is required"
|
232
|
+
end
|
233
|
+
|
234
|
+
unless conf.self_address
|
235
|
+
raise "--address option is required"
|
236
|
+
end
|
237
|
+
|
238
|
+
unless conf.self_rsids
|
239
|
+
raise "--rsid option is required"
|
240
|
+
end
|
241
|
+
|
242
|
+
unless conf.cs_address
|
243
|
+
raise "--cs option is required"
|
244
|
+
end
|
245
|
+
|
246
|
+
unless conf.storage_path
|
247
|
+
raise "--store option is required"
|
248
|
+
end
|
249
|
+
|
250
|
+
FileUtils.mkdir_p(conf.storage_path)
|
251
|
+
|
252
|
+
unless conf.ulog_path
|
253
|
+
conf.ulog_path = conf.storage_path
|
254
|
+
#raise "--ulog option is required"
|
255
|
+
end
|
256
|
+
|
257
|
+
unless conf.rts_path
|
258
|
+
conf.rts_path = conf.storage_path
|
259
|
+
#raise "--rts option is required"
|
260
|
+
end
|
261
|
+
|
262
|
+
unless conf.fault_path
|
263
|
+
conf.fault_path = File.join(conf.storage_path, "fault")
|
264
|
+
end
|
265
|
+
|
266
|
+
unless conf.membership_path
|
267
|
+
conf.membership_path = File.join(conf.storage_path, "membership")
|
268
|
+
end
|
269
|
+
|
270
|
+
unless conf.weight_path
|
271
|
+
conf.weight_path = File.join(conf.storage_path, "weight")
|
272
|
+
end
|
273
|
+
|
274
|
+
if conf.http_redirect_path_format && !conf.http_redirect_port
|
275
|
+
$log.warn "--http-redirect-port option is ignored"
|
276
|
+
end
|
277
|
+
|
278
|
+
listen_port ||= DS_DEFAULT_PORT
|
279
|
+
|
280
|
+
rescue
|
281
|
+
usage $!.to_s
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
ProcessService.init
|
286
|
+
LogService.open!
|
287
|
+
SyncClientService.init
|
288
|
+
HeartbeatMemberService.init
|
289
|
+
RoutRobinWeightBalanceService.init
|
290
|
+
WeightMemberService.init
|
291
|
+
if conf.self_location.empty?
|
292
|
+
FlatMasterSelectService.init
|
293
|
+
else
|
294
|
+
LocationAwareMasterSelectService.init
|
295
|
+
end
|
296
|
+
MembershipMemberService.init
|
297
|
+
DataClientService.init
|
298
|
+
if read_only_gw
|
299
|
+
ReadOnlyGatewayService.init
|
300
|
+
else
|
301
|
+
GatewayService.init
|
302
|
+
end
|
303
|
+
if conf.http_gateway_address
|
304
|
+
HTTPGatewayService.open!
|
305
|
+
end
|
306
|
+
StorageSelector.open!
|
307
|
+
UpdateLogSelector.open!
|
308
|
+
RelayTimeStampSelector.open!
|
309
|
+
SlaveService.init
|
310
|
+
DataServerService.init
|
311
|
+
DataServerURLService.init
|
312
|
+
DSStatService.init
|
313
|
+
MDSService.init
|
314
|
+
MDSCacheService.init
|
315
|
+
CachedMDSService.init
|
316
|
+
TimeCheckService.init
|
317
|
+
|
318
|
+
LogService.instance.log_event_bus
|
319
|
+
|
320
|
+
ProcessBus.run
|
321
|
+
|
322
|
+
TimeCheckService.instance.check_blocking! rescue nil
|
323
|
+
SyncClientService.instance.sync_blocking! rescue nil
|
324
|
+
MembershipMemberService.instance.register_self_blocking! rescue nil
|
325
|
+
#HeartbeatMemberService.instance.heartbeat_blocking! rescue nil
|
326
|
+
|
327
|
+
net = ProcessBus.serve_rpc(DSRPCService.instance)
|
328
|
+
net.listen(listen_host, listen_port)
|
329
|
+
|
330
|
+
$log.info "start on #{listen_host}:#{listen_port}"
|
331
|
+
|
332
|
+
net.run
|
333
|
+
|
334
|
+
ProcessBus.shutdown
|
335
|
+
|