roma 0.8.11 → 0.8.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
-
2
1
  # -*- coding: utf-8 -*-
3
2
  require 'thread'
4
3
  require 'digest/sha1'
@@ -86,7 +85,7 @@ module Roma
86
85
  end
87
86
 
88
87
  def asyncev_broadcast_cmd(args)
89
- @log.debug("asyncev_broadcast_cmd #{args.inspect}")
88
+ @log.debug("#{__method__} #{args.inspect}")
90
89
  cmd, nids, tout = args
91
90
  t = Thread::new{
92
91
  async_broadcast_cmd("#{cmd}\r\n", nids, tout)
@@ -95,88 +94,66 @@ module Roma
95
94
  true
96
95
  end
97
96
 
98
- def asyncev_start_acquire_vnodes_process(args)
99
- @log.debug("asyncev_start_acquire_vnodes_process")
100
- if @stats.run_acquire_vnodes
101
- @log.error("asyncev_start_acquire_vnodes_process:already in being")
97
+ def asyncev_start_join_process(args)
98
+ @log.debug(__method__)
99
+ if @stats.run_join
100
+ @log.error("#{__method__}:join process running")
102
101
  return true
103
102
  end
104
- @stats.run_acquire_vnodes = true
105
- t = Thread::new{
103
+ if @stats.run_recover
104
+ @log.error("#{__method__}:recover process running")
105
+ return true
106
+ end
107
+ if @stats.run_balance
108
+ @log.error("#{__method__}:balance process running")
109
+ return true
110
+ end
111
+ @stats.run_join = true
112
+ t = Thread::new do
106
113
  begin
107
- acquire_vnodes_process
114
+ join_process
108
115
  rescue =>e
109
- @log.error("asyncev_start_acquire_vnodes_process:#{e.inspect} #{$@}")
116
+ @log.error("#{__method__}:#{e.inspect} #{$@}")
110
117
  ensure
111
- @stats.run_acquire_vnodes = false
118
+ @stats.run_join = false
112
119
  @stats.join_ap = nil
113
120
  end
114
- }
121
+ end
115
122
  t[:name] = __method__
116
- true
123
+ true
117
124
  end
118
125
 
119
- def asyncev_start_dumpfile_process(args)
120
- @log.debug("asyncev_start_dumpfile_process #{args.inspect}")
121
- key, path, cmd = args
122
- path = Roma::Config::STORAGE_DUMP_PATH + '/' + path
123
- t = Thread.new{
126
+ def asyncev_start_balance_process(args)
127
+ @log.debug(__method__)
128
+ if @stats.run_join
129
+ @log.error("#{__method__}:join process running")
130
+ return true
131
+ end
132
+ if @stats.run_recover
133
+ @log.error("#{__method__}:recover process running")
134
+ return true
135
+ end
136
+ if @stats.run_balance
137
+ @log.error("#{__method__}:balance process running")
138
+ return true
139
+ end
140
+ @stats.run_balance = true
141
+ t = Thread::new do
124
142
  begin
125
- except_vnh = {}
126
- @rttable.each_vnode{|vn,nids|
127
- if nids[0]!=@stats.ap_str
128
- except_vnh[vn]=vn
129
- end
130
- }
131
- # cmd expect the :dumpfile or :rdumpfile.
132
- delete_to_end_of_dump(key) if cmd == :dumpfile
133
- sleep 0.1
134
- @storages.each_pair{|hname,st|
135
- st.dump_file("#{path}/#{@stats.ap_str}/#{hname}",except_vnh)
136
- }
137
- ret = set_to_end_of_dump(key,@stats.ap_str)
138
- if ret==nil || ret!="STORED"
139
- @log.error("asyncev_start_dumpfile_process:result of set_to_end_of_dump was #{ret.inspect}")
140
- end
141
- @log.info("asyncev_start_dumpfile_process has done.")
143
+ balance_process
142
144
  rescue =>e
143
- @log.error("#{e}\n#{$@}")
145
+ @log.error("#{__method__}:#{e.inspect} #{$@}")
146
+ ensure
147
+ @stats.run_balance = false
144
148
  end
145
- }
149
+ end
146
150
  t[:name] = __method__
147
- true
148
- end
149
-
150
- def delete_to_end_of_dump(key)
151
- con = Roma::Messaging::ConPool.instance.get_connection(@stats.ap_str)
152
- con.write("delete #{key}\eroma\r\n")
153
- res = con.gets
154
- res.chomp! if res
155
- Roma::Messaging::ConPool.instance.return_connection(@stats.ap_str,con)
156
- res
157
- end
158
-
159
- def set_to_end_of_dump(key,nid)
160
- count = 0
161
- begin
162
- sleep 0.1
163
- con = Roma::Messaging::ConPool.instance.get_connection(nid)
164
- con.write("add #{key}\eroma 0 86400 #{nid.length}\r\n#{nid}\r\n")
165
- res = con.gets
166
- unless res=="STORED\r\n"
167
- con.write("append #{key}\eroma 0 86400 #{nid.length+1}\r\n,#{nid}\r\n")
168
- res = con.gets
169
- end
170
- Roma::Messaging::ConPool.instance.return_connection(nid,con)
171
- count += 1
172
- end while(res!="STORED\r\n" && count < 5)
173
- res.chomp! if res
174
- res
151
+ true
175
152
  end
176
153
 
177
154
  def asyncev_redundant(args)
178
155
  nid,hname,k,d,clk,expt,v = args
179
- @log.debug("asyncev_redundant #{args.inspect}")
156
+ @log.debug("#{__method__} #{args.inspect}")
180
157
  unless @rttable.nodes.include?(nid)
181
158
  @log.warn("async redundant failed:#{nid} dose not found in routing table.#{k}\e#{hname} #{d} #{clk} #{expt} #{v.length}")
182
159
  return true # no retry
@@ -191,7 +168,7 @@ module Roma
191
168
 
192
169
  def asyncev_zredundant(args)
193
170
  nid,hname,k,d,clk,expt,zv = args
194
- @log.debug("asyncev_zredundant #{args.inspect}")
171
+ @log.debug("#{__method__} #{args.inspect}")
195
172
  unless @rttable.nodes.include?(nid)
196
173
  @log.warn("async zredundant failed:#{nid} dose not found in routing table.#{k}\e#{hname} #{d} #{clk} #{expt} #{zv.length}")
197
174
  return true # no retry
@@ -206,7 +183,7 @@ module Roma
206
183
 
207
184
  def asyncev_rdelete(args)
208
185
  nid,hname,k,clk = args
209
- @log.debug("asyncev_rdelete #{args.inspect}")
186
+ @log.debug("#{__method__} #{args.inspect}")
210
187
  unless @rttable.nodes.include?(nid)
211
188
  @log.warn("async rdelete failed:#{nid} dose not found in routing table.#{k}\e#{hname} #{clk}")
212
189
  return true # no retry
@@ -221,101 +198,87 @@ module Roma
221
198
 
222
199
  def asyncev_reqpushv(args)
223
200
  vn, nid, p = args
224
- @log.debug("asyncev_reqpushv #{args.inspect}")
225
- t = Thread::new{
226
- sync_a_vnode(vn.to_i, nid, p == 'true')
227
- }
228
- t[:name] = __method__
201
+ @log.debug("#{__method__} #{args.inspect}")
202
+ if @stats.run_iterate_storage
203
+ @log.warn("#{__method__}:already be iterated storage process.")
204
+ else
205
+ @stats.run_iterate_storage = true
206
+ t = Thread::new do
207
+ begin
208
+ sync_a_vnode(vn.to_i, nid, p == 'true')
209
+ rescue =>e
210
+ @log.error("#{__method__}:#{e.inspect} #{$@}")
211
+ ensure
212
+ @stats.run_iterate_storage = false
213
+ end
214
+ end
215
+ t[:name] = __method__
216
+ end
229
217
  end
230
218
 
231
219
  def asyncev_start_recover_process(args)
232
- @log.debug("asyncev_start_recover_process #{args.inspect}")
220
+ @log.debug("#{__method__} #{args.inspect}")
221
+ if @stats.run_join
222
+ @log.error("#{__method__}:join process running")
223
+ return true
224
+ end
225
+ if @stats.run_recover
226
+ @log.error("#{__method__}:recover process running.")
227
+ return false
228
+ end
229
+ if @stats.run_balance
230
+ @log.error("#{__method__}:balance process running")
231
+ return true
232
+ end
233
233
  @stats.run_recover = true
234
- t = Thread::new{
234
+ t = Thread::new do
235
235
  begin
236
- if args == nil || args.length == 0
237
- acquired_recover_process
238
- elsif args[0] == '-s'
239
- recover_process
240
- elsif args[0] == '-r' || args[0] == nil
241
- acquired_recover_process
242
- else
243
- @log.error("asyncev_start_recover_process:argument error #{args.inspect}")
244
- end
236
+ acquired_recover_process
245
237
  rescue => e
246
- @log.error("asyncev_start_recover_process:#{e.inspect} #{$@}")
238
+ @log.error("#{__method__}:#{e.inspect} #{$@}")
239
+ ensure
240
+ @stats.run_recover = false
247
241
  end
248
- @stats.run_recover = false
249
- }
242
+ end
250
243
  t[:name] = __method__
251
244
  end
252
245
 
253
246
  def asyncev_start_release_process(args)
254
- @log.debug("asyncev_start_release_process #{args}")
255
- @stats.run_release = true
256
- t = Thread::new{
257
- begin
258
- release_process
259
- rescue => e
260
- @log.error("asyncev_start_release_process:#{e.inspect} #{$@}")
261
- end
262
- @stats.run_release = false
263
- }
264
- t[:name] = __method__
265
- end
266
-
267
- def asyncev_start_sync_process(args)
268
- @log.debug("asyncev_start_sync_process")
269
- @stats.run_recover = true
270
- t = Thread::new{
271
- sync_process(args)
272
- @stats.run_recover = false
273
- }
274
- t[:name] = __method__
275
- end
276
-
277
- def sync_process(st)
278
- own_nid = @stats.ap_str
279
- @do_sync_process = true
280
- @rttable.each_vnode{ |vn, nids|
281
- break unless @do_sync_process
282
- # my process charges of the primary node
283
- if nids[0] == own_nid
284
- nids[1..-1].each{ |nid|
285
- unless sync_a_vnode(vn, nid)
286
- @log.warn("sync_process:error at vn=#{vn} nid=#{nid}")
287
- end
288
- }
247
+ @log.debug("#{__method__} #{args}")
248
+ if @stats.run_iterate_storage
249
+ @log.warn("#{__method__}:already be iterated storage process.")
250
+ else
251
+ @stats.run_release = true
252
+ @stats.run_iterate_storage = true
253
+ @stats.spushv_protection = true
254
+ t = Thread::new do
255
+ begin
256
+ release_process
257
+ rescue => e
258
+ @log.error("#{__method__}:#{e.inspect} #{$@}")
259
+ ensure
260
+ @stats.run_iterate_storage = false
261
+ @stats.run_release = false
262
+ end
289
263
  end
290
- }
291
- @log.info("Sync process has done.")
292
- rescue =>e
293
- @log.error("#{e.inspect} #{$@}")
294
- ensure
295
- @do_sync_process = false
296
- Roma::Messaging::ConPool.instance.close_all
264
+ t[:name] = __method__
265
+ end
297
266
  end
298
267
 
299
268
  def acquired_recover_process
300
- @log.info("acquired_recover_process:start")
301
- exclude_nodes = @rttable.nodes
302
-
303
- if @stats.enabled_repetition_host_in_routing
304
- exclude_nodes = [@stats.ap_str]
305
- else
306
- myhost = @stats.ap_str.split(/[:_]/)[0]
307
- exclude_nodes.delete_if{|nid| nid.split(/[:_]/)[0] != myhost }
308
- end
269
+ @log.info("#{__method__}:start")
270
+
271
+ exclude_nodes = @rttable.exclude_nodes_for_recover(@stats.ap_str, @stats.rep_host)
309
272
 
310
273
  @do_acquired_recover_process = true
311
- loop {
274
+ loop do
312
275
  break unless @do_acquired_recover_process
313
- vnodes = @rttable.select_a_short_vnodes(exclude_nodes)
314
- @log.info("acquired_recover_process:#{vnodes.length} short vnodes found.")
315
- break if vnodes.length == 0
316
- vn, nodes = vnodes[rand(vnodes.length)]
276
+
277
+ vn, nodes, is_primary = @rttable.select_vn_for_recover(exclude_nodes)
278
+ break unless vn
279
+
317
280
  if nodes.length != 0
318
- ret = req_push_a_vnode(vn, nodes[0], rand(@rttable.rn) == 0)
281
+ ret = req_push_a_vnode(vn, nodes[0], is_primary)
319
282
  if ret == :rejected
320
283
  sleep 1
321
284
  elsif ret == false
@@ -323,69 +286,84 @@ module Roma
323
286
  end
324
287
  sleep 1
325
288
  end
326
- }
327
- @log.info("acquired_recover_process has done.")
289
+ end
290
+ @log.info("#{__method__} has done.")
328
291
  rescue => e
329
292
  @log.error("#{e.inspect} #{$@}")
330
293
  ensure
331
294
  @do_acquired_recover_process = false
332
295
  end
333
296
 
334
- def acquire_vnodes_process
297
+ def join_process
298
+ @log.info("#{__method__}:start")
335
299
  count = 0
336
300
  nv = @rttable.v_idx.length
337
- @do_acquire_vnodes_process = true
301
+ exclude_nodes = @rttable.exclude_nodes_for_join(@stats.ap_str, @stats.rep_host)
302
+
303
+ @do_join_process = true
338
304
  while (@rttable.vnode_balance(@stats.ap_str) == :less && count < nv) do
339
- break unless @do_acquire_vnodes_process
340
- ret = acquire_vnode
305
+ break unless @do_join_process
306
+
307
+ vn, nodes, is_primary = @rttable.select_vn_for_join(exclude_nodes)
308
+ unless vn
309
+ @log.warn("#{__method__}:vnode dose not found")
310
+ return false
311
+ end
312
+ ret = req_push_a_vnode(vn, nodes[0], is_primary)
341
313
  if ret == :rejected
342
314
  sleep 5
343
- next
344
- elsif ret == false
345
- break
315
+ else
316
+ sleep 1
317
+ count += 1
346
318
  end
347
- sleep 1
348
- count += 1
349
319
  end
350
- @log.info("acquire_vnodes_prosess has done.")
320
+ @log.info("#{__method__} has done.")
351
321
  rescue => e
352
322
  @log.error("#{e.inspect} #{$@}")
353
323
  ensure
354
- @do_acquire_vnodes_process = false
324
+ @do_join_process = false
355
325
  end
356
-
357
- def acquire_vnode
358
- widthout_nodes = @rttable.nodes
359
-
360
- if @stats.enabled_repetition_host_in_routing
361
- widthout_nodes = [@stats.ap_str]
362
- else
363
- myhost = @stats.ap_str.split(/[:_]/)[0]
364
- widthout_nodes.delete_if{|nid| nid.split(/[:_]/)[0] != myhost }
365
- end
366
326
 
367
- vn, nodes = @rttable.sample_vnode(widthout_nodes)
368
- unless vn
369
- @log.warn("acquire_vnode:sample_vnode dose not found")
370
- return false
327
+ def balance_process
328
+ @log.info("#{__method__}:start")
329
+ count = 0
330
+ nv = @rttable.v_idx.length
331
+ exclude_nodes = @rttable.exclude_nodes_for_balance(@stats.ap_str, @stats.rep_host)
332
+
333
+ @do_balance_process = true
334
+ while (@rttable.vnode_balance(@stats.ap_str) == :less && count < nv) do
335
+ break unless @do_balance_process
336
+
337
+ vn, nodes, is_primary = @rttable.select_vn_for_balance(exclude_nodes)
338
+ unless vn
339
+ @log.warn("#{__method__}:vnode dose not found")
340
+ return false
341
+ end
342
+ ret = req_push_a_vnode(vn, nodes[0], is_primary)
343
+ if ret == :rejected
344
+ sleep 5
345
+ else
346
+ sleep 1
347
+ count += 1
348
+ end
371
349
  end
372
- #
373
- # tunning point
374
- # sleep 0.1
375
- #
376
- req_push_a_vnode(vn, nodes[0], rand(@rttable.rn) == 0)
350
+ @log.info("#{__method__} has done.")
351
+ rescue => e
352
+ @log.error("#{e.inspect} #{$@}")
353
+ ensure
354
+ @do_balance_process = false
377
355
  end
378
-
356
+
379
357
  def req_push_a_vnode(vn, src_nid, is_primary)
380
358
  con = Roma::Messaging::ConPool.instance.get_connection(src_nid)
381
359
  con.write("reqpushv #{vn} #{@stats.ap_str} #{is_primary}\r\n")
382
360
  res = con.gets # receive 'PUSHED\r\n' | 'REJECTED\r\n' | 'ERROR\r\n'
383
361
  if res == "REJECTED\r\n"
384
- @log.warn("req_push_a_vnode:request was rejected from #{src_nid}.")
362
+ @log.warn("#{__method__}:request was rejected from #{src_nid}.")
385
363
  Roma::Messaging::ConPool.instance.return_connection(src_nid,con)
386
364
  return :rejected
387
- elsif res.start_with?("ERROR")
388
- @log.warn("req_push_a_vnode:#{src_nid} busy.")
365
+ elsif res != "PUSHED\r\n"
366
+ @log.warn("#{__method__}:#{res}")
389
367
  return :rejected
390
368
  end
391
369
  Roma::Messaging::ConPool.instance.return_connection(src_nid,con)
@@ -396,95 +374,39 @@ module Roma
396
374
  count += 1
397
375
  end
398
376
  if count >= 300
399
- @log.warn("req_push_a_vnode:request has been time-out.vn=#{vn} nid=#{src_nid}")
377
+ @log.warn("#{__method__}:request has been time-out.vn=#{vn} nid=#{src_nid}")
400
378
  return :timeout
401
379
  end
402
380
  true
403
381
  rescue =>e
404
- @log.error("req_push_a_vnode:#{e.inspect} #{$@}")
382
+ @log.error("#{__method__}:#{e.inspect} #{$@}")
405
383
  @rttable.proc_failed(src_nid)
406
384
  false
407
385
  end
408
386
 
409
- def recover_process
410
- @log.info("recover_process:start.")
411
- nodes = @rttable.nodes
412
-
413
- unless @stats.enabled_repetition_host_in_routing
414
- host = @stats.ap_str.split(/[:_]/)[0]
415
- nodes.delete_if{|nid| nid.split(/[:_]/)[0] == host }
416
- else
417
- nodes.delete(@stats.ap_str)
418
- end
419
-
420
- if nodes.length == 0
421
- @log.error("New redundant node dose not found.")
422
- return
423
- end
424
-
425
- @do_recover_process = true
426
- @rttable.each_vnode{ |vn, nids|
427
- break unless @do_recover_process
428
- # my process charges of a primary node and it's short of redundant
429
- if nids[0] == @stats.ap_str && nids.length < @rttable.rn
430
- unless sync_a_vnode(vn, nodes[rand(nodes.length)])
431
- @log.warn("recover_process:error at hname=#{hname} vn=#{vn}")
432
- end
433
- end
434
- }
435
- @log.info("Recover process has done.")
436
- rescue =>e
437
- @log.error("#{e}\n#{$@}")
438
- ensure
439
- @do_recover_process = false
440
- Roma::Messaging::ConPool.instance.close_all
441
- end
442
-
443
387
  def release_process
444
- @log.info("release_process:start.")
445
- nodes = @rttable.nodes
446
- nodes.delete(@stats.ap_str)
447
- hosts = []
448
-
449
- unless @stats.enabled_repetition_host_in_routing
450
- nodes.each{ |node|
451
- host = node.split(/[:_]/)[0]
452
- hosts << host unless hosts.include?(host)
453
- }
454
- else
455
- hosts = nodes
456
- end
457
-
458
- if hosts.length < @rttable.rn
459
- @log.error("Sufficient nodes do not found.")
388
+ @log.info("#{__method__}:start.")
389
+
390
+ if @rttable.can_i_release?(@stats.ap_str, @stats.rep_host)
391
+ @log.error("#{__method__}:Sufficient nodes do not found.")
460
392
  return
461
393
  end
462
394
 
463
395
  @do_release_process = true
464
- @rttable.each_vnode{ |vn, nids|
465
- break unless @do_release_process
466
- if nids.include?(@stats.ap_str)
467
- buf = nodes.clone
468
-
469
- unless @stats.enabled_repetition_host_in_routing
470
- deny_hosts = []
471
- nids.each{ |nid|
472
- host = nid.split(/[:_]/)[0]
473
- deny_hosts << host if host != @stats.ap_str.split(/[:_]/)[0]
474
- }
475
- buf.delete_if{|nid| deny_hosts.include?(nid.split(/[:_]/)[0])}
476
- else
477
- nids.each{|nid| buf.delete(nid) }
478
- end
479
-
480
- new_nid = buf[rand(buf.length)]
481
- new_nids = nids.map{|n| n == @stats.ap_str ? new_nid : n }
482
- unless sync_a_vnode_for_release(vn, new_nid, new_nids)
483
- @log.warn("release_process:error at hname=#{hname} vn=#{vn}")
396
+ while(@rttable.has_node?(@stats.ap_str)) do
397
+ @rttable.each_vnode do |vn, nids|
398
+ break unless @do_release_process
399
+ if nids.include?(@stats.ap_str)
400
+
401
+ to_nid, new_nids = @rttable.select_node_for_release(@stats.ap_str, @stats.rep_host, nids)
402
+ unless sync_a_vnode_for_release(vn, to_nid, new_nids)
403
+ @log.warn("#{__method__}:error at vn=#{vn} to_nid=#{to_nid} new_nid=#{new_nids}")
404
+ redo
405
+ end
484
406
  end
485
407
  end
486
- }
487
- @log.info("Release process has done.")
408
+ end
409
+ @log.info("#{__method__} has done.")
488
410
  rescue =>e
489
411
  @log.error("#{e}\n#{$@}")
490
412
  ensure
@@ -493,14 +415,10 @@ module Roma
493
415
  end
494
416
 
495
417
  def sync_a_vnode_for_release(vn, to_nid, new_nids)
496
- if @stats.run_iterate_storage == true
497
- @log.warn("sync_a_vnode:already in being.#{vn} #{to_nid}")
498
- return false
499
- end
500
418
  nids = @rttable.search_nodes(vn)
501
419
 
502
420
  if nids.include?(to_nid)==false || (is_primary && nids[0]!=to_nid)
503
- @log.debug("sync_a_vnode_for_release:#{vn} #{to_nid}")
421
+ @log.debug("#{__method__}:#{vn} #{to_nid}")
504
422
  # change routing data at the vnode and synchronize a data
505
423
  nids << to_nid
506
424
  return false unless @rttable.transaction(vn, nids)
@@ -511,14 +429,14 @@ module Roma
511
429
 
512
430
  if res != "STORED"
513
431
  @rttable.rollback(vn)
514
- @log.error("push_a_vnode was failed:hname=#{hname} vn=#{vn}:#{res}")
432
+ @log.error("#{__method__}:push_a_vnode was failed:hname=#{hname} vn=#{vn}:#{res}")
515
433
  return false
516
434
  end
517
435
  }
