ls4 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/AUTHORS +1 -0
  2. data/COPYING +661 -0
  3. data/ChangeLog +9 -0
  4. data/NOTICE +8 -0
  5. data/README.rdoc +61 -0
  6. data/bin/ls4-cs +3 -0
  7. data/bin/ls4-ds +3 -0
  8. data/bin/ls4-gw +3 -0
  9. data/bin/ls4-standalone +3 -0
  10. data/bin/ls4cmd +3 -0
  11. data/bin/ls4ctl +3 -0
  12. data/bin/ls4rpc +3 -0
  13. data/bin/ls4stat +3 -0
  14. data/bin/ls4top +3 -0
  15. data/lib/ls4/command/cmd.rb +241 -0
  16. data/lib/ls4/command/cs.rb +190 -0
  17. data/lib/ls4/command/ctl.rb +278 -0
  18. data/lib/ls4/command/ds.rb +335 -0
  19. data/lib/ls4/command/gw.rb +256 -0
  20. data/lib/ls4/command/rpc.rb +172 -0
  21. data/lib/ls4/command/standalone.rb +318 -0
  22. data/lib/ls4/command/stat.rb +244 -0
  23. data/lib/ls4/command/top.rb +291 -0
  24. data/lib/ls4/default.rb +26 -0
  25. data/lib/ls4/lib/cclog.rb +220 -0
  26. data/lib/ls4/lib/ebus.rb +553 -0
  27. data/lib/ls4/lib/vbcode.rb +228 -0
  28. data/lib/ls4/logic/fault_detector.rb +212 -0
  29. data/lib/ls4/logic/membership.rb +253 -0
  30. data/lib/ls4/logic/node.rb +66 -0
  31. data/lib/ls4/logic/okey.rb +45 -0
  32. data/lib/ls4/logic/tsv_data.rb +81 -0
  33. data/lib/ls4/logic/weight.rb +166 -0
  34. data/lib/ls4/service/balance.rb +62 -0
  35. data/lib/ls4/service/base.rb +29 -0
  36. data/lib/ls4/service/bus.rb +37 -0
  37. data/lib/ls4/service/config.rb +63 -0
  38. data/lib/ls4/service/config_cs.rb +33 -0
  39. data/lib/ls4/service/config_ds.rb +56 -0
  40. data/lib/ls4/service/config_gw.rb +42 -0
  41. data/lib/ls4/service/data_client.rb +122 -0
  42. data/lib/ls4/service/data_server.rb +168 -0
  43. data/lib/ls4/service/data_server_url.rb +83 -0
  44. data/lib/ls4/service/gateway.rb +375 -0
  45. data/lib/ls4/service/gateway_ro.rb +91 -0
  46. data/lib/ls4/service/gw_http.rb +821 -0
  47. data/lib/ls4/service/heartbeat.rb +182 -0
  48. data/lib/ls4/service/log.rb +81 -0
  49. data/lib/ls4/service/master_select.rb +148 -0
  50. data/lib/ls4/service/mds.rb +292 -0
  51. data/lib/ls4/service/mds_cache.rb +294 -0
  52. data/lib/ls4/service/mds_cache_mem.rb +63 -0
  53. data/lib/ls4/service/mds_cache_memcached.rb +65 -0
  54. data/lib/ls4/service/mds_ha.rb +176 -0
  55. data/lib/ls4/service/mds_memcache.rb +209 -0
  56. data/lib/ls4/service/mds_tc.rb +508 -0
  57. data/lib/ls4/service/mds_tt.rb +472 -0
  58. data/lib/ls4/service/membership.rb +331 -0
  59. data/lib/ls4/service/process.rb +90 -0
  60. data/lib/ls4/service/rpc.rb +50 -0
  61. data/lib/ls4/service/rpc_cs.rb +101 -0
  62. data/lib/ls4/service/rpc_ds.rb +96 -0
  63. data/lib/ls4/service/rpc_gw.rb +255 -0
  64. data/lib/ls4/service/rts.rb +94 -0
  65. data/lib/ls4/service/rts_file.rb +76 -0
  66. data/lib/ls4/service/rts_memory.rb +55 -0
  67. data/lib/ls4/service/slave.rb +132 -0
  68. data/lib/ls4/service/stat.rb +91 -0
  69. data/lib/ls4/service/stat_cs.rb +25 -0
  70. data/lib/ls4/service/stat_ds.rb +40 -0
  71. data/lib/ls4/service/stat_gw.rb +25 -0
  72. data/lib/ls4/service/storage.rb +116 -0
  73. data/lib/ls4/service/storage_dir.rb +201 -0
  74. data/lib/ls4/service/sync.rb +206 -0
  75. data/lib/ls4/service/time_check.rb +80 -0
  76. data/lib/ls4/service/ulog.rb +159 -0
  77. data/lib/ls4/service/ulog_file.rb +398 -0
  78. data/lib/ls4/service/ulog_memory.rb +53 -0
  79. data/lib/ls4/service/weight.rb +134 -0
  80. data/lib/ls4/version.rb +5 -0
  81. data/test/01_add_get_remove.rt +84 -0
  82. data/test/02_read.rt +61 -0
  83. data/test/03_getd_readd.rt +69 -0
  84. data/test/04_version_time.rt +170 -0
  85. data/test/05_version_name.rt +161 -0
  86. data/test/06_http_get_set_remove_1.rt +119 -0
  87. data/test/07_http_get_set_remove_2.rt +116 -0
  88. data/test/08_read_only_time.rt +177 -0
  89. data/test/09_read_only_name.rt +173 -0
  90. data/test/10_http_get_set_remove_3.rt +73 -0
  91. data/test/11_mds_cache_memcached.rt +88 -0
  92. data/test/12_mds_cache_local_memory.rt +86 -0
  93. data/test/13_memcache_mds.rt +84 -0
  94. data/test/14_delete.rt +63 -0
  95. data/test/15_standalone.rt +71 -0
  96. data/test/chukan.rb +516 -0
  97. data/test/common.rb +250 -0
  98. data/test/load_test.rb +79 -0
  99. data/test/load_test_offload.rb +86 -0
  100. metadata +295 -0
