roma 0.8.2 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANG +326 -0
  2. data/CHANGELOG +132 -0
  3. data/{README.rdoc → FETCH_HEAD} +0 -0
  4. data/{LICENSE.rdoc → LICENSE} +0 -1
  5. data/README +17 -0
  6. data/Rakefile +33 -18
  7. data/ruby/server/bin/chg_redundancy +10 -0
  8. data/ruby/server/bin/key_access +7 -0
  9. data/ruby/server/bin/key_list +7 -0
  10. data/ruby/server/bin/mkconfig +19 -0
  11. data/{bin → ruby/server/bin}/mkrecent +0 -1
  12. data/{bin → ruby/server/bin}/mkroute +0 -1
  13. data/ruby/server/bin/multi_commander +19 -0
  14. data/ruby/server/bin/recoverlost +10 -0
  15. data/ruby/server/bin/recoverlost_alist +10 -0
  16. data/ruby/server/bin/recoverlost_alist_all +10 -0
  17. data/ruby/server/bin/recoverlost_alist_keys +10 -0
  18. data/{bin/recoverlost → ruby/server/bin/roma_watcher} +1 -2
  19. data/ruby/server/bin/romad +36 -0
  20. data/{bin → ruby/server/bin}/sample_watcher +0 -1
  21. data/{bin → ruby/server/bin}/sample_watcher2 +0 -1
  22. data/{bin/simple_bench → ruby/server/bin/sample_watcher3} +1 -2
  23. data/ruby/server/bin/simple_bench +26 -0
  24. data/{bin → ruby/server/bin}/ssroute +0 -1
  25. data/ruby/server/bin/test-scenario +11 -0
  26. data/{bin → ruby/server/bin}/tribunus +0 -1
  27. data/{lib → ruby/server/lib}/roma/async_process.rb +67 -15
  28. data/{lib → ruby/server/lib}/roma/command/bg_command_receiver.rb +1 -1
  29. data/ruby/server/lib/roma/command/command_definition.rb +422 -0
  30. data/ruby/server/lib/roma/command/mh_command_receiver.rb +127 -0
  31. data/ruby/server/lib/roma/command/receiver.rb +64 -0
  32. data/{lib → ruby/server/lib}/roma/command/rt_command_receiver.rb +6 -1
  33. data/ruby/server/lib/roma/command/sys_command_receiver.rb +609 -0
  34. data/{lib → ruby/server/lib}/roma/command/util_command_receiver.rb +15 -5
  35. data/{lib → ruby/server/lib}/roma/command/vn_command_receiver.rb +12 -4
  36. data/{lib → ruby/server/lib}/roma/command_plugin.rb +0 -0
  37. data/ruby/server/lib/roma/config.rb +84 -0
  38. data/{lib → ruby/server/lib}/roma/event/con_pool.rb +12 -1
  39. data/ruby/server/lib/roma/event/handler.rb +256 -0
  40. data/ruby/server/lib/roma/live_patch-20120302-001.rb +107 -0
  41. data/ruby/server/lib/roma/logging/rlogger.rb +163 -0
  42. data/ruby/server/lib/roma/messaging/con_pool.rb +92 -0
  43. data/{lib → ruby/server/lib}/roma/plugin/plugin_alist.rb +118 -240
  44. data/ruby/server/lib/roma/plugin/plugin_debug.rb +31 -0
  45. data/ruby/server/lib/roma/plugin/plugin_map.rb +177 -0
  46. data/ruby/server/lib/roma/plugin/plugin_mapcount.rb +185 -0
  47. data/{lib/roma/command/st_command_receiver.rb → ruby/server/lib/roma/plugin/plugin_storage.rb} +170 -146
  48. data/ruby/server/lib/roma/plugin/plugin_stub.rb +283 -0
  49. data/{lib → ruby/server/lib}/roma/plugin/plugin_test.rb +0 -0
  50. data/{lib → ruby/server/lib}/roma/romad.rb +221 -94
  51. data/{lib → ruby/server/lib}/roma/routing/cb_rttable.rb +4 -6
  52. data/{lib → ruby/server/lib}/roma/routing/merkle_tree.rb +0 -0
  53. data/ruby/server/lib/roma/routing/routing_data.rb +307 -0
  54. data/{lib → ruby/server/lib}/roma/routing/rttable.rb +4 -0
  55. data/{lib → ruby/server/lib}/roma/stats.rb +19 -3
  56. data/{lib → ruby/server/lib}/roma/storage/basic_storage.rb +25 -26
  57. data/{lib → ruby/server/lib}/roma/storage/dbm_storage.rb +1 -23
  58. data/{lib → ruby/server/lib}/roma/storage/dummy_storage.rb +0 -0
  59. data/{lib → ruby/server/lib}/roma/storage/rh_storage.rb +0 -0
  60. data/{lib → ruby/server/lib}/roma/storage/sqlite3_storage.rb +0 -0
  61. data/{lib → ruby/server/lib}/roma/storage/tc_storage.rb +62 -2
  62. data/ruby/server/lib/roma/tools/chg_redundancy.rb +36 -0
  63. data/ruby/server/lib/roma/tools/key_access.rb +105 -0
  64. data/ruby/server/lib/roma/tools/key_list.rb +94 -0
  65. data/ruby/server/lib/roma/tools/mkconfig.rb +535 -0
  66. data/{lib → ruby/server/lib}/roma/tools/mkrecent.rb +0 -0
  67. data/{lib → ruby/server/lib}/roma/tools/mkroute.rb +0 -0
  68. data/ruby/server/lib/roma/tools/multi_commander.rb +45 -0
  69. data/{lib → ruby/server/lib}/roma/tools/recoverlost.rb +0 -0
  70. data/{lib → ruby/server/lib}/roma/tools/recoverlost_alist.rb +0 -0
  71. data/ruby/server/lib/roma/tools/recoverlost_alist_all.rb +8 -0
  72. data/ruby/server/lib/roma/tools/recoverlost_alist_keys.rb +16 -0
  73. data/ruby/server/lib/roma/tools/recoverlost_lib.rb +349 -0
  74. data/ruby/server/lib/roma/tools/roma_watcher.rb +150 -0
  75. data/ruby/server/lib/roma/tools/roma_watcher_config.yml.example +20 -0
  76. data/{lib → ruby/server/lib}/roma/tools/sample_watcher.rb +3 -1
  77. data/{lib → ruby/server/lib}/roma/tools/sample_watcher2.rb +3 -1
  78. data/ruby/server/lib/roma/tools/sample_watcher3.rb +49 -0
  79. data/{lib → ruby/server/lib}/roma/tools/simple_bench.rb +2 -0
  80. data/ruby/server/lib/roma/tools/simple_bench2.rb +78 -0
  81. data/{lib → ruby/server/lib}/roma/tools/ssroute.rb +0 -0
  82. data/ruby/server/lib/roma/tools/test-scenario.rb +327 -0
  83. data/{lib → ruby/server/lib}/roma/tools/tribunus.rb +0 -0
  84. data/ruby/server/lib/roma/version.rb +4 -0
  85. data/{lib → ruby/server/lib}/roma/write_behind.rb +1 -0
  86. data/ruby/server/test/config4mhash.rb +68 -0
  87. data/ruby/server/test/config4storage_error.rb +69 -0
  88. data/{lib/roma/config.rb → ruby/server/test/config4test.rb} +6 -3
  89. data/{test → ruby/server/test}/rcirb.rb +0 -1
  90. data/{test → ruby/server/test}/roma-test-utils.rb +21 -8
  91. data/{test → ruby/server/test}/run-test.rb +3 -2
  92. data/ruby/server/test/storage_error_storage.rb +37 -0
  93. data/ruby/server/test/t_command_definition.rb +326 -0
  94. data/{test → ruby/server/test}/t_cpdata.rb +9 -3
  95. data/{test → ruby/server/test}/t_listplugin.rb +48 -12
  96. data/ruby/server/test/t_mapcountplugin.rb +231 -0
  97. data/ruby/server/test/t_mapplugin.rb +131 -0
  98. data/ruby/server/test/t_mhash.rb +222 -0
  99. data/ruby/server/test/t_rclient.rb +199 -0
  100. data/{test → ruby/server/test}/t_routing_data.rb +56 -0
  101. data/{test → ruby/server/test}/t_storage.rb +107 -111
  102. data/ruby/server/test/t_storage_error.rb +61 -0
  103. data/ruby/server/test/t_writebehind.rb +374 -0
  104. metadata +150 -82
  105. data/bin/recoverlost_alist +0 -8
  106. data/bin/romad +0 -7
  107. data/lib/roma/command/mh_command_receiver.rb +0 -117
  108. data/lib/roma/command/receiver.rb +0 -287
  109. data/lib/roma/event/handler.rb +0 -159
  110. data/lib/roma/plugin/plugin_debug.rb +0 -19
  111. data/lib/roma/tools/recoverlost_lib.rb +0 -217
  112. data/lib/roma/version.rb +0 -4
  113. data/test/t_rclient.rb +0 -318
  114. data/test/t_writebehind.rb +0 -200