518
436
 
519
437
  if (clk = @rttable.commit(vn)) == false
520
438
  @rttable.rollback(vn)
521
- @log.error("sync_a_vnode:routing table commit failed")
439
+ @log.error("#{__method__}:routing table commit failed")
522
440
  return false
523
441
  end
524
442
 
@@ -530,7 +448,7 @@ module Roma
530
448
  cmd = "setroute #{vn} #{clk - 1}"
531
449
  new_nids.each{ |nn| cmd << " #{nn}"}
532
450
  res = async_broadcast_cmd("#{cmd}\r\n")
533
- @log.debug("async_a_vnode_for_release:async_broadcast_cmd(#{cmd}) #{res}")
451
+ @log.debug("#{__method__}:async_broadcast_cmd(#{cmd}) #{res}")
534
452
  end
535
453
 
536
454
  return true
@@ -540,14 +458,10 @@ module Roma
540
458
  end
541
459
 
542
460
  def sync_a_vnode(vn, to_nid, is_primary=nil)
543
- if @stats.run_iterate_storage == true
544
- @log.warn("sync_a_vnode:already in being.#{vn} #{to_nid} #{is_primary}")
545
- return false
546
- end
547
461
  nids = @rttable.search_nodes(vn)
548
462
 
549
463
  if nids.include?(to_nid)==false || (is_primary && nids[0]!=to_nid)