@@ -0,0 +1,256 @@
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/stat'
39
+ require 'ls4/service/stat_gw'
40
+ require 'ls4/service/config'
41
+ require 'ls4/service/config_gw'
42
+ require 'ls4/service/data_client'
43
+ require 'ls4/service/mds'
44
+ require 'ls4/service/mds_ha'
45
+ require 'ls4/service/mds_tt'
46
+ require 'ls4/service/mds_memcache'
47
+ require 'ls4/service/mds_cache'
48
+ require 'ls4/service/mds_cache_mem'
49
+ require 'ls4/service/mds_cache_memcached'
50
+ require 'ls4/service/gateway'
51
+ require 'ls4/service/gateway_ro'
52
+ require 'ls4/service/gw_http'
53
+ require 'ls4/service/sync'
54
+ require 'ls4/service/heartbeat'
55
+ require 'ls4/service/weight'
56
+ require 'ls4/service/balance'
57
+ require 'ls4/service/master_select'
58
+ require 'ls4/service/membership'
59
+ require 'ls4/service/time_check'
60
+ require 'ls4/service/log'
61
+ require 'ls4/default'
62
+ require 'ls4/version'
63
+ require 'optparse'
64
+
65
+ include LS4
66
+
67
+ conf = GWConfigService.init
68
+
69
+ op = OptionParser.new
70
+
71
+ (class<<self;self;end).module_eval do
72
+ define_method(:usage) do |msg|
73
+ puts op.to_s
74
+ puts "error: #{msg}" if msg
75
+ exit 1
76
+ end
77
+ end
78
+
79
+ store_path = nil
80
+
81
+ listen_host = '0.0.0.0'
82
+ listen_port = GW_DEFAULT_PORT
83
+
84
+ read_only_gw = false
85
+
86
+ op.on('-c', '--cs ADDRESS', "address of config server (required)") do |addr|
87
+ host, port = addr.split(':',2)
88
+ port = port.to_i
89
+ port = CS_DEFAULT_PORT if port == 0
90
+ conf.cs_address = Address.new(host, port)
91
+ end
92
+
93
+ op.on('-p', '--port PORT', "listen port") do |addr|
94
+ if addr.include?(':')
95
+ listen_host, listen_port = addr.split(':',2)
96
+ listen_port = listen_port.to_i
97
+ listen_port = GW_DEFAULT_PORT if listen_port == 0
98
+ else
99
+ listen_port = addr.to_i
100
+ end
101
+ end
102
+
103
+ op.on('-l', '--listen HOST', "listen address") do |addr|
104
+ if addr.include?(':')
105
+ host, port = addr.split(':',2)
106
+ port = port.to_i
107
+ port = GW_DEFAULT_PORT if port == 0
108
+ listen_host = host
109
+ listen_port = port
110
+ else
111
+ listen_host = addr
112
+ end
113
+ end
114
+
115
+ op.on('-t', '--http PORT', "http listen port") do |addr|
116
+ if addr.include?(':')
117
+ host, port = addr.split(':',2)
118
+ port = port.to_i
119
+ else
120
+ host = '0.0.0.0'
121
+ port = addr.to_i
122
+ end
123
+ conf.http_gateway_address = Address.new(host, port)
124
+ end
125
+
126
+ op.on('--http-error-page PATH', 'path to eRuby template file') do |path|
127
+ conf.http_gateway_error_template_file = path
128
+ end
129
+
130
+ op.on('-R', '--read-only', "read-only mode", TrueClass) do |b|
131
+ read_only_gw = b
132
+ end
133
+
134
+ op.on('-T', '--read-only-time TIME', "read-only mode using the time", Integer) do |time|
135
+ read_only_gw = true
136
+ conf.read_only_version = time
137
+ end
138
+
139
+ op.on('-N', '--read-only-name NAME', "read-only mode using the version name") do |name|
140
+ read_only_gw = true
141
+ conf.read_only_version = name
142
+ end
143
+
144
+ op.on('-L', '--location STRING', "enable location-aware master selection") do |str|
145
+ conf.self_location = str
146
+ end
147
+
148
+ op.on('-s', '--store PATH', "path to base directory") do |path|
149
+ store_path = path
150
+ end
151
+
152
+ op.on('--fault_store PATH', "path to fault status file") do |path|
153
+ conf.fault_path = path
154
+ end
155
+
156
+ op.on('--membership_store PATH', "path to membership status file") do |path|
157
+ conf.membership_path = path
158
+ end
159
+
160
+ op.on('--weight_store PATH', "path to weight status file") do |path|
161
+ conf.weight_path = path
162
+ end
163
+
164
+ op.on('-o', '--log PATH') do |path|
165
+ conf.log_path = path
166
+ end
167
+
168
+ op.on('-v', '--verbose', "show debug messages", TrueClass) do |b|
169
+ $log.level = 1 if b
170
+ end
171
+
172
+ op.on('--trace', "show debug and trace messages", TrueClass) do |b|
173
+ $log.level = 0 if b
174
+ end
175
+
176
+ op.on('--color-log', "force to enable color log", TrueClass) do |b|
177
+ $log.enable_color
178
+ end
179
+
180
+
181
+ begin
182
+ op.parse!(ARGV)
183
+
184
+ if ARGV.length != 0
185
+ raise "unknown option: #{ARGV[0].dump}"
186
+ end
187
+
188
+ unless conf.cs_address
189
+ raise "--cs option is required"
190
+ end
191
+
192
+ if store_path
193
+ FileUtils.mkdir_p(store_path)
194
+ end
195
+
196
+ if !conf.fault_path && store_path
197
+ conf.fault_path = File.join(store_path, "fault")
198
+ end
199
+
200
+ if !conf.membership_path && store_path
201
+ conf.membership_path = File.join(store_path, "membership")
202
+ end
203
+
204
+ if !conf.weight_path && store_path
205
+ conf.weight_path = File.join(store_path, "weight")
206
+ end
207
+
208
+ rescue
209
+ usage $!.to_s
210
+ end
211
+
212
+
213
+ ProcessService.init
214
+ LogService.open!
215
+ SyncClientService.init
216
+ HeartbeatClientService.init
217
+ RoutRobinWeightBalanceService.init
218
+ WeightMemberService.init
219
+ if conf.self_location.empty?
220
+ FlatMasterSelectService.init
221
+ else
222
+ LocationAwareMasterSelectService.init
223
+ end
224
+ MembershipClientService.init
225
+ DataClientService.init
226
+ if read_only_gw
227
+ ReadOnlyGatewayService.init
228
+ else
229
+ GatewayService.init
230
+ end
231
+ if conf.http_gateway_address
232
+ HTTPGatewayService.open!
233
+ end
234
+ GWStatService.init
235
+ MDSService.init
236
+ MDSCacheService.init
237
+ CachedMDSService.init
238
+ TimeCheckService.init
239
+
240
+ LogService.instance.log_event_bus
241
+
242
+ ProcessBus.run
243
+
244
+ TimeCheckService.instance.check_blocking! rescue nil
245
+ SyncClientService.instance.sync_blocking! rescue nil
246
+ #HeartbeatClientService.instance.heartbeat_blocking! rescue nil
247
+
248
+ net = ProcessBus.serve_rpc(GWRPCService.instance)
249
+ net.listen(listen_host, listen_port)
250
+
251
+ $log.info "start on #{listen_host}:#{listen_port}"
252
+
253
+ net.run
254
+
255
+ ProcessBus.shutdown
256
+
@@ -0,0 +1,172 @@
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
+ #!/usr/bin/env ruby
19
+
20
+ begin
21
+ require 'rubygems'
22
+ rescue LoadError
23
+ end
24
+ require 'msgpack'
25
+ require 'msgpack/rpc'
26
+ require 'irb'
27
+
28
+ def call(method, *args)
29
+ cli = MessagePack::RPC::Client.new(Host, Port)
30
+ begin
31
+ cli.timeout = 5
32
+ cli.call(method, *args)
33
+ ensure
34
+ cli.close
35
+ end
36
+ end
37
+
38
+ module LS4RPC
39
+ CS_METHODS = []
40
+ DS_METHODS = []
41
+ GW_METHODS = []
42
+
43
+ def self.rpc(name, args)
44
+ self.module_eval <<-RUBY
45
+ def #{name}(#{args.join(',')})
46
+ call(:#{([name]+args).join(',')})
47
+ end
48
+ RUBY
49
+ end
50
+
51
+ def self.cs_rpc(name, *args)
52
+ CS_METHODS << [name, args]
53
+ rpc(name, args)
54
+ end
55
+
56
+ def self.ds_rpc(name, *args)
57
+ DS_METHODS << [name, args]
58
+ rpc(name, args)
59
+ end
60
+
61
+ def self.gw_rpc(name, *args)
62
+ GW_METHODS << [name, args]
63
+ rpc(name, args)
64
+ end
65
+
66
+ def show
67
+ puts "Gateway methods:"
68
+ GW_METHODS.each {|name,args|
69
+ puts " #{name}(#{args.join(', ')})"
70
+ }
71
+ puts ""
72
+ puts "Config Server methods:"
73
+ CS_METHODS.each {|name,args|
74
+ puts " #{name}(#{args.join(', ')})"
75
+ }
76
+ puts ""
77
+ puts "Data Server methods:"
78
+ (DS_METHODS+GW_METHODS).each {|name,args|
79
+ puts " #{name}(#{args.join(', ')})"
80
+ }
81
+ nil
82
+ end
83
+
84
+ gw_rpc :get, :key
85
+ gw_rpc :get_data, :key
86
+ gw_rpc :get_attrs, :key
87
+ gw_rpc :read, :key, :offset, :size
88
+ gw_rpc :gett, :vtime, :key
89
+ gw_rpc :gett_data, :vtime, :key
90
+ gw_rpc :gett_attrs, :vtime, :key
91
+ gw_rpc :readt, :vtime, :key, :offset, :size
92
+ gw_rpc :getv, :vname, :key
93
+ gw_rpc :getv_data, :vname, :key
94
+ gw_rpc :getv_attrs, :vname, :key
95
+ gw_rpc :readv, :vname, :key, :offset, :size
96
+ gw_rpc :getd_data, :okey
97
+ gw_rpc :readd, :okey, :offset, :size
98
+ gw_rpc :add, :key, :data, :attrs
99
+ gw_rpc :add_data, :key, :data
100
+ gw_rpc :addv, :vname, :key, :data, :attrs
101
+ gw_rpc :addv_data, :vname, :key, :data
102
+ gw_rpc :update_attrs, :key, :attrs
103
+ gw_rpc :remove, :key
104
+ gw_rpc :delete, :key
105
+ gw_rpc :deletet, :vtime, :key
106
+ gw_rpc :deletev, :vname, :key
107
+ gw_rpc :url, :key
108
+ gw_rpc :urlt, :vtime, :key
109
+ gw_rpc :urlv, :vname, :key
110
+ gw_rpc :util_locate, :key
111
+ gw_rpc :stat, :cmd
112
+
113
+ cs_rpc :heartbeat, :nid, :sync_hash
114
+ cs_rpc :sync_config, :hash_array
115
+ cs_rpc :add_node, :nid, :address, :name, :rsids, :self_location
116
+ cs_rpc :remove_node, :nid
117
+ cs_rpc :update_node_info, :nid, :address, :name, :rsids
118
+ cs_rpc :recover_node, :nid
119
+ cs_rpc :set_replset_weight, :rsid, :weight
120
+ cs_rpc :reset_replset_weight, :rsid
121
+ cs_rpc :get_mds_uri
122
+ cs_rpc :set_mds_uri, :uri
123
+ cs_rpc :get_mds_cache_uri
124
+ cs_rpc :set_mds_cache_uri, :uri
125
+ cs_rpc :stat, :cmd
126
+
127
+ ds_rpc :get_direct, :okey
128
+ ds_rpc :set_direct, :okey, :data
129
+ ds_rpc :delete_direct, :okey
130
+ ds_rpc :read_direct, :okey, :offset, :size
131
+ ds_rpc :url_direct, :okey
132
+ ds_rpc :resize_direct, :okey, :size
133
+ ds_rpc :replicate_pull, :pos, :limit
134
+ ds_rpc :replicate_notify, :nid
135
+ end
136
+
137
+ def usage_exit
138
+ puts "Usage: #{File.basename($0)} <host>:<port> [method [args ...]]"
139
+ exit 1
140
+ end
141
+
142
+ if ARGV.length < 1
143
+ usage_exit
144
+ end
145
+
146
+ host, port = ARGV.shift.split(':')
147
+ port = port.to_i
148
+ if port == 0
149
+ usage_exit
150
+ end
151
+
152
+ Host = host
153
+ Port = port
154
+
155
+ include LS4RPC
156
+
157
+ if ARGV.empty?
158
+ puts "Type 'show' to show all supported RPC methods."
159
+ IRB.start
160
+
161
+ else
162
+ require 'pp'
163
+ require 'yaml'
164
+ #require 'json' # TODO
165
+ method = ARGV.shift
166
+ args = ARGV.map {|arg|
167
+ YAML.load(arg)
168
+ }
169
+ puts LS4RPC.method(method).call(*args).to_json
170
+
171
+ end
172
+
@@ -0,0 +1,318 @@
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/rpc_cs'
40
+ require 'ls4/service/stat'
41
+ require 'ls4/service/stat_gw'
42
+ require 'ls4/service/stat_ds'
43
+ require 'ls4/service/config'
44
+ require 'ls4/service/config_gw'
45
+ require 'ls4/service/config_ds'
46
+ require 'ls4/service/config_cs'
47
+ require 'ls4/service/data_server'
48
+ require 'ls4/service/data_server_url'
49
+ require 'ls4/service/data_client'
50
+ require 'ls4/service/mds'
51
+ require 'ls4/service/mds_ha'
52
+ require 'ls4/service/mds_tt'
53
+ require 'ls4/service/mds_tc'
54
+ require 'ls4/service/mds_memcache'
55
+ require 'ls4/service/mds_cache'
56
+ require 'ls4/service/mds_cache_mem'
57
+ require 'ls4/service/mds_cache_memcached'
58
+ require 'ls4/service/gateway'
59
+ require 'ls4/service/gateway_ro'
60
+ require 'ls4/service/gw_http'
61
+ require 'ls4/service/sync'
62
+ require 'ls4/service/heartbeat'
63
+ require 'ls4/service/weight'
64
+ require 'ls4/service/balance'
65
+ require 'ls4/service/master_select'
66
+ require 'ls4/service/membership'
67
+ require 'ls4/service/rts'
68
+ require 'ls4/service/rts_file'
69
+ require 'ls4/service/rts_memory'
70
+ require 'ls4/service/slave'
71
+ require 'ls4/service/storage'
72
+ require 'ls4/service/storage_dir'
73
+ require 'ls4/service/ulog'
74
+ require 'ls4/service/ulog_file'
75
+ require 'ls4/service/ulog_memory'
76
+ require 'ls4/service/time_check'
77
+ require 'ls4/service/log'
78
+ require 'ls4/default'
79
+ require 'ls4/version'
80
+ require 'optparse'
81
+
82
+ include LS4
83
+
84
+ conf = DSConfigService.init
85
+ mds_uri = nil
86
+ mds_cache_uri = ""
87
+
88
+ op = OptionParser.new
89
+
90
+ (class<<self;self;end).module_eval do
91
+ define_method(:usage) do |msg|
92
+ puts op.to_s
93
+ puts "error: #{msg}" if msg
94
+ exit 1
95
+ end
96
+ end
97
+
98
+ listen_host = '0.0.0.0'
99
+ listen_port = DS_DEFAULT_PORT
100
+
101
+ read_only_gw = false
102
+
103
+ op.on('-p', '--port PORT', "listen port") do |addr|
104
+ if addr.include?(':')
105
+ listen_host, listen_port = addr.split(':',2)
106
+ listen_port = listen_port.to_i
107
+ listen_port = DS_DEFAULT_PORT if listen_port == 0
108
+ else
109
+ listen_port = addr.to_i
110
+ end
111
+ end
112
+
113
+ op.on('-l', '--listen HOST', "listen address") do |addr|
114
+ if addr.include?(':')
115
+ host, port = addr.split(':',2)
116
+ port = port.to_i
117
+ port = DS_DEFAULT_PORT if port == 0
118
+ listen_host = host
119
+ listen_port = port
120
+ else
121
+ listen_host = addr
122
+ end
123
+ end
124
+
125
+ op.on('-m', '--mds EXPR', "address of metadata servers") do |s|
126
+ mds_uri = s
127
+ end
128
+
129
+ op.on('-M', '--mds-cache EXPR', "address of metadata cache servers") do |s|
130
+ mds_cache_uri = s
131
+ end
132
+
133
+ op.on('-s', '--store PATH', "path to storage directory (required)") do |path|
134
+ conf.storage_path = path
135
+ end
136
+
137
+ op.on('-u', '--ulog PATH', "path to update log directory") do |path|
138
+ conf.ulog_path = path
139
+ end
140
+
141
+ op.on('-r', '--rts PATH', "path to relay timestamp directory") do |path|
142
+ conf.rts_path = path
143
+ end
144
+
145
+ op.on('-t', '--http PORT', "http listen port") do |addr|
146
+ if addr.include?(':')
147
+ host, port = addr.split(':',2)
148
+ port = port.to_i
149
+ else
150
+ host = '0.0.0.0'
151
+ port = addr.to_i
152
+ end
153
+ conf.http_gateway_address = Address.new(host, port)
154
+ end
155
+
156
+ op.on('--http-error-page PATH', 'path to eRuby template file') do |path|
157
+ conf.http_gateway_error_template_file = path
158
+ end
159
+
160
+ op.on('--http-redirect-port PORT', Integer) do |port|
161
+ conf.http_redirect_port = port
162
+ end
163
+
164
+ op.on('--http-redirect-path FORMAT') do |format|
165
+ conf.http_redirect_path_format = format
166
+ end
167
+
168
+ op.on('-R', '--read-only', "read-only mode", TrueClass) do |b|
169
+ read_only_gw = b
170
+ end
171
+
172
+ op.on('-N', '--read-only-name NAME', "read-only mode using the version name") do |name|
173
+ read_only_gw = true
174
+ conf.read_only_version = name
175
+ end
176
+
177
+ op.on('-T', '--read-only-time TIME', "read-only mode using the time", Integer) do |time|
178
+ read_only_gw = true
179
+ conf.read_only_version = time
180
+ end
181
+
182
+ op.on('--fault_store PATH', "path to fault status file") do |path|
183
+ conf.fault_path = path
184
+ end
185
+
186
+ op.on('--membership_store PATH', "path to membership status file") do |path|
187
+ conf.membership_path = path
188
+ end
189
+
190
+ op.on('-o', '--log PATH') do |path|
191
+ conf.log_path = path
192
+ end
193
+
194
+ op.on('-v', '--verbose', "show debug messages", TrueClass) do |b|
195
+ $log.level = 1 if b
196
+ end
197
+
198
+ op.on('--trace', "show debug and trace messages", TrueClass) do |b|
199
+ $log.level = 0 if b
200
+ end
201
+
202
+ op.on('--color-log', "force to enable color log", TrueClass) do |b|
203
+ $log.enable_color
204
+ end
205
+
206
+
207
+ begin
208
+ op.parse!(ARGV)
209
+
210
+ if ARGV.length != 0
211
+ raise "unknown option: #{ARGV[0].dump}"
212
+ end
213
+
214
+ conf.self_address = Address.new('127.0.0.1', listen_port)
215
+ conf.cs_address = conf.self_address
216
+
217
+ conf.self_nid = 1
218
+ conf.self_name = "standalone"
219
+ conf.self_rsids = [1]
220
+
221
+ a = conf.self_address.host
222
+ if a.include?('.')
223
+ s = a.split('.')[0,3].map{|v4| "%03d" % v4.to_i }.join('.')
224
+ else
225
+ s = a.split(':')[0,4].map{|v6| "%04x" % v6.to_i(16) }.join(':')
226
+ end
227
+ conf.self_location = "subnet-#{s}"
228
+
229
+ unless conf.storage_path
230
+ raise "--store option is required"
231
+ end
232
+
233
+ unless mds_uri
234
+ mds_uri = "local:#{conf.storage_path}/mds.tct"
235
+ end
236
+
237
+ FileUtils.mkdir_p(conf.storage_path)
238
+
239
+ unless conf.ulog_path
240
+ conf.ulog_path = conf.storage_path
241
+ #raise "--ulog option is required"
242
+ end
243
+
244
+ unless conf.rts_path
245
+ conf.rts_path = conf.storage_path
246
+ #raise "--rts option is required"
247
+ end
248
+
249
+ unless conf.fault_path
250
+ conf.fault_path = File.join(conf.storage_path, "fault")
251
+ end
252
+
253
+ unless conf.membership_path
254
+ conf.membership_path = File.join(conf.storage_path, "membership")
255
+ end
256
+
257
+ unless conf.weight_path
258
+ conf.weight_path = File.join(conf.storage_path, "weight")
259
+ end
260
+
261
+ if conf.http_redirect_path_format && !conf.http_redirect_port
262
+ $log.warn "--http-redirect-port option is ignored"
263
+ end
264
+
265
+ rescue
266
+ usage $!.to_s
267
+ end
268
+
269
+
270
+ ProcessService.init
271
+ LogService.open!
272
+ StandaloneSyncService.init
273
+ RoutRobinWeightBalanceService.init
274
+ WeightMemberService.init
275
+ if conf.self_location.empty?
276
+ FlatMasterSelectService.init
277
+ else
278
+ LocationAwareMasterSelectService.init
279
+ end
280
+ StandaloneMembershipService.init
281
+ DataClientService.init
282
+ if read_only_gw
283
+ ReadOnlyGatewayService.init
284
+ else
285
+ GatewayService.init
286
+ end
287
+ if conf.http_gateway_address
288
+ HTTPGatewayService.open!
289
+ end
290
+ StorageSelector.open!
291
+ UpdateLogSelector.open!
292
+ RelayTimeStampSelector.open!
293
+ SlaveService.init
294
+ DataServerService.init
295
+ DataServerURLService.init
296
+ DSStatService.init
297
+ MDSService.init
298
+ MDSCacheService.init
299
+ CachedMDSService.init
300
+ TimeCheckService.init
301
+
302
+ LogService.instance.log_event_bus
303
+
304
+ ProcessBus.run
305
+
306
+ StandaloneMembershipService.instance.rpc_add_node(conf.self_nid, conf.self_address, conf.self_name, conf.self_rsids, conf.self_location)
307
+ MDSService.instance.reopen(mds_uri)
308
+ MDSCacheService.instance.reopen(mds_cache_uri) if mds_cache_uri
309
+
310
+ net = ProcessBus.serve_rpc(DSRPCService.instance)
311
+ net.listen(listen_host, listen_port)
312
+
313
+ $log.info "start on #{listen_host}:#{listen_port}"
314
+
315
+ net.run
316
+
317
+ ProcessBus.shutdown
318
+