roma 0.8.2 → 0.8.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANG +326 -0
- data/CHANGELOG +132 -0
- data/{README.rdoc → FETCH_HEAD} +0 -0
- data/{LICENSE.rdoc → LICENSE} +0 -1
- data/README +17 -0
- data/Rakefile +33 -18
- data/ruby/server/bin/chg_redundancy +10 -0
- data/ruby/server/bin/key_access +7 -0
- data/ruby/server/bin/key_list +7 -0
- data/ruby/server/bin/mkconfig +19 -0
- data/{bin → ruby/server/bin}/mkrecent +0 -1
- data/{bin → ruby/server/bin}/mkroute +0 -1
- data/ruby/server/bin/multi_commander +19 -0
- data/ruby/server/bin/recoverlost +10 -0
- data/ruby/server/bin/recoverlost_alist +10 -0
- data/ruby/server/bin/recoverlost_alist_all +10 -0
- data/ruby/server/bin/recoverlost_alist_keys +10 -0
- data/{bin/recoverlost → ruby/server/bin/roma_watcher} +1 -2
- data/ruby/server/bin/romad +36 -0
- data/{bin → ruby/server/bin}/sample_watcher +0 -1
- data/{bin → ruby/server/bin}/sample_watcher2 +0 -1
- data/{bin/simple_bench → ruby/server/bin/sample_watcher3} +1 -2
- data/ruby/server/bin/simple_bench +26 -0
- data/{bin → ruby/server/bin}/ssroute +0 -1
- data/ruby/server/bin/test-scenario +11 -0
- data/{bin → ruby/server/bin}/tribunus +0 -1
- data/{lib → ruby/server/lib}/roma/async_process.rb +67 -15
- data/{lib → ruby/server/lib}/roma/command/bg_command_receiver.rb +1 -1
- data/ruby/server/lib/roma/command/command_definition.rb +422 -0
- data/ruby/server/lib/roma/command/mh_command_receiver.rb +127 -0
- data/ruby/server/lib/roma/command/receiver.rb +64 -0
- data/{lib → ruby/server/lib}/roma/command/rt_command_receiver.rb +6 -1
- data/ruby/server/lib/roma/command/sys_command_receiver.rb +609 -0
- data/{lib → ruby/server/lib}/roma/command/util_command_receiver.rb +15 -5
- data/{lib → ruby/server/lib}/roma/command/vn_command_receiver.rb +12 -4
- data/{lib → ruby/server/lib}/roma/command_plugin.rb +0 -0
- data/ruby/server/lib/roma/config.rb +84 -0
- data/{lib → ruby/server/lib}/roma/event/con_pool.rb +12 -1
- data/ruby/server/lib/roma/event/handler.rb +256 -0
- data/ruby/server/lib/roma/live_patch-20120302-001.rb +107 -0
- data/ruby/server/lib/roma/logging/rlogger.rb +163 -0
- data/ruby/server/lib/roma/messaging/con_pool.rb +92 -0
- data/{lib → ruby/server/lib}/roma/plugin/plugin_alist.rb +118 -240
- data/ruby/server/lib/roma/plugin/plugin_debug.rb +31 -0
- data/ruby/server/lib/roma/plugin/plugin_map.rb +177 -0
- data/ruby/server/lib/roma/plugin/plugin_mapcount.rb +185 -0
- data/{lib/roma/command/st_command_receiver.rb → ruby/server/lib/roma/plugin/plugin_storage.rb} +170 -146
- data/ruby/server/lib/roma/plugin/plugin_stub.rb +283 -0
- data/{lib → ruby/server/lib}/roma/plugin/plugin_test.rb +0 -0
- data/{lib → ruby/server/lib}/roma/romad.rb +221 -94
- data/{lib → ruby/server/lib}/roma/routing/cb_rttable.rb +4 -6
- data/{lib → ruby/server/lib}/roma/routing/merkle_tree.rb +0 -0
- data/ruby/server/lib/roma/routing/routing_data.rb +307 -0
- data/{lib → ruby/server/lib}/roma/routing/rttable.rb +4 -0
- data/{lib → ruby/server/lib}/roma/stats.rb +19 -3
- data/{lib → ruby/server/lib}/roma/storage/basic_storage.rb +25 -26
- data/{lib → ruby/server/lib}/roma/storage/dbm_storage.rb +1 -23
- data/{lib → ruby/server/lib}/roma/storage/dummy_storage.rb +0 -0
- data/{lib → ruby/server/lib}/roma/storage/rh_storage.rb +0 -0
- data/{lib → ruby/server/lib}/roma/storage/sqlite3_storage.rb +0 -0
- data/{lib → ruby/server/lib}/roma/storage/tc_storage.rb +62 -2
- data/ruby/server/lib/roma/tools/chg_redundancy.rb +36 -0
- data/ruby/server/lib/roma/tools/key_access.rb +105 -0
- data/ruby/server/lib/roma/tools/key_list.rb +94 -0
- data/ruby/server/lib/roma/tools/mkconfig.rb +535 -0
- data/{lib → ruby/server/lib}/roma/tools/mkrecent.rb +0 -0
- data/{lib → ruby/server/lib}/roma/tools/mkroute.rb +0 -0
- data/ruby/server/lib/roma/tools/multi_commander.rb +45 -0
- data/{lib → ruby/server/lib}/roma/tools/recoverlost.rb +0 -0
- data/{lib → ruby/server/lib}/roma/tools/recoverlost_alist.rb +0 -0
- data/ruby/server/lib/roma/tools/recoverlost_alist_all.rb +8 -0
- data/ruby/server/lib/roma/tools/recoverlost_alist_keys.rb +16 -0
- data/ruby/server/lib/roma/tools/recoverlost_lib.rb +349 -0
- data/ruby/server/lib/roma/tools/roma_watcher.rb +150 -0
- data/ruby/server/lib/roma/tools/roma_watcher_config.yml.example +20 -0
- data/{lib → ruby/server/lib}/roma/tools/sample_watcher.rb +3 -1
- data/{lib → ruby/server/lib}/roma/tools/sample_watcher2.rb +3 -1
- data/ruby/server/lib/roma/tools/sample_watcher3.rb +49 -0
- data/{lib → ruby/server/lib}/roma/tools/simple_bench.rb +2 -0
- data/ruby/server/lib/roma/tools/simple_bench2.rb +78 -0
- data/{lib → ruby/server/lib}/roma/tools/ssroute.rb +0 -0
- data/ruby/server/lib/roma/tools/test-scenario.rb +327 -0
- data/{lib → ruby/server/lib}/roma/tools/tribunus.rb +0 -0
- data/ruby/server/lib/roma/version.rb +4 -0
- data/{lib → ruby/server/lib}/roma/write_behind.rb +1 -0
- data/ruby/server/test/config4mhash.rb +68 -0
- data/ruby/server/test/config4storage_error.rb +69 -0
- data/{lib/roma/config.rb → ruby/server/test/config4test.rb} +6 -3
- data/{test → ruby/server/test}/rcirb.rb +0 -1
- data/{test → ruby/server/test}/roma-test-utils.rb +21 -8
- data/{test → ruby/server/test}/run-test.rb +3 -2
- data/ruby/server/test/storage_error_storage.rb +37 -0
- data/ruby/server/test/t_command_definition.rb +326 -0
- data/{test → ruby/server/test}/t_cpdata.rb +9 -3
- data/{test → ruby/server/test}/t_listplugin.rb +48 -12
- data/ruby/server/test/t_mapcountplugin.rb +231 -0
- data/ruby/server/test/t_mapplugin.rb +131 -0
- data/ruby/server/test/t_mhash.rb +222 -0
- data/ruby/server/test/t_rclient.rb +199 -0
- data/{test → ruby/server/test}/t_routing_data.rb +56 -0
- data/{test → ruby/server/test}/t_storage.rb +107 -111
- data/ruby/server/test/t_storage_error.rb +61 -0
- data/ruby/server/test/t_writebehind.rb +374 -0
- metadata +150 -82
- data/bin/recoverlost_alist +0 -8
- data/bin/romad +0 -7
- data/lib/roma/command/mh_command_receiver.rb +0 -117
- data/lib/roma/command/receiver.rb +0 -287
- data/lib/roma/event/handler.rb +0 -159
- data/lib/roma/plugin/plugin_debug.rb +0 -19
- data/lib/roma/tools/recoverlost_lib.rb +0 -217
- data/lib/roma/version.rb +0 -4
- data/test/t_rclient.rb +0 -318
- data/test/t_writebehind.rb +0 -200
data/bin/recoverlost_alist
DELETED
data/bin/romad
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'roma/stats'
|
2
|
-
require 'roma/command/util_command_receiver'
|
3
|
-
|
4
|
-
module Roma
|
5
|
-
module Command
|
6
|
-
|
7
|
-
module MultiHashCommandReceiver
|
8
|
-
|
9
|
-
# defhash hashname
|
10
|
-
def ev_defhash(s)
|
11
|
-
if s.length!=2
|
12
|
-
send_data("CLIENT_ERROR usage:defhash hashname\r\n")
|
13
|
-
return
|
14
|
-
end
|
15
|
-
@defhash=s[1]
|
16
|
-
send_data("STORED\r\n")
|
17
|
-
end
|
18
|
-
|
19
|
-
# hashlist
|
20
|
-
def ev_hashlist(s)
|
21
|
-
ret=''
|
22
|
-
@storages.each_key{|hn| ret << hn << ' ' }
|
23
|
-
send_data("#{ret[0...-1]}\r\n")
|
24
|
-
end
|
25
|
-
|
26
|
-
# createhash hashname
|
27
|
-
def ev_createhash(s)
|
28
|
-
if s.length != 2
|
29
|
-
send_data("CLIENT_ERROR usage:createhash hashname\r\n")
|
30
|
-
return
|
31
|
-
end
|
32
|
-
res = broadcast_cmd("rcreatehash #{s[1]}\r\n")
|
33
|
-
res[@stats.ap_str] = createhash(s[1])
|
34
|
-
send_data("#{res.inspect}\r\n")
|
35
|
-
end
|
36
|
-
|
37
|
-
# rcreatehash hashname
|
38
|
-
def ev_rcreatehash(s)
|
39
|
-
if s.length != 2
|
40
|
-
send_data("CLIENT_ERROR usage:createhash hashname\r\n")
|
41
|
-
return
|
42
|
-
end
|
43
|
-
send_data("#{createhash(s[1])}\r\n")
|
44
|
-
end
|
45
|
-
|
46
|
-
def createhash(hname)
|
47
|
-
if @storages.key?(hname)
|
48
|
-
return "SERVER_ERROR #{hname} already exists."
|
49
|
-
end
|
50
|
-
st = Roma::Config::STORAGE_CLASS.new
|
51
|
-
st.storage_path = "#{@stats.ap_str}/#{hname}"
|
52
|
-
st.vn_list = @rttable.vnodes
|
53
|
-
st.divnum = Roma::Config::STORAGE_DIVNUM
|
54
|
-
st.option = Roma::Config::STORAGE_OPTION
|
55
|
-
@storages[hname] = st
|
56
|
-
@storages[hname].opendb
|
57
|
-
@log.info("createhash #{hname}")
|
58
|
-
return "CREATED"
|
59
|
-
rescue =>e
|
60
|
-
@log.error("#{e}")
|
61
|
-
end
|
62
|
-
private :createhash
|
63
|
-
|
64
|
-
# deletehash hashname
|
65
|
-
def ev_deletehash(s)
|
66
|
-
if s.length != 2
|
67
|
-
send_data("CLIENT_ERROR usage:deletehash hashname\r\n")
|
68
|
-
return
|
69
|
-
end
|
70
|
-
res = broadcast_cmd("rdeletehash #{s[1]}\r\n")
|
71
|
-
res[@stats.ap_str] = deletehash(s[1])
|
72
|
-
send_data("#{res.inspect}\r\n")
|
73
|
-
end
|
74
|
-
|
75
|
-
# rdeletehash hashname
|
76
|
-
def ev_rdeletehash(s)
|
77
|
-
if s.length != 2
|
78
|
-
send_data("CLIENT_ERROR usage:rdeletehash hashname\r\n")
|
79
|
-
return
|
80
|
-
end
|
81
|
-
send_data("#{deletehash(s[1])}\r\n")
|
82
|
-
end
|
83
|
-
|
84
|
-
def deletehash(hname)
|
85
|
-
unless @storages.key?(hname)
|
86
|
-
return "SERVER_ERROR #{hname} dose not exists."
|
87
|
-
end
|
88
|
-
if hname == 'roma'
|
89
|
-
return "SERVER_ERROR the hash name of 'roma' can't delete."
|
90
|
-
end
|
91
|
-
st = @storages[hname]
|
92
|
-
@storages.delete(hname)
|
93
|
-
st.closedb
|
94
|
-
rm_rf("#{@stats.ap_str}/#{hname}")
|
95
|
-
@log.info("deletehash #{hname}")
|
96
|
-
return "DELETED"
|
97
|
-
rescue =>e
|
98
|
-
@log.error("#{e}")
|
99
|
-
end
|
100
|
-
private :deletehash
|
101
|
-
|
102
|
-
# looked like a "rm -rf" command
|
103
|
-
def rm_rf(fname)
|
104
|
-
return unless File.exists?(fname)
|
105
|
-
if File::directory?(fname)
|
106
|
-
Dir["#{fname}/*"].each{|f| rm_rf(f) }
|
107
|
-
Dir.rmdir(fname)
|
108
|
-
else
|
109
|
-
File.delete(fname)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
private :rm_rf
|
113
|
-
|
114
|
-
end # MultiHashCommandReceiver
|
115
|
-
|
116
|
-
end # module Command
|
117
|
-
end # module Roma
|
@@ -1,287 +0,0 @@
|
|
1
|
-
require 'roma/stats'
|
2
|
-
require 'roma/version'
|
3
|
-
require 'roma/event/handler'
|
4
|
-
require 'roma/messaging/con_pool'
|
5
|
-
require 'roma/command/bg_command_receiver'
|
6
|
-
require 'roma/command/rt_command_receiver'
|
7
|
-
require 'roma/command/st_command_receiver'
|
8
|
-
require 'roma/command/util_command_receiver'
|
9
|
-
require 'roma/command/mh_command_receiver'
|
10
|
-
|
11
|
-
module Roma
|
12
|
-
module Command
|
13
|
-
|
14
|
-
class Receiver < Roma::Event::Handler
|
15
|
-
|
16
|
-
include BackgroundCommandReceiver
|
17
|
-
include RoutingCommandReceiver
|
18
|
-
include StorageCommandReceiver
|
19
|
-
include UtilCommandReceiver
|
20
|
-
include MultiHashCommandReceiver
|
21
|
-
|
22
|
-
def initialize(storages, rttable)
|
23
|
-
super(storages, rttable)
|
24
|
-
@stats = Roma::Stats.instance
|
25
|
-
@nid = @stats.ap_str
|
26
|
-
@defhash = 'roma'
|
27
|
-
end
|
28
|
-
|
29
|
-
# balse [reason]
|
30
|
-
def ev_balse(s)
|
31
|
-
send_data("Are you sure?(yes/no)\r\n")
|
32
|
-
if gets != "yes\r\n"
|
33
|
-
close_connection_after_writing
|
34
|
-
return
|
35
|
-
end
|
36
|
-
|
37
|
-
if s.length == 2
|
38
|
-
@log.info("Receive a balse #{s[1]}")
|
39
|
-
else
|
40
|
-
@log.info("Receive a balse command.")
|
41
|
-
end
|
42
|
-
@rttable.enabled_failover = false
|
43
|
-
res = broadcast_cmd("rbalse\r\n")
|
44
|
-
send_data("#{res.inspect}\r\n")
|
45
|
-
close_connection_after_writing
|
46
|
-
@stop_event_loop = true
|
47
|
-
end
|
48
|
-
|
49
|
-
# rbalse [reason]
|
50
|
-
def ev_rbalse(s)
|
51
|
-
if s.length == 2
|
52
|
-
@log.info("Receive a rbalse #{s[1]}")
|
53
|
-
else
|
54
|
-
@log.info("Receive a rbalse command.")
|
55
|
-
end
|
56
|
-
@rttable.enabled_failover = false
|
57
|
-
send_data("BYE\r\n")
|
58
|
-
close_connection_after_writing
|
59
|
-
@stop_event_loop = true
|
60
|
-
end
|
61
|
-
|
62
|
-
# version
|
63
|
-
def ev_version(s)
|
64
|
-
send_data("VERSION #{Roma::VERSION}\r\n")
|
65
|
-
end
|
66
|
-
|
67
|
-
# quit
|
68
|
-
def ev_quit(s)
|
69
|
-
close_connection
|
70
|
-
end
|
71
|
-
|
72
|
-
def ev_whoami(s)
|
73
|
-
send_data("#{@stats.name}\r\n")
|
74
|
-
end
|
75
|
-
|
76
|
-
# stats [regexp]
|
77
|
-
def ev_stats(s); ev_stat(s); end
|
78
|
-
|
79
|
-
# stat [regexp]
|
80
|
-
def ev_stat(s)
|
81
|
-
regexp = s[1] if s.length == 2
|
82
|
-
h = {}
|
83
|
-
h['version'] = Roma::VERSION
|
84
|
-
send_stat_result(nil,h,regexp)
|
85
|
-
send_stat_result(nil,Roma::Config.get_stat,regexp)
|
86
|
-
send_stat_result(nil,@stats.get_stat,regexp)
|
87
|
-
@storages.each{|hname,st|
|
88
|
-
send_stat_result("storages[#{hname}].",st.get_stat,regexp)
|
89
|
-
}
|
90
|
-
send_stat_result(nil,$roma.wb_get_stat,regexp)
|
91
|
-
send_stat_result(nil,@rttable.get_stat(@stats.ap_str),regexp)
|
92
|
-
send_data("END\r\n")
|
93
|
-
end
|
94
|
-
|
95
|
-
def send_stat_result(prefix,h,regexp = nil)
|
96
|
-
h.each{|k,v|
|
97
|
-
if prefix
|
98
|
-
key = "#{prefix}#{k}"
|
99
|
-
else
|
100
|
-
key = "#{k}"
|
101
|
-
end
|
102
|
-
if regexp
|
103
|
-
send_data("#{key} #{v}\r\n") if key =~ /#{regexp}/
|
104
|
-
else
|
105
|
-
send_data("#{key} #{v}\r\n")
|
106
|
-
end
|
107
|
-
}
|
108
|
-
end
|
109
|
-
private :send_stat_result
|
110
|
-
|
111
|
-
# writebehind_rotate [hash_name]
|
112
|
-
def ev_writebehind_rotate(s)
|
113
|
-
if s.length < 2
|
114
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
115
|
-
end
|
116
|
-
res = broadcast_cmd("rwritebehind_rotate #{s[1]}\r\n")
|
117
|
-
|
118
|
-
if $roma.wb_rotate(s[1])
|
119
|
-
res[@stats.ap_str] = "ROTATED"
|
120
|
-
else
|
121
|
-
res[@stats.ap_str] = "NOT_OPEND"
|
122
|
-
end
|
123
|
-
send_data("#{res}\r\n")
|
124
|
-
end
|
125
|
-
|
126
|
-
# rwritebehind_rotate [hash_name]
|
127
|
-
def ev_rwritebehind_rotate(s)
|
128
|
-
if s.length < 2
|
129
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
130
|
-
end
|
131
|
-
if $roma.wb_rotate(s[1])
|
132
|
-
send_data("ROTATED\r\n")
|
133
|
-
else
|
134
|
-
send_data("NOT_OPEND\r\n")
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# writebehind_get_path [hash_name]
|
139
|
-
def ev_writebehind_get_path(s)
|
140
|
-
if s.length < 2
|
141
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
142
|
-
end
|
143
|
-
res = broadcast_cmd("rwritebehind_get_path #{s[1]}\r\n")
|
144
|
-
|
145
|
-
ret = $roma.wb_get_path(s[1])
|
146
|
-
res[@stats.ap_str] = ret
|
147
|
-
|
148
|
-
send_data("#{res}\r\n")
|
149
|
-
end
|
150
|
-
|
151
|
-
# rwritebehind_get_path [hash_name]
|
152
|
-
def ev_rwritebehind_get_path(s)
|
153
|
-
if s.length < 2
|
154
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
155
|
-
end
|
156
|
-
|
157
|
-
ret = $roma.wb_get_path(s[1])
|
158
|
-
send_data("#{ret}\r\n")
|
159
|
-
end
|
160
|
-
|
161
|
-
# writebehind_get_current_file [hash_name]
|
162
|
-
def ev_writebehind_get_current_file(s)
|
163
|
-
if s.length < 2
|
164
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
165
|
-
end
|
166
|
-
res = broadcast_cmd("rwritebehind_get_current_file #{s[1]}\r\n")
|
167
|
-
|
168
|
-
ret = $roma.wb_get_current_file_path(s[1])
|
169
|
-
if ret
|
170
|
-
res[@stats.ap_str] = ret
|
171
|
-
else
|
172
|
-
res[@stats.ap_str] = "NOT_OPEND"
|
173
|
-
end
|
174
|
-
send_data("#{res}\r\n")
|
175
|
-
end
|
176
|
-
|
177
|
-
# rwritebehind_get_current_file [hash_name]
|
178
|
-
def ev_rwritebehind_get_current_file(s)
|
179
|
-
if s.length < 2
|
180
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
181
|
-
end
|
182
|
-
ret = $roma.wb_get_current_file_path(s[1])
|
183
|
-
if ret
|
184
|
-
send_data("#{ret}\r\n")
|
185
|
-
else
|
186
|
-
send_data("NOT_OPEND\r\n")
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
# dcnice command is setting priority for a data-copy thread.
|
191
|
-
# a niceness of 1 is the highest priority and 5 is the lowest priority.
|
192
|
-
# dcnice <priority:1 to 5>
|
193
|
-
def ev_dcnice(s)
|
194
|
-
if s.length < 2
|
195
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
196
|
-
end
|
197
|
-
res = broadcast_cmd("rdcnice #{s[1]}\r\n")
|
198
|
-
res[@stats.ap_str] = dcnice(s[1].to_i)
|
199
|
-
send_data("#{res}\r\n")
|
200
|
-
end
|
201
|
-
|
202
|
-
def ev_rdcnice(s)
|
203
|
-
if s.length < 2
|
204
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
205
|
-
end
|
206
|
-
|
207
|
-
send_data("#{dcnice(s[1].to_i)}\r\n")
|
208
|
-
end
|
209
|
-
|
210
|
-
def ev_restart(s)
|
211
|
-
res = broadcast_cmd("rrestart\r\n")
|
212
|
-
$roma.eventloop = true
|
213
|
-
EventMachine::stop_event_loop
|
214
|
-
res[@stats.ap_str] = "RESTARTED"
|
215
|
-
send_data("#{res}\r\n")
|
216
|
-
end
|
217
|
-
|
218
|
-
def ev_rrestart(s)
|
219
|
-
$roma.eventloop = true
|
220
|
-
EventMachine::stop_event_loop
|
221
|
-
send_data("RESTARTED\r\n")
|
222
|
-
end
|
223
|
-
|
224
|
-
# set_log_level [ 'debug' | 'info' | 'warn' | 'error' ]
|
225
|
-
def ev_set_log_level(s)
|
226
|
-
if s.length < 2
|
227
|
-
return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
|
228
|
-
end
|
229
|
-
|
230
|
-
case s[1].downcase
|
231
|
-
when 'debug'
|
232
|
-
@log.level = Roma::Logging::RLogger::Severity::DEBUG
|
233
|
-
when 'info'
|
234
|
-
@log.level = Roma::Logging::RLogger::Severity::INFO
|
235
|
-
when 'warn'
|
236
|
-
@log.level = Roma::Logging::RLogger::Severity::WARN
|
237
|
-
when 'error'
|
238
|
-
@log.level = Roma::Logging::RLogger::Severity::ERROR
|
239
|
-
else
|
240
|
-
return send_data("CLIENT_ERROR no match log-level string\r\n")
|
241
|
-
end
|
242
|
-
send_data("STORED\r\n")
|
243
|
-
end
|
244
|
-
|
245
|
-
private
|
246
|
-
|
247
|
-
def dcnice(p)
|
248
|
-
case(p)
|
249
|
-
when 1 # highest priority
|
250
|
-
@stats.stream_copy_wait_param = 0.001
|
251
|
-
@storages.each_value{|st|
|
252
|
-
st.each_vn_dump_sleep = 0.001
|
253
|
-
st.each_vn_dump_sleep_count = 1000
|
254
|
-
}
|
255
|
-
when 2
|
256
|
-
@stats.stream_copy_wait_param = 0.005
|
257
|
-
@storages.each_value{|st|
|
258
|
-
st.each_vn_dump_sleep = 0.005
|
259
|
-
st.each_vn_dump_sleep_count = 100
|
260
|
-
}
|
261
|
-
when 3 # default priority
|
262
|
-
@stats.stream_copy_wait_param = 0.01
|
263
|
-
@storages.each_value{|st|
|
264
|
-
st.each_vn_dump_sleep = 0.001
|
265
|
-
st.each_vn_dump_sleep_count = 10
|
266
|
-
}
|
267
|
-
when 4
|
268
|
-
@stats.stream_copy_wait_param = 0.01
|
269
|
-
@storages.each_value{|st|
|
270
|
-
st.each_vn_dump_sleep = 0.005
|
271
|
-
st.each_vn_dump_sleep_count = 10
|
272
|
-
}
|
273
|
-
when 5 # lowest priority
|
274
|
-
@stats.stream_copy_wait_param = 0.01
|
275
|
-
@storages.each_value{|st|
|
276
|
-
st.each_vn_dump_sleep = 0.01
|
277
|
-
st.each_vn_dump_sleep_count = 10
|
278
|
-
}
|
279
|
-
else
|
280
|
-
return "CLIENT_ERROR You sholud input a priority from 1 to 5."
|
281
|
-
end
|
282
|
-
"STORED"
|
283
|
-
end
|
284
|
-
end # class Receiver < Roma::Event::Handler
|
285
|
-
|
286
|
-
end # module Command
|
287
|
-
end # module Roma
|
data/lib/roma/event/handler.rb
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# File: handler.rb
|
3
|
-
#
|
4
|
-
require 'eventmachine'
|
5
|
-
require 'roma/event/con_pool'
|
6
|
-
require 'roma/logging/rlogger'
|
7
|
-
require 'socket'
|
8
|
-
|
9
|
-
module Roma
|
10
|
-
module Event
|
11
|
-
|
12
|
-
class Handler < EventMachine::Connection
|
13
|
-
@@ev_list={}
|
14
|
-
|
15
|
-
attr :stop_event_loop
|
16
|
-
attr :connected
|
17
|
-
attr :fiber
|
18
|
-
attr :rbuf
|
19
|
-
|
20
|
-
attr :storages
|
21
|
-
attr :rttable
|
22
|
-
attr_accessor :timeout
|
23
|
-
attr_reader :lastcmd
|
24
|
-
|
25
|
-
def initialize(storages, rttable)
|
26
|
-
@rbuf=''
|
27
|
-
unless has_event?
|
28
|
-
public_methods.each{|m|
|
29
|
-
if m.to_s.start_with?('ev_')
|
30
|
-
add_event(m.to_s[3..-1],m)
|
31
|
-
end
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
@storages = storages
|
36
|
-
@rttable = rttable
|
37
|
-
@timeout = 10
|
38
|
-
@log = Roma::Logging::RLogger.instance
|
39
|
-
end
|
40
|
-
|
41
|
-
def post_init
|
42
|
-
@addr = Socket.unpack_sockaddr_in(get_peername)
|
43
|
-
@log.info("Connected from #{@addr[1]}:#{@addr[0]}")
|
44
|
-
@connected = true
|
45
|
-
@fiber = Fiber.new { dispatcher }
|
46
|
-
end
|
47
|
-
|
48
|
-
def receive_data(data)
|
49
|
-
@rbuf << data
|
50
|
-
@fiber.resume
|
51
|
-
rescue =>e
|
52
|
-
@log.error("#{__FILE__}:#{__LINE__}:#{@addr[1]}:#{@addr[0]} #{e.inspect} #{$@}")
|
53
|
-
end
|
54
|
-
|
55
|
-
def unbind
|
56
|
-
@connected=false
|
57
|
-
@fiber.resume
|
58
|
-
EventMachine::stop_event_loop if @stop_event_loop
|
59
|
-
@log.info("Disconnected from #{@addr[1]}:#{@addr[0]}")
|
60
|
-
rescue =>e
|
61
|
-
@log.warn("#{__FILE__}:#{__LINE__}:#{@addr[1]}:#{@addr[0]} #{e.inspect} #{$@}")
|
62
|
-
end
|
63
|
-
|
64
|
-
protected
|
65
|
-
|
66
|
-
def has_event?
|
67
|
-
@@ev_list.length!=0
|
68
|
-
end
|
69
|
-
|
70
|
-
def add_event(c,m)
|
71
|
-
@@ev_list[c]=m
|
72
|
-
end
|
73
|
-
|
74
|
-
def exit
|
75
|
-
EventMachine::stop_event_loop
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def get_connection(ap)
|
81
|
-
con=Roma::Event::EMConPool::instance.get_connection(ap)
|
82
|
-
con.fiber=@fiber
|
83
|
-
con
|
84
|
-
end
|
85
|
-
|
86
|
-
def return_connection(ap,con)
|
87
|
-
Roma::Event::EMConPool.instance.return_connection(ap,con)
|
88
|
-
end
|
89
|
-
|
90
|
-
def dispatcher
|
91
|
-
while(@connected) do
|
92
|
-
next unless s=gets
|
93
|
-
s=s.chomp.split(/ /)
|
94
|
-
if s[0] && @@ev_list.key?(s[0].downcase)
|
95
|
-
send(@@ev_list[s[0].downcase],s)
|
96
|
-
@lastcmd=s
|
97
|
-
elsif s.length==0
|
98
|
-
next
|
99
|
-
elsif s[0]=='!!'
|
100
|
-
send(@@ev_list[@lastcmd[0].downcase],@lastcmd)
|
101
|
-
else
|
102
|
-
@log.warn("command error:#{s}")
|
103
|
-
send_data("ERROR\r\n")
|
104
|
-
close_connection_after_writing
|
105
|
-
end
|
106
|
-
end
|
107
|
-
rescue =>e
|
108
|
-
@log.warn("#{__FILE__}:#{__LINE__}:#{@addr[1]}:#{@addr[0]} #{e} #{$@}")
|
109
|
-
close_connection
|
110
|
-
end
|
111
|
-
|
112
|
-
def pop(size)
|
113
|
-
if @rbuf.size >= size
|
114
|
-
r = @rbuf[0..size-1]
|
115
|
-
@rbuf = @rbuf[size..-1]
|
116
|
-
r
|
117
|
-
else
|
118
|
-
nil
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def read_bytes(size, mult = 1)
|
123
|
-
t=Time.now.to_i
|
124
|
-
while(@connected) do
|
125
|
-
d = pop(size)
|
126
|
-
if d
|
127
|
-
return d
|
128
|
-
else
|
129
|
-
remain = size - @rbuf.size
|
130
|
-
Fiber.yield(remain)
|
131
|
-
if Time.now.to_i - t > @timeout * mult
|
132
|
-
@log.warn("#{__FILE__}:#{__LINE__}:#{@addr[1]}:#{@addr[0]} read_bytes time out");
|
133
|
-
close_connection
|
134
|
-
return nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
nil
|
139
|
-
end
|
140
|
-
|
141
|
-
def gets
|
142
|
-
while(@connected) do
|
143
|
-
if idx=@rbuf.index("\n")
|
144
|
-
return pop(idx+1)
|
145
|
-
else
|
146
|
-
Fiber.yield(@rbuf.size)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
nil
|
150
|
-
end
|
151
|
-
|
152
|
-
def detach_socket
|
153
|
-
@connected = false
|
154
|
-
Socket::for_fd(detach)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
end
|