550
- @log.debug("sync_a_vnode:#{vn} #{to_nid} #{is_primary}")
464
+ @log.debug("#{__method__}:#{vn} #{to_nid} #{is_primary}")
551
465
  # change routing data at the vnode and synchronize a data
552
466
  nids << to_nid
553
467
  return false unless @rttable.transaction(vn, nids)
@@ -558,14 +472,14 @@ module Roma
558
472
 
559
473
  if res != "STORED"
560
474
  @rttable.rollback(vn)
561
- @log.error("push_a_vnode was failed:hname=#{hname} vn=#{vn}:#{res}")
475
+ @log.error("#{__method__}:push_a_vnode was failed:hname=#{hname} vn=#{vn}:#{res}")
562
476
  return false
563
477
  end
564
478
  }
565
479
 
566
480
  if (clk = @rttable.commit(vn)) == false
567
481
  @rttable.rollback(vn)
568
- @log.error("sync_a_vnode:routing table commit failed")
482
+ @log.error("#{__method__}:routing table commit failed")
569
483
  return false
570
484
  end
571
485
 
@@ -578,13 +492,13 @@ module Roma
578
492
  cmd = "setroute #{vn} #{clk - 1}"
579
493
  nids.each{ |nn| cmd << " #{nn}"}
580
494
  res = async_broadcast_cmd("#{cmd}\r\n")
581
- @log.debug("sync_a_vnode:async_broadcast_cmd(#{cmd}) #{res}")
495
+ @log.debug("#{__method__}:async_broadcast_cmd(#{cmd}) #{res}")
582
496
  else
583
497
  # synchronize a data
584
498
  @storages.each_key{ |hname|
585
499
  res = push_a_vnode_stream(hname, vn, to_nid)
586
500
  if res != "STORED"
587
- @log.error("push_a_vnode was failed:hname=#{hname} vn=#{vn}:#{res}")
501
+ @log.error("#{__method__}:push_a_vnode was failed:hname=#{hname} vn=#{vn}:#{res}")
588
502
  return false
589
503
  end
590
504
  }
@@ -612,54 +526,15 @@ module Roma
612
526
  nodes
613
527
  end
614
528
 
615
- def push_a_vnode(hname, vn, nid)
616
- dmp = @storages[hname].dump(vn)
617
- unless dmp
618
- @log.info("hname=#{hname} vn=#{vn} has a empty data.")
619
- return "STORED"
620
- end
621
- con = Roma::Messaging::ConPool.instance.get_connection(nid)
622
-
623
- con.write("pushv #{hname} #{vn}\r\n")
624
- res = con.gets # READY\r\n or error string
625
- if res != "READY\r\n"
626
- con.close
627
- return res.chomp
628
- end
629
- con.write("#{dmp.length}\r\n#{dmp}\r\nEND\r\n")
630
- res = con.gets # STORED\r\n or error string
631
-
632
- Roma::Messaging::ConPool.instance.return_connection(nid,con)
633
- res.chomp! if res
634
- res
635
- rescue Errno::EPIPE
636
- @log.debug("Errno::EPIPE retry")
637
- retry
638
- rescue =>e
639
- @log.error("#{e.inspect}\n#{$@}")
640
- "#{e}"
641
- end
642
-
643
529
  def push_a_vnode_stream(hname, vn, nid)
644
- @stats.run_iterate_storage = true
645
530
  @log.info("#{__method__}:hname=#{hname} vn=#{vn} nid=#{nid}")
646
531
 
647
- while(@stats.run_storage_clean_up)
648
- @log.info("#{__method__}:stop clean up storage process")
649
- @storages.each_value{|st| st.stop_clean_up}
650
- sleep 0.1
651
- end
532
+ stop_clean_up
652
533
 
653
534
  con = Roma::Messaging::ConPool.instance.get_connection(nid)
654
535
 
655
536
  @do_push_a_vnode_stream = true
656
537
 
657
- while(@stats.run_storage_clean_up)
658
- @log.info("#{__method__}:stop_clean_up")
659
- @storages.each_value{|st| st.stop_clean_up}
660
- sleep 0.5
661
- end
662
-
663
538
  con.write("spushv #{hname} #{vn}\r\n")
664
539
 
665
540
  res = con.gets # READY\r\n or error string
@@ -676,7 +551,6 @@ module Roma
676
551
  return "CANCELED"
677
552
  end
678
553
 
679
- @stats.run_iterate_storage = true
680
554
  con.write(data)
681
555
  sleep @stats.stream_copy_wait_param
682
556
  }
@@ -689,8 +563,6 @@ module Roma
689
563
  rescue =>e