@@ -45,7 +45,7 @@ module Roma
45
45
  end
46
46
  end
47
47
 
48
- # recover [-r]
48
+ # recover [-r|-s]
49
49
  def ev_recover(s)
50
50
  option = s[1] if s.length == 2
51
51
  if @rttable.can_i_recover?
@@ -0,0 +1,422 @@
1
+ module Roma
2
+ module Command
3
+ module Definition
4
+
5
+ class ClientErrorException < Exception; end
6
+ class ServerErrorException < Exception; end
7
+
8
+ def self.included(base)
9
+ # include ClassMethods module into an eigen-class of a +base+
10
+ base.extend ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ def def_command_with_relay(cmd, &block)
16
+ # check a duplicated command definition in a same scope
17
+ if public_method_defined? "ev_#{cmd}".to_sym
18
+ raise "ev_#{cmd} already defined."
19
+ end
20
+
21
+ # define a command receiver
22
+ define_method "ev_#{cmd}" do |s|
23
+ begin
24
+ res = {}
25
+ res[@stats.ap_str] = instance_exec(s, &block)
26
+ # command relay
27
+ res.merge! broadcast_cmd("r#{cmd} #{s[1..-1].join(' ')}\r\n")
28
+ send_data("#{res}\r\n")
29
+ rescue ClientErrorException => e
30
+ send_data("CLIENT_ERROR #{e.message}\r\n")
31
+ rescue ServerErrorException => e
32
+ send_data("SERVER_ERROR #{e.message}\r\n")
33
+ rescue LocalJumpError => e
34
+ @log.warn("#{e} #{$@}")
35
+ e.exit_value
36
+ end
37
+ end
38
+
39
+ # define a relaid command receiver
40
+ define_method "ev_r#{cmd}" do |s|
41
+ begin
42
+ send_data("#{instance_exec(s, &block)}\r\n")
43
+ rescue ClientErrorException => e
44
+ send_data("CLIENT_ERROR #{e.message}\r\n")
45
+ rescue ServerErrorException => e
46
+ send_data("SERVER_ERROR #{e.message}\r\n")
47
+ rescue LocalJumpError => e
48
+ @log.warn("#{e} #{$@}")
49
+ e.exit_value
50
+ end
51
+ end
52
+ end # def_command_with_relay
53
+
54
+ CommandParams = Struct.new(:key, :hash_name, :digest, :vn, :nodes, :value)
55
+ StoredData = Struct.new(:vn, :last, :clk, :flg, :expt, :value)
56
+ CommandContext = Struct.new(:argv, :params, :stored)
57
+
58
+ def def_read_command_with_key(cmd, forward = :one_line, &block)
59
+ define_method "ev_#{cmd}" do |s|
60
+ return send_data("CLIENT_ERROR dose not find key\r\n") if s.length < 2
61
+ begin
62
+ params = CommandParams.new
63
+ params.key, params.hash_name = s[1].split("\e")
64
+ params.hash_name ||= @defhash
65
+ params.digest = Digest::SHA1.hexdigest(params.key).hex % @rttable.hbits
66
+ params.vn = @rttable.get_vnode_id(params.digest)
67
+ params.nodes = @rttable.search_nodes_for_write(params.vn)
68
+ if params.nodes[0] != @nid
69
+ if forward == :one_line
70
+ return forward_and_one_line_receive(params.nodes[0], s)
71
+ elsif forward == :multi_line
72
+ return forward_and_multi_line_receive(params.nodes[0], s)
73
+ end
74
+ end
75
+ stored = StoredData.new
76
+ unless @storages[params.hash_name]
77
+ return send_data("SERVER_ERROR #{params.hash_name} dose not exists.\r\n")
78
+ end
79
+
80
+ stored.vn, stored.last, stored.clk, stored.expt, stored.value =
81
+ @storages[params.hash_name].get_raw(params.vn, params.key, params.digest)
82
+ stored = nil if stored.vn == nil || Time.now.to_i > stored.expt
83
+ ctx = CommandContext.new(s, params, stored)
84
+ instance_exec(ctx, &block)
85
+ @stats.read_count += 1
86
+ rescue ClientErrorException => e
87
+ send_data("CLIENT_ERROR #{e.message}\r\n")
88
+ rescue ServerErrorException => e
89
+ send_data("SERVER_ERROR #{e.message}\r\n")
90
+ rescue LocalJumpError => e
91
+ @log.warn("#{e} #{$@}")
92
+ e.exit_value
93
+ end
94
+ end
95
+ end # def_read_command_with_key
96
+
97
+ def def_write_command_with_key(cmd, forward = :one_line, &block)
98
+ define_method "ev_#{cmd}" do |s|
99
+ return send_data("CLIENT_ERROR dose not find key\r\n") if s.length < 2
100
+ begin
101
+ params = CommandParams.new
102
+ params.key, params.hash_name = s[1].split("\e")
103
+ params.hash_name ||= @defhash
104
+ params.digest = Digest::SHA1.hexdigest(params.key).hex % @rttable.hbits
105
+ params.vn = @rttable.get_vnode_id(params.digest)
106
+ params.nodes = @rttable.search_nodes_for_write(params.vn)
107
+ if params.nodes[0] != @nid
108
+ if forward == :one_line
109
+ return forward_and_one_line_receive(params.nodes[0], s)
110
+ elsif forward == :multi_line
111
+ return forward_and_multi_line_receive(params.nodes[0], s)
112
+ end
113
+ end
114
+ stored = StoredData.new
115
+ unless @storages[params.hash_name]
116
+ return send_data("SERVER_ERROR #{params.hash_name} dose not exists.\r\n")
117
+ end
118
+
119
+ stored.vn, stored.last, stored.clk, stored.expt, stored.value =
120
+ @storages[params.hash_name].get_raw(params.vn, params.key, params.digest)
121
+ stored = nil if stored.vn == nil || Time.now.to_i > stored.expt
122
+ ctx = CommandContext.new(s, params, stored)
123
+
124
+ ret = instance_exec(ctx, &block)
125
+ if ret.instance_of? Array
126
+ flg, expt, value, count, msg = ret
127
+ ret = @storages[ctx.params.hash_name].set(ctx.params.vn,
128
+ ctx.params.key,
129
+ ctx.params.digest,
130
+ expt,
131
+ value)
132
+ if count == :write
133
+ @stats.write_count += 1
134
+ elsif count == :delete
135
+ @stats.delete_count += 1
136
+ end
137
+
138
+ if ret
139
+ if @stats.wb_command_map.key?(cmd.to_sym)
140
+ Roma::WriteBehindProcess::push(ctx.params.hash_name, @stats.wb_command_map[cmd.to_sym], ctx.params.key, ret[4])
141
+ end
142
+ redundant(ctx.params.nodes[1..-1], ctx.params.hash_name,
143
+ ctx.params.key, ctx.params.digest, ret[2],
144
+ expt, ret[4])
145
+ send_data("#{msg}\r\n")
146
+ else
147
+ send_data("NOT_#{msg}\r\n")
148
+ end
149
+ end
150
+ rescue ClientErrorException => e
151
+ send_data("CLIENT_ERROR #{e.message}\r\n")
152
+ rescue ServerErrorException => e
153
+ send_data("SERVER_ERROR #{e.message}\r\n")
154
+ rescue LocalJumpError => e
155
+ @log.warn("#{e} #{$@}")
156
+ e.exit_value
157
+ end
158
+ end
159
+ end # def_write_command_with_key
160
+
161
+ def def_command_with_key(cmd, forward = :one_line, &block)
162
+ define_method "ev_#{cmd}" do |s|
163
+ return send_data("CLIENT_ERROR dose not find key\r\n") if s.length < 2
164
+ begin
165
+ params = CommandParams.new
166
+ params.key, params.hash_name = s[1].split("\e")
167
+ params.hash_name ||= @defhash
168
+ params.digest = Digest::SHA1.hexdigest(params.key).hex % @rttable.hbits
169
+ params.vn = @rttable.get_vnode_id(params.digest)
170
+ params.nodes = @rttable.search_nodes_for_write(params.vn)
171
+ if params.nodes[0] != @nid
172
+ if forward == :one_line
173
+ return forward_and_one_line_receive(params.nodes[0], s)
174
+ elsif forward == :multi_line
175
+ return forward_and_multi_line_receive(params.nodes[0], s)
176
+ end
177
+ end
178
+ stored = StoredData.new
179
+ unless @storages[params.hash_name]
180
+ return send_data("SERVER_ERROR #{params.hash_name} dose not exists.\r\n")
181
+ end
182
+
183
+ stored.vn, stored.last, stored.clk, stored.expt, stored.value =
184
+ @storages[params.hash_name].get_raw(params.vn, params.key, params.digest)
185
+ stored = nil if stored.vn == nil || Time.now.to_i > stored.expt
186
+ ctx = CommandContext.new(s, params, stored)
187
+ instance_exec(ctx, &block)
188
+ rescue ClientErrorException => e
189
+ send_data("CLIENT_ERROR #{e.message}\r\n")
190
+ rescue ServerErrorException => e
191
+ send_data("SERVER_ERROR #{e.message}\r\n")
192
+ rescue LocalJumpError => e
193
+ @log.warn("#{e} #{$@}")
194
+ e.exit_value
195
+ end
196
+ end
197
+ end # def_command_with_key
198
+
199
+ def def_write_command_with_key_value(cmd, idx_of_val_len, forward = :one_line, &block)
200
+ define_method "ev_#{cmd}" do |s|
201
+ return send_data("CLIENT_ERROR dose not find key\r\n") if s.length < 2
202
+ begin
203
+ params = CommandParams.new
204
+ params.key, params.hash_name = s[1].split("\e")
205
+ params.hash_name ||= @defhash
206
+ params.digest = Digest::SHA1.hexdigest(params.key).hex % @rttable.hbits
207
+ params.vn = @rttable.get_vnode_id(params.digest)
208
+ params.nodes = @rttable.search_nodes_for_write(params.vn)
209
+ params.value = read_bytes(s[idx_of_val_len].to_i)
210
+ read_bytes(2)
211
+ if params.nodes[0] != @nid
212
+ if forward == :one_line
213
+ return forward_and_one_line_receive(params.nodes[0], s, params.value)
214
+ elsif forward == :multi_line
215
+ return forward_and_multi_line_receive(params.nodes[0], s, params.value)
216
+ end
217
+ end
218
+ stored = StoredData.new
219
+ unless @storages[params.hash_name]
220
+ return send_data("SERVER_ERROR #{params.hash_name} dose not exists.\r\n")
221
+ end
222
+
223
+ stored.vn, stored.last, stored.clk, stored.expt, stored.value =
224
+ @storages[params.hash_name].get_raw(params.vn, params.key, params.digest)
225
+ stored = nil if stored.vn == nil || Time.now.to_i > stored.expt
226
+ ctx = CommandContext.new(s, params, stored)
227
+
228
+ ret = instance_exec(ctx, &block)
229
+ if ret.instance_of? Array
230
+ flg, expt, value, count, msg = ret
231
+ ret = @storages[ctx.params.hash_name].set(ctx.params.vn,
232
+ ctx.params.key,
233
+ ctx.params.digest,
234
+ expt,
235
+ value)
236
+ if count == :write
237
+ @stats.write_count += 1
238
+ elsif count == :delete
239
+ @stats.delete_count += 1
240
+ end
241
+
242
+ if ret
243
+ if @stats.wb_command_map.key?(cmd.to_sym)
244
+ Roma::WriteBehindProcess::push(ctx.params.hash_name, @stats.wb_command_map[cmd.to_sym], ctx.params.key, ctx.params.value)
245
+ end
246
+ redundant(ctx.params.nodes[1..-1], ctx.params.hash_name,
247
+ ctx.params.key, ctx.params.digest, ret[2],
248
+ expt, ret[4])
249
+ send_data("#{msg}\r\n")
250
+ else
251
+ send_data("NOT_#{msg}\r\n")
252
+ end
253
+ end
254
+ rescue ClientErrorException => e
255
+ send_data("CLIENT_ERROR #{e.message}\r\n")
256
+ rescue ServerErrorException => e
257
+ send_data("SERVER_ERROR #{e.message}\r\n")
258
+ rescue LocalJumpError => e
259
+ @log.warn("#{e} #{$@}")
260
+ e.exit_value
261
+ end
262
+ end
263
+ end # def_write_command_with_key_value
264
+
265
+ def def_read_command_with_key_value(cmd, idx_of_val_len, forward = :one_line, &block)
266
+ define_method "ev_#{cmd}" do |s|
267
+ return send_data("CLIENT_ERROR dose not find key\r\n") if s.length < 2
268
+ begin
269
+ params = CommandParams.new
270
+ params.key, params.hash_name = s[1].split("\e")
271
+ params.hash_name ||= @defhash
272
+ params.digest = Digest::SHA1.hexdigest(params.key).hex % @rttable.hbits
273
+ params.vn = @rttable.get_vnode_id(params.digest)
274
+ params.nodes = @rttable.search_nodes_for_write(params.vn)
275
+ params.value = read_bytes(s[idx_of_val_len].to_i)
276
+ read_bytes(2)
277
+ if params.nodes[0] != @nid
278
+ if forward == :one_line
279
+ return forward_and_one_line_receive(params.nodes[0], s, params.value)
280
+ elsif forward == :multi_line
281
+ return forward_and_multi_line_receive(params.nodes[0], s, params.value)
282
+ end
283
+ end
284
+ stored = StoredData.new
285
+ unless @storages[params.hash_name]
286
+ return send_data("SERVER_ERROR #{params.hash_name} dose not exists.\r\n")
287
+ end
288
+
289
+ stored.vn, stored.last, stored.clk, stored.expt, stored.value =
290
+ @storages[params.hash_name].get_raw(params.vn, params.key, params.digest)
291
+ stored = nil if stored.vn == nil || Time.now.to_i > stored.expt
292
+ ctx = CommandContext.new(s, params, stored)
293
+
294
+ instance_exec(ctx, &block)
295
+ @stats.read_count += 1
296
+ rescue ClientErrorException => e
297
+ send_data("CLIENT_ERROR #{e.message}\r\n")
298
+ rescue ServerErrorException => e
299
+ send_data("SERVER_ERROR #{e.message}\r\n")
300
+ rescue LocalJumpError => e
301
+ @log.warn("#{e} #{$@}")
302
+ e.exit_value
303
+ end
304
+ end
305
+ end # def_read_command_with_key_value
306
+
307
+ def def_command_with_key_value(cmd, idx_of_val_len, forward = :one_line, &block)
308
+ define_method "ev_#{cmd}" do |s|
309
+ return send_data("CLIENT_ERROR dose not find key\r\n") if s.length < 2
310
+ begin
311
+ params = CommandParams.new
312
+ params.key, params.hash_name = s[1].split("\e")
313
+ params.hash_name ||= @defhash
314
+ params.digest = Digest::SHA1.hexdigest(params.key).hex % @rttable.hbits
315
+ params.vn = @rttable.get_vnode_id(params.digest)
316
+ params.nodes = @rttable.search_nodes_for_write(params.vn)
317
+ params.value = read_bytes(s[idx_of_val_len].to_i)
318
+ read_bytes(2)
319
+ if params.nodes[0] != @nid
320
+ if forward == :one_line
321
+ return forward_and_one_line_receive(params.nodes[0], s, params.value)
322
+ elsif forward == :multi_line
323
+ return forward_and_multi_line_receive(params.nodes[0], s, params.value)
324
+ end
325
+ end
326
+ stored = StoredData.new
327
+ unless @storages[params.hash_name]
328
+ return send_data("SERVER_ERROR #{params.hash_name} dose not exists.\r\n")
329
+ end
330
+
331
+ stored.vn, stored.last, stored.clk, stored.expt, stored.value =
332
+ @storages[params.hash_name].get_raw(params.vn, params.key, params.digest)
333
+ stored = nil if stored.vn == nil || Time.now.to_i > stored.expt
334
+ ctx = CommandContext.new(s, params, stored)
335
+ instance_exec(ctx, &block)
336
+ rescue ClientErrorException => e
337
+ send_data("CLIENT_ERROR #{e.message}\r\n")
338
+ rescue ServerErrorException => e
339
+ send_data("SERVER_ERROR #{e.message}\r\n")
340
+ rescue LocalJumpError => e
341
+ @log.warn("#{e} #{$@}")
342
+ e.exit_value
343
+ end
344
+ end
345
+ end # def_command_with_key_value
346
+
347
+ end # module ClassMethods
348
+
349
+ #
350
+ def forward_and_one_line_receive(nid, rs, data = nil)
351
+ if rs.last == "forward"
352
+ return send_data("SERVER_ERROR Routing table is inconsistent.\r\n")
353
+ end
354
+
355
+ @log.warn("forward #{rs} to #{nid}");
356
+
357
+ buf = rs.join(' ') + " forward\r\n"
358
+ buf << data + "\r\n" if data
359
+ res = send_cmd(nid, buf)
360
+ if res == nil || res.start_with?("ERROR")
361
+ return send_data("SERVER_ERROR Message forward failed.\r\n")
362
+ end
363
+ send_data("#{res}\r\n")
364
+ end
365
+
366
+ #
367
+ def forward_and_multi_line_receive(nid, rs, data=nil)
368
+ if rs.last == "forward"
369
+ return send_data("SERVER_ERROR Routing table is inconsistent.\r\n")
370
+ end
371
+
372
+ @log.warn("forward #{rs} to #{nid}");
373
+
374
+ buf = rs.join(' ') + " forward\r\n"
375
+ buf << data + "\r\n" if data
376
+
377
+ con = get_connection(nid)
378
+ con.send(buf)
379
+
380
+ buf = con.gets
381
+ if buf == nil
382
+ @rttable.proc_failed(nid)
383
+ @log.error("forward get failed:nid=#{nid} rs=#{rs} #{$@}")
384
+ return send_data("SERVER_ERROR Message forward failed.\r\n")
385
+ elsif buf.start_with?("ERROR")
386
+ @rttable.proc_succeed(nid)
387
+ con.close_connection
388
+ @log.error("forward get failed:nid=#{nid} rs=#{rs} #{$@}")
389
+ return send_data("SERVER_ERROR Message forward failed.\r\n")
390
+ elsif buf.start_with?("VALUE") == false
391
+ return_connection(nid, con)
392
+ @rttable.proc_succeed(nid)
393
+ return send_data(buf)
394
+ end
395
+
396
+ res = ''
397
+ begin
398
+ res << buf
399
+ s = buf.split(/ /)
400
+ if s[0] != 'VALUE'
401
+ return_connection(nid, con)
402
+ @rttable.proc_succeed(nid)
403
+ return send_data(buf)
404
+ end
405
+ res << con.read_bytes(s[3].to_i + 2)
406
+ end while (buf = con.gets)!="END\r\n"
407
+
408
+ res << "END\r\n"
409
+
410
+ return_connection(nid, con)
411
+ @rttable.proc_succeed(nid)
412
+
413
+ send_data(res)
414
+ rescue => e
415
+ @rttable.proc_failed(nid) if e.message != "no connection"
416
+ @log.error("forward get failed:nid=#{nid} rs=#{rs} #{e} #{$@}")
417
+ send_data("SERVER_ERROR Message forward failed.\r\n")
418
+ end
419
+
420
+ end # module Definition
421
+ end # module Command
422
+ end # module Roma
@@ -0,0 +1,127 @@
1
+ require 'fileutils'
2
+ require 'roma/stats'
3
+ require 'roma/command/util_command_receiver'
4
+ require 'roma/command/command_definition'
5
+
6
+ module Roma
7
+ module Command
8
+
9
+ module MultiHashCommandReceiver
10
+ include Roma::Command::Definition
11
+
12
+ # defhash <name>
13
+ def_command_with_relay :defhash do |s|
14
+ if s.length != 2
15
+ "#{@defhash}"
16
+ else
17
+ unless @storages.key?(s[1])
18
+ raise(Roma::Command::Definition::ClientErrorException,
19
+ "#{s[1]} dose not find.")
20
+ end
21
+ @defhash = s[1]
22
+ "STORED"
23
+ end
24
+ end
25
+
26
+ # mounthash <name>
27
+ def_command_with_relay :mounthash do |s|
28
+ if s.length != 2
29
+ raise(Roma::Command::Definition::ClientErrorException,
30
+ "usage:mounthash <name>")
31
+ end
32
+ if @storages.key?(s[1])
33
+ raise(Roma::Command::Definition::ServerErrorException,
34
+ "#{s[1]} already mounted.")
35
+ end
36
+ # check a directory existence
37
+ unless File.directory? "#{Config::STORAGE_PATH}/#{@stats.ap_str}/#{s[1]}"
38
+ raise(Roma::Command::Definition::ServerErrorException,
39
+ "#{s[1]} dose not find.")
40
+ end
41
+ createhash(s[1], 'MOUNTED')
42
+ end
43
+
44
+ # umounthash <name>
45
+ def_command_with_relay :umounthash do |s|
46
+ if s.length != 2
47
+ raise(Roma::Command::Definition::ClientErrorException,
48
+ "usage:umounthash <name>")
49
+ end
50
+ unless @storages.key?(s[1])
51
+ raise(Roma::Command::Definition::ServerErrorException,
52
+ "#{s[1]} dose not find.")
53
+ end
54
+ umounthash(s[1])
55
+ end
56
+
57
+ # createhash <name>
58
+ def_command_with_relay :createhash do |s|
59
+ if s.length != 2
60
+ raise(Roma::Command::Definition::ClientErrorException,
61
+ "usage:createhash <name>")
62
+ end
63
+ createhash(s[1], 'CREATED')
64
+ end
65
+
66
+ # deletehash <name>
67
+ def_command_with_relay :deletehash do |s|
68
+ if s.length != 2
69
+ raise(Roma::Command::Definition::ClientErrorException,
70
+ "usage:deletehash <name>")
71
+ end
72
+ deletehash(s[1])
73
+ end
74
+
75
+ # hashlist
76
+ def ev_hashlist(s)
77
+ send_data("#{@storages.keys.join ' '}\r\n")
78
+ end
79
+
80
+ def createhash(hname, msg)
81
+ if @storages.key?(hname)
82
+ return "SERVER_ERROR #{hname} already exists."
83
+ end
84
+ st = Config::STORAGE_CLASS.new
85
+ st.storage_path = "#{Config::STORAGE_PATH}/#{@stats.ap_str}/#{hname}"
86
+ st.vn_list = @rttable.vnodes
87
+ st.divnum = Config::STORAGE_DIVNUM
88
+ st.option = Config::STORAGE_OPTION
89
+ @storages[hname] = st
90
+ @storages[hname].opendb
91
+ @log.info("createhash #{hname}")
92
+ return msg
93
+ rescue =>e
94
+ @log.error("#{e} #{$@}")
95
+ "NOT #{msg}"
96
+ end
97
+ private :createhash
98
+
99
+ def deletehash(hname)
100
+ ret = umounthash(hname)
101
+ return ret if ret != 'UNMOUNTED'
102
+ FileUtils.rm_rf "#{Config::STORAGE_PATH}/#{@stats.ap_str}/#{hname}"
103
+ @log.info("deletehash #{hname}")
104
+ return "DELETED"
105
+ rescue =>e
106
+ @log.error("#{e}")
107
+ end
108
+ private :deletehash
109
+
110
+ def umounthash(hname)
111
+ if @defhash == hname
112
+ return "SERVER_ERROR default hash can't unmount."
113
+ end
114
+ unless @storages.key?(hname)
115
+ return "SERVER_ERROR #{hname} dose not exists."
116
+ end
117
+ st = @storages[hname]
118
+ @storages.delete(hname)
119
+ st.closedb
120
+ "UNMOUNTED"
121
+ end
122
+ private :umounthash
123
+
124
+ end # MultiHashCommandReceiver
125
+
126
+ end # module Command
127
+ end # module Roma