690
564
  @log.error("#{e}\n#{$@}")
691
565
  e.to_s
692
- ensure
693
- @stats.run_iterate_storage = false
694
566
  end
695
567
 
696
568
 
@@ -707,6 +579,7 @@ module Roma
707
579
  rescue =>e
708
580
  @log.error("#{__method__}:#{e.inspect} #{$@}")
709
581
  ensure
582
+ @stats.last_clean_up = Time.now
710
583
  @stats.run_storage_clean_up = false
711
584
  end
712
585
  }
@@ -714,10 +587,10 @@ module Roma
714
587
  end
715
588
 
716
589
  def storage_clean_up_process
717
- # @log.info("#{__method__}:start")
590
+ @log.info("#{__method__}:start")
718
591
  me = @stats.ap_str
719
592
  vnhash={}
720
- @rttable.each_vnode{|vn, nids|
593
+ @rttable.each_vnode do |vn, nids|
721
594
  if nids.include?(me)
722
595
  if nids[0] == me
723
596
  vnhash[vn] = :primary
@@ -725,28 +598,37 @@ module Roma
725
598
  vnhash[vn] = :secondary
726
599
  end
727
600
  end
728
- }
601
+ end
729
602
  t = Time.now.to_i - Roma::Config::STORAGE_DELMARK_EXPTIME
730
603
  count = 0
731
- @storages.each_pair{|hname,st|
732
- st.each_clean_up(t, vnhash){|key, vn|
733
- count += 1
734
- @stats.out_count += 1
735
- # @log.debug("#{__method__}:key=#{key} vn=#{vn}")
736
- nodes = @rttable.search_nodes_for_write(vn)
737
- next if(nodes == nil || nodes.length <= 1)
738
- nodes[1..-1].each{|nid|
739
- res = async_send_cmd(nid,"out #{key}\e#{hname} #{vn}\r\n")
740
- unless res
741
- @log.warn("send out command failed:#{key}\e#{hname} #{vn} -> #{nid}")
604
+ @storages.each_pair do |hname,st|
605
+ break unless @stats.do_clean_up?
606
+ st.each_clean_up(t, vnhash) do |key, vn|
607
+ # @log.debug("#{__method__}:key=#{key} vn=#{vn}")
608
+ if @stats.run_receive_a_vnode.key?("#{hname}_#{vn}")
609
+ false
610
+ else
611
+ nodes = @rttable.search_nodes_for_write(vn)
612
+ if nodes && nodes.length > 1
613
+ nodes[1..-1].each do |nid|
614
+ res = async_send_cmd(nid,"out #{key}\e#{hname} #{vn}\r\n")
615
+ unless res
616
+ @log.warn("send out command failed:#{key}\e#{hname} #{vn} -> #{nid}")
617
+ end
618
+ # @log.debug("#{__method__}:res=#{res}")
619
+ end
742
620
  end
743
- # @log.debug("#{__method__}:res=#{res}")
744
- }
745
- }
746
- }
621
+ count += 1
622
+ @stats.out_count += 1
623
+ true
624
+ end
625
+ end
626
+ end
747
627
  if count>0
748
628
  @log.info("#{__method__}:#{count} keys deleted.")
749
629
  end
630
+ ensure
631
+ @log.info("#{__method__}:stop")
750
632
  end
751
633
 
752
634