roma 0.8.12 → 0.8.13p1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGELOG +34 -1
  2. data/Gemfile +17 -0
  3. data/Rakefile +2 -3
  4. data/ruby/server/lib/roma/async_process.rb +158 -20
  5. data/ruby/server/lib/roma/command/bg_command_receiver.rb +3 -4
  6. data/ruby/server/lib/roma/command/rt_command_receiver.rb +133 -5
  7. data/ruby/server/lib/roma/command/sys_command_receiver.rb +353 -0
  8. data/ruby/server/lib/roma/command/vn_command_receiver.rb +9 -3
  9. data/ruby/server/lib/roma/config.rb +6 -0
  10. data/ruby/server/lib/roma/dns_cache.rb +40 -0
  11. data/ruby/server/lib/roma/event/con_pool.rb +3 -1
  12. data/ruby/server/lib/roma/event/handler.rb +18 -3
  13. data/ruby/server/lib/roma/messaging/con_pool.rb +3 -1
  14. data/ruby/server/lib/roma/romad.rb +19 -3
  15. data/ruby/server/lib/roma/routing/cb_rttable.rb +22 -1
  16. data/ruby/server/lib/roma/routing/random_balancer.rb +76 -0
  17. data/ruby/server/lib/roma/routing/routing_data.rb +16 -2
  18. data/ruby/server/lib/roma/routing/rttable.rb +55 -8
  19. data/ruby/server/lib/roma/stats.rb +32 -0
  20. data/ruby/server/lib/roma/storage/sqlite3_storage.rb +9 -3
  21. data/ruby/server/lib/roma/tools/mkconfig.rb +135 -73
  22. data/ruby/server/lib/roma/tools/mkrecent.rb +3 -4
  23. data/ruby/server/lib/roma/tools/mkroute.rb +6 -7
  24. data/ruby/server/lib/roma/tools/multi_commander.rb +3 -4
  25. data/ruby/server/lib/roma/tools/recoverlost.rb +0 -1
  26. data/ruby/server/lib/roma/tools/recoverlost_alist.rb +0 -1
  27. data/ruby/server/lib/roma/tools/recoverlost_lib.rb +10 -11
  28. data/ruby/server/lib/roma/tools/roma_watcher.rb +0 -1
  29. data/ruby/server/lib/roma/tools/sample_watcher.rb +3 -4
  30. data/ruby/server/lib/roma/tools/sample_watcher2.rb +3 -4
  31. data/ruby/server/lib/roma/tools/sample_watcher3.rb +0 -1
  32. data/ruby/server/lib/roma/tools/simple_bench.rb +3 -3
  33. data/ruby/server/lib/roma/tools/simple_bench2.rb +1 -2
  34. data/ruby/server/lib/roma/tools/ssroute.rb +0 -1
  35. data/ruby/server/lib/roma/tools/tribunus.rb +5 -6
  36. data/ruby/server/lib/roma/version.rb +1 -1
  37. data/ruby/server/lib/roma/write_behind.rb +4 -1
  38. data/ruby/server/test/rcirb.rb +0 -1
  39. data/ruby/server/test/t_cpdata.rb +8 -9
  40. data/ruby/server/test/t_rclient.rb +1 -2
  41. data/ruby/server/test/t_routing_data.rb +13 -14
  42. data/ruby/server/test/t_storage.rb +1 -1
  43. data/ruby/server/test/t_writebehind.rb +29 -30
  44. metadata +25 -24
@@ -19,6 +19,7 @@ module Roma
19
19
  end
20
20
  @rttable.enabled_failover = false
21
21
  res = broadcast_cmd("rbalse\r\n")
22
+ res[@stats.ap_str] = "BYE"
22
23
  send_data("#{res.inspect}\r\n")
23
24
  close_connection_after_writing
24
25
  @stop_event_loop = true
@@ -84,6 +85,7 @@ module Roma
84
85
  send_stat_result(nil,$roma.wb_get_stat,regexp)
85
86
  send_stat_result(nil,@rttable.get_stat(@stats.ap_str),regexp)
86
87
  send_stat_result(nil,conn_get_stat,regexp)
88
+ send_stat_result(nil,DNSCache.instance.get_stat,regexp)
87
89
  send_data("END\r\n")
88
90
  end
89
91
 
@@ -366,6 +368,244 @@ module Roma
366
368
  end
367
369
  end
368
370
 
371
+ def ev_set_descriptor_table_size(s)
372
+ if s.length != 2
373
+ return send_data("CLIENT_ERROR number of arguments\r\n")
374
+ elsif s[1].to_i < 1024
375
+ return send_data("CLIENT_ERROR length must be greater than 1024\r\n")
376
+ end
377
+
378
+ res = broadcast_cmd("rset_descriptor_table_size #{s[1]}\r\n")
379
+
380
+ EM.set_descriptor_table_size(s[1].to_i)
381
+ res[@stats.ap_str] = "STORED"
382
+ send_data("#{res}\r\n")
383
+ end
384
+
385
+ def ev_rset_descriptor_table_size(s)
386
+ if s.length != 2
387
+ return send_data("CLIENT_ERROR number of arguments\r\n")
388
+ elsif s[1].to_i < 1024
389
+ return send_data("CLIENT_ERROR length must be greater than 1024\r\n")
390
+ end
391
+
392
+ EM.set_descriptor_table_size(s[1].to_i)
393
+ send_data("STORED\r\n")
394
+ end
395
+
396
+ # set_latency_avg_calc_rule <mode> <count> <command1> <command2>....
397
+ # <mode> is on/off
398
+ # <count> is denominator to calculate average.
399
+ # <commandx> is target command
400
+ def ev_set_latency_avg_calc_rule(s)
401
+ #check argument
402
+ if /^on$|^off$/ !~ s[1]
403
+ return send_data("CLIENT_ERROR argument 1: please input \"on\" or \"off\"\r\n")
404
+ elsif s[1] == "on" && (s.length <= 3 || s[2].to_i < 1)
405
+ return send_data("CLIENT_ERROR number of arguments (0 for 3) and <count> must be greater than zero\r\n")
406
+ elsif s[1] == "off" && !(s.length == 2)
407
+ return send_data("CLIENT_ERROR number of arguments (0 for 1, or more 3)\r\n")
408
+ end
409
+
410
+ #check support commands
411
+ s.each_index {|idx|
412
+ if idx >= 3 && (!Event::Handler::ev_list.include?(s[idx]) || Event::Handler::system_commands.include?(s[idx]))
413
+ return send_data("NOT SUPPORT [#{s[idx]}] command\r\n")
414
+ end
415
+ }
416
+
417
+ arg ="rset_latency_avg_calc_rule"
418
+ s.each_index {|idx|
419
+ arg += " #{s[idx]}" if idx>=1
420
+ }
421
+ res = broadcast_cmd("#{arg}\r\n")
422
+
423
+ if s[1] =="on"
424
+ @stats.latency_check_cmd = [] #reset
425
+ s.each_index {|idx|
426
+ @stats.latency_check_cmd.push(s[idx]) if idx >= 3
427
+ }
428
+ @stats.latency_check_time_count = s[2].to_i
429
+ @stats.latency_log = true
430
+ res[@stats.ap_str] = "ACTIVATED"
431
+ elsif s[1] =="off"
432
+ @stats.latency_check_cmd = [] #reset
433
+ @stats.latency_check_time_count = nil
434
+ @stats.latency_log = false
435
+ res[@stats.ap_str] = "DEACTIVATED"
436
+ end
437
+ @stats.latency_data = Hash.new { |hash,key| hash[key] = {}}
438
+ send_data("#{res}\r\n")
439
+ end
440
+
441
+ def ev_rset_latency_avg_calc_rule(s)
442
+ if /^on$|^off$/ !~ s[1]
443
+ return send_data("CLIENT_ERROR argument 1: please input \"on\" or \"off\"\r\n")
444
+ elsif s[1] == "on" && (s.length <= 3 || s[2].to_i < 1)
445
+ return send_data("CLIENT_ERROR number of arguments (0 for 3) and <count> must be greater than zero\r\n")
446
+ elsif s[1] == "off" && !(s.length == 2)
447
+ return send_data("CLIENT_ERROR number of arguments (0 for 1, or more 3)\r\n")
448
+ end
449
+
450
+ s.each_index {|idx|
451
+ if idx >= 3 && (!Event::Handler::ev_list.include?(s[idx]) || Event::Handler::system_commands.include?(s[idx]))
452
+ return send_data("NOT SUPPORT [#{s[idx]}] command\r\n")
453
+ end
454
+ }
455
+
456
+ if s[1] =="on"
457
+ @latency_data = Hash.new { |hash,key| hash[key] = {}}
458
+ @stats.latency_check_cmd = []
459
+ s.each_index {|idx|
460
+ @stats.latency_check_cmd.push(s[idx]) if idx >= 3
461
+ }
462
+ @stats.latency_check_time_count = s[1].to_i
463
+ @stats.latency_log = true
464
+ send_data("ACTIVATED\r\n")
465
+ elsif s[1] =="off"
466
+ @latency_data = Hash.new { |hash,key| hash[key] = {}}
467
+ @stats.latency_check_cmd = []
468
+ @stats.latency_check_time_count = nil
469
+ @stats.latency_log = false
470
+ send_data("DEACTIVATED\r\n")
471
+ end
472
+ end
473
+
474
+ # add_calc_latency_average <command1> <command2>....
475
+ def ev_add_latency_avg_calc_cmd(s)
476
+ #check argument
477
+ if s.length < 2
478
+ return send_data("CLIENT_ERROR number of arguments (0 for 2)\r\n")
479
+ end
480
+ #check support commands
481
+ s.each_index {|idx|
482
+ if idx >= 1 && (!Event::Handler::ev_list.include?(s[idx]) || Event::Handler::system_commands.include?(s[idx]))
483
+ return send_data("NOT SUPPORT [#{s[idx]}] command\r\n")
484
+ end
485
+ if idx >= 1 && @stats.latency_check_cmd.include?(s[idx])
486
+ return send_data("ALREADY SET [#{s[idx]}] command\r\n")
487
+ end
488
+ }
489
+
490
+ arg ="radd_latency_avg_calc_cmd"
491
+ s.each_index {|idx|
492
+ arg += " #{s[idx]}" if idx>=1
493
+ }
494
+ res = broadcast_cmd("#{arg}\r\n")
495
+
496
+ s.each_index {|idx|
497
+ @stats.latency_check_cmd.push(s[idx]) if idx >= 1
498
+ }
499
+ res[@stats.ap_str] = "SET"
500
+ send_data("#{res}\r\n")
501
+ end
502
+
503
+ def ev_radd_latency_avg_calc_cmd(s)
504
+ if s.length < 2
505
+ return send_data("CLIENT_ERROR number of arguments (0 for 2)\r\n")
506
+ end
507
+ s.each_index {|idx|
508
+ if idx >= 2 && (!Event::Handler::ev_list.include?(s[idx]) || Event::Handler::system_commands.include?(s[idx]))
509
+ return send_data("NOT SUPPORT [#{s[idx]}] command\r\n")
510
+ end
511
+ if idx >= 1 && @stats.latency_check_cmd.include?(s[idx])
512
+ return send_data("ALREADY SET [#{s[idx]}] command\r\n")
513
+ end
514
+ }
515
+
516
+ s.each_index {|idx|
517
+ @stats.latency_check_cmd.push(s[idx]) if idx >= 1
518
+ }
519
+ send_data("SET\r\n")
520
+ end
521
+
522
+ # del_calc_latency_average <command1> <command2>....
523
+ def ev_del_latency_avg_calc_cmd(s)
524
+ #check argument
525
+ if s.length < 2
526
+ return send_data("CLIENT_ERROR number of arguments (0 for 2)\r\n")
527
+ end
528
+
529
+ #check support commands
530
+ s.each_index {|idx|
531
+ if idx >= 1 && !@stats.latency_check_cmd.include?(s[idx])
532
+ return send_data("[#{s[idx]}] command is NOT set\r\n")
533
+ end
534
+ }
535
+
536
+ arg ="rdel_latency_avg_calc_cmd"
537
+ s.each_index {|idx|
538
+ arg += " #{s[idx]}" if idx>=1
539
+ }
540
+ res = broadcast_cmd("#{arg}\r\n")
541
+
542
+ s.each_index {|idx|
543
+ @stats.latency_check_cmd.delete(s[idx]) if idx >= 1
544
+ @stats.latency_data.delete(s[idx]) if idx >= 1
545
+ }
546
+ res[@stats.ap_str] = "DELETED"
547
+ send_data("#{res}\r\n")
548
+ end
549
+
550
+ def ev_rdel_latency_avg_calc_cmd(s)
551
+ if s.length < 2
552
+ return send_data("CLIENT_ERROR number of arguments (0 for 2)\r\n")
553
+ end
554
+
555
+ # reset
556
+ s.each_index {|idx|
557
+ if idx >= 1 && !@stats.latency_check_cmd.include?(s[idx])
558
+ return send_data("[#{s[idx]}] command is NOT set\r\n")
559
+ end
560
+ }
561
+ s.each_index {|idx|
562
+ @stats.latency_check_cmd.delete(s[idx]) if idx >= 1
563
+ @stats.latency_data.delete(s[idx]) if idx >= 1
564
+ }
565
+ send_data("DELETED\r\n")
566
+ end
567
+
568
+ # chg_calc_latency_average_denominator <count>
569
+ def ev_chg_latency_avg_calc_time_count(s)
570
+ #check argument
571
+ if s.length != 2
572
+ return send_data("CLIENT_ERROR number of arguments (0 for 2)\r\n")
573
+ elsif s[1] != "nil" && s[1].to_i < 1
574
+ return send_data("s[1].class = #{s[1].class}\r\n")
575
+ return send_data("<count> must be greater than zero or nil[DEACTIVATE]\r\n")
576
+ end
577
+
578
+ res = broadcast_cmd("rchg_latency_avg_calc_time_count #{s[1]}\r\n")
579
+
580
+ if s[1] != "nil"
581
+ @stats.latency_check_time_count = s[1].to_i
582
+ @stats.latency_log = true
583
+ elsif s[1] == "nil"
584
+ @stats.latency_check_time_count = nil
585
+ @stats.latency_log = false
586
+ end
587
+ res[@stats.ap_str] = "CHANGED"
588
+ send_data("#{res}\r\n")
589
+ end
590
+
591
+ def ev_rchg_latency_avg_calc_time_count(s)
592
+ if s.length != 2
593
+ return send_data("CLIENT_ERROR number of arguments (0 for 2)\r\n")
594
+ elsif s[1] != "nil" && s[1].to_i < 1
595
+ return send_data("<count> must be greater than zero\r\n")
596
+ end
597
+
598
+ if s[1] != "nil"
599
+ @stats.latency_check_time_count = s[1].to_i
600
+ @stats.latency_log = true
601
+ elsif s[1] == "nil"
602
+ @stats.latency_check_time_count = nil
603
+ @stats.latency_log = false
604
+ end
605
+ @stats.latency_check_time_count = s[1].to_i
606
+ send_data("CHANGED\r\n")
607
+ end
608
+
369
609
  def ev_set_continuous_limit(s)
370
610
  if s.length < 2
371
611
  return send_data("CLIENT_ERROR number of arguments (0 for 1)\r\n")
@@ -472,6 +712,94 @@ module Roma
472
712
  send_data("STORED\r\n")
473
713
  end
474
714
 
715
+ # set_connection_pool_expire_time <sec>
716
+ # set to expired time(sec) for connection_pool expire time
717
+ def ev_set_connection_pool_expire_time(s)
718
+ if s.length != 2
719
+ return send_data("CLIENT_ERROR number of arguments\r\n")
720
+ end
721
+
722
+ res = broadcast_cmd("rset_connection_pool_expire_time #{s[1]}\r\n")
723
+ Messaging::ConPool.instance.expire_time = s[1].to_i
724
+ res[@stats.ap_str] = "STORED"
725
+ send_data("#{res}\r\n")
726
+ end
727
+
728
+ # rset_connection_pool_expire_time <sec>
729
+ def ev_rset_connection_pool_expire_time(s)
730
+ if s.length != 2
731
+ return send_data("CLIENT_ERROR number of arguments\r\n")
732
+ end
733
+ Messaging::ConPool.instance.expire_time = s[1].to_i
734
+ send_data("STORED\r\n")
735
+ end
736
+
737
+ # set_emconnection_pool_expire_time <sec>
738
+ def ev_set_emconnection_pool_expire_time(s)
739
+ # chcking s incude command and value (NOT check digit)
740
+ if s.length != 2
741
+ return send_data("CLIENT_ERROR number of arguments\r\n")
742
+ end
743
+
744
+ #if ARGV is 0, expire time become infinity(NOT happen expire)
745
+ if s[1].to_i == 0
746
+ s[1] = "2147483647"
747
+ end
748
+ res = broadcast_cmd("rset_emconnection_pool_expire_time #{s[1]}\r\n")
749
+ Event::EMConPool::instance.expire_time = s[1].to_i
750
+ res[@stats.ap_str] = "STORED"
751
+ send_data("#{res}\r\n")
752
+ end
753
+
754
+ # rset_emconnection_pool_expire_time <sec>
755
+ def ev_rset_emconnection_pool_expire_time(s)
756
+ if s.length != 2
757
+ return send_data("CLIENT_ERROR number of arguments\r\n")
758
+ end
759
+ Event::EMConPool::instance.expire_time = s[1].to_i
760
+ send_data("STORED\r\n")
761
+ end
762
+
763
+ # switch_dns_caching <on|off|true|false>
764
+ def ev_switch_dns_caching(s)
765
+ if s.length != 2
766
+ return send_data("CLIENT_ERROR number of arguments\r\n")
767
+ end
768
+
769
+ res = broadcast_cmd("rswitch_dns_caching #{s[1]}\r\n")
770
+ if s[1] == 'on' || s[1] == 'true'
771
+ DNSCache.instance.enable_dns_cache
772
+ @log.info("DNS caching enabled")
773
+ res[@stats.ap_str] = "ENABLED"
774
+ elsif s[1] == 'off' || s[1] == 'false'
775
+ DNSCache.instance.disable_dns_cache
776
+ @log.info("DNS caching disabled")
777
+ res[@stats.ap_str] = "DISABLED"
778
+ else
779
+ res[@stats.ap_str] = "NOTSWITCHED"
780
+ end
781
+ send_data("#{res}\r\n")
782
+ end
783
+
784
+ # rswitch_dns_caching <on|off|true|false>
785
+ def ev_rswitch_dns_caching(s)
786
+ if s.length != 2
787
+ return send_data("CLIENT_ERROR number of arguments\r\n")
788
+ end
789
+
790
+ if s[1] == 'on' || s[1] == 'true'
791
+ DNSCache.instance.enable_dns_cache
792
+ @log.info("DNS caching enabled")
793
+ return send_data("ENABLED\r\n")
794
+ elsif s[1] == 'off' || s[1] == 'false'
795
+ DNSCache.instance.disable_dns_cache
796
+ @log.info("DNS caching disabled")
797
+ return send_data("DISABLED\r\n")
798
+ else
799
+ send_data("NOTSWITCHED\r\n")
800
+ end
801
+ end
802
+
475
803
  # set_hilatency_warn_time <sec>
476
804
  # set to threshold of warn message into a log when hilatency occured in a command.
477
805
  def ev_set_hilatency_warn_time(s)
@@ -542,6 +870,31 @@ module Roma
542
870
  end
543
871
  end
544
872
 
873
+ # set_wb_shift_size <size>
874
+ def ev_set_wb_shift_size(s)
875
+ if s.length != 2
876
+ return send_data("CLIENT_ERROR number of arguments\r\n")
877
+ elsif s[1].to_i < 1
878
+ return send_data("CLIENT_ERROR length must be greater than zero\r\n")
879
+ end
880
+
881
+ res = broadcast_cmd("rset_wb_shift_size #{s[1]}\r\n")
882
+ $roma.wb_writer.shift_size = s[1].to_i
883
+ res[@stats.ap_str] = "STORED"
884
+ send_data("#{res}\r\n")
885
+ end
886
+
887
+ def ev_rset_wb_shift_size(s)
888
+ if s.length != 2
889
+ return send_data("CLIENT_ERROR number of arguments\r\n")
890
+ elsif s[1].to_i < 1
891
+ return send_data("CLIENT_ERROR length must be greater than zero\r\n")
892
+ end
893
+
894
+ $roma.wb_writer.shift_size = s[1].to_i
895
+ send_data("STORED\r\n")
896
+ end
897
+
545
898
  private
546
899
 
547
900
  def dcnice(p)
@@ -45,14 +45,20 @@ module Roma
45
45
  count = rcount = 0
46
46
  @log.debug("#{__method__}:#{s.inspect} received.")
47
47
  loop {
48
- context_bin = read_bytes(20, 100)
48
+ context_bin = read_bytes(20, @stats.spushv_read_timeout)
49
49
  vn, last, clk, expt, klen = context_bin.unpack('NNNNN')
50
50
  break if klen == 0 # end of dump ?
51
51
  k = read_bytes(klen)
52
- vlen_bin = read_bytes(4, 100)
52
+ vlen_bin = read_bytes(4, @stats.spushv_read_timeout)
53
53
  vlen, = vlen_bin.unpack('N')
54
54
  if vlen != 0
55
- v = read_bytes(vlen, 100)
55
+ if klen > @stats.spushv_klength_warn
56
+ @log.warn("#{__method__}:Too long key: key = #{k}")
57
+ end
58
+ if vlen > @stats.spushv_vlength_warn
59
+ @log.warn("#{__method__}:Too long value: key = #{k} vlen = #{vlen}")
60
+ end
61
+ v = read_bytes(vlen, @stats.spushv_read_timeout)
56
62
 
57
63
  createhash(s[1]) unless @storages[s[1]]
58
64
  if @storages[s[1]].load_stream_dump(vn, last, clk, expt, k, v)
@@ -8,6 +8,8 @@ module Roma
8
8
 
9
9
  # :no_action | :auto_assign | :shutdown
10
10
  DEFAULT_LOST_ACTION = :auto_assign
11
+ # to use a auto recover function, AUTO_RECOVER is to set true
12
+ AUTO_RECOVER = false
11
13
 
12
14
  # failover setting
13
15
  # threshold of failover occurrence
@@ -50,6 +52,10 @@ module Roma
50
52
  # max length of the eventmachine's connection pool
51
53
  CONNECTION_EMPOOL_MAX = 15
52
54
 
55
+ # lookup hostname to the nameserver everytime or only first time.
56
+ # if set true, the result of lookup will keep.
57
+ DNS_CACHING = false
58
+
53
59
  # storage setting
54
60
  STORAGE_CLASS = Roma::Storage::RubyHashStorage
55
61
  STORAGE_DIVNUM = 10
@@ -0,0 +1,40 @@
1
+ require 'singleton'
2
+
3
+ module Roma
4
+ class DNSCache
5
+ include Singleton
6
+
7
+ def initialize
8
+ @@addrs = {}
9
+ @@enabled_caching = false
10
+ if Config.const_defined?(:DNS_CACHING)
11
+ @@enabled_caching = Config::DNS_CACHING
12
+ end
13
+ end
14
+
15
+ def resolve_name(host)
16
+ return host unless @@enabled_caching
17
+
18
+ unless @@addrs.include?(host)
19
+ res = TCPSocket.gethostbyname(host)
20
+ @@addrs[host] = res[3]
21
+ end
22
+ @@addrs[host]
23
+ end
24
+
25
+ def disable_dns_cache
26
+ @@enabled_caching = false
27
+ @@addrs.clear
28
+ end
29
+
30
+ def enable_dns_cache
31
+ @@enabled_caching = true
32
+ end
33
+
34
+ def get_stat
35
+ ret = {}
36
+ ret["dns_caching"] = @@enabled_caching
37
+ ret
38
+ end
39
+ end
40
+ end
@@ -4,6 +4,7 @@
4
4
  require 'singleton'
5
5
  require 'eventmachine'
6
6
  require 'roma/logging/rlogger'
7
+ require 'roma/dns_cache'
7
8
 
8
9
  module Roma
9
10
  module Event
@@ -114,7 +115,8 @@ module Roma
114
115
  end
115
116
 
116
117
  def create_connection(ap)
117
- addr,port = ap.split(/[:_]/)
118
+ host,port = ap.split(/[:_]/)
119
+ addr = DNSCache.instance.resolve_name(host)
118
120
  con = EventMachine::connect(addr, port, Roma::Event::EMConnection)
119
121
  con.ap = ap
120
122
  con
@@ -50,7 +50,15 @@ module Roma
50
50
  @@connection_expire_time
51
51
  end
52
52
 
53
- attr_accessor :timeout
53
+ @@timeout = 10
54
+ def self.timeout=(n)
55
+ @@timeout = n
56
+ end
57
+
58
+ def self.timeout
59
+ @@timeout
60
+ end
61
+
54
62
  attr_reader :connected
55
63
  attr_reader :lastcmd
56
64
  attr_reader :last_access
@@ -71,7 +79,6 @@ module Roma
71
79
 
72
80
  @storages = storages
73
81
  @rttable = rttable
74
- @timeout = 10
75
82
  @log = Roma::Logging::RLogger.instance
76
83
  @last_access = Time.now
77
84
  end
@@ -143,11 +150,13 @@ module Roma
143
150
 
144
151
  def dispatcher
145
152
  @stats = Roma::Stats.instance
153
+ #@log.debug("Roma::Event::Handler.dipatcher called")
146
154
  while(@connected) do
147
155
  @enter_time = nil
148
156
  next unless s=gets
149
157
  @enter_time = Time.now
150
158
  s=s.chomp.split(/ /)
159
+ # check whether comand was send or not? and check this command listed on ROMA?
151
160
  if s[0] && @@ev_list.key?(s[0].downcase)
152
161
  send(@@ev_list[s[0].downcase],s)
153
162
  @lastcmd=s
@@ -161,6 +170,7 @@ module Roma
161
170
  @log.warn("command error:#{s}")
162
171
  send_data("ERROR\r\n")
163
172
  close_connection_after_writing
173
+ next
164
174
  end
165
175
 
166
176
  # hilatency check
@@ -168,6 +178,10 @@ module Roma
168
178
  if ps > @stats.hilatency_warn_time
169
179
  @log.warn("hilatency occurred in #{@lastcmd} put in a #{ps} seconds")
170
180
  end
181
+ # check latency average
182
+ if @stats.latency_check_cmd.include?(@lastcmd[0])
183
+ Roma::AsyncProcess::queue_latency.push(Roma::AsyncMessage.new('calc_latency_average', [ps, @lastcmd[0]]))
184
+ end
171
185
 
172
186
  d = EM.connection_count - @@ccl_start
173
187
  if d > 0 &&
@@ -216,7 +230,7 @@ module Roma
216
230
  else
217
231
  remain = size - @rbuf.size
218
232
  Fiber.yield(remain)
219
- if Time.now.to_i - t > @timeout * mult
233
+ if Time.now.to_i - t > @@timeout * mult
220
234
  @log.warn("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} read_bytes time out");
221
235
  close_connection
222
236
  return nil
@@ -245,6 +259,7 @@ module Roma
245
259
  def conn_get_stat
246
260
  ret = {}
247
261
  ret["connection.count"] = EM.connection_count
262
+ ret["connection.descriptor_table_size"] = EM.set_descriptor_table_size
248
263
  ret["connection.continuous_limit"] = Handler.get_ccl
249
264
  ret["connection.accepted_connection_expire_time"] = Handler.connection_expire_time
250
265
  ret["connection.handler_instance_count"] = Handler.connections.length
@@ -1,6 +1,7 @@
1
1
  require 'thread'
2
2
  require 'socket'
3
3
  require 'singleton'
4
+ require 'roma/dns_cache'
4
5
 
5
6
  module Roma
6
7
  module Messaging
@@ -53,7 +54,8 @@ module Roma
53
54
  end
54
55
 
55
56
  def create_connection(ap)
56
- addr, port = ap.split(/[:_]/)
57
+ host, port = ap.split(/[:_]/)
58
+ addr = DNSCache.instance.resolve_name(host)
57
59
  TCPSocket.new(addr, port)
58
60
  end
59
61
 
@@ -21,6 +21,7 @@ module Roma
21
21
  attr :storages
22
22
  attr :rttable
23
23
  attr :stats
24
+ attr :wb_writer
24
25
 
25
26
  attr_accessor :eventloop
26
27
  attr_accessor :startup
@@ -36,7 +37,7 @@ module Roma
36
37
  initialize_storages
37
38
  initialize_handler
38
39
  initialize_plugin
39
- initialize_wb_witer
40
+ initialize_wb_writer
40
41
  end
41
42
 
42
43
  def start
@@ -191,7 +192,7 @@ module Roma
191
192
  end
192
193
  end
193
194
 
194
- def initialize_wb_witer
195
+ def initialize_wb_writer
195
196
  @wb_writer = Roma::WriteBehind::FileWriter.new(
196
197
  Roma::Config::WRITEBEHIND_PATH,
197
198
  Roma::Config::WRITEBEHIND_SHIFT_SIZE,
@@ -379,6 +380,10 @@ module Roma
379
380
  end
380
381
  end
381
382
 
383
+ if Roma::Config.const_defined?(:RTTABLE_SUB_NID)
384
+ @rttable.sub_nid = Roma::Config::RTTABLE_SUB_NID
385
+ end
386
+
382
387
  if Roma::Config.const_defined?(:ROUTING_FAIL_CNT_THRESHOLD)
383
388
  @rttable.fail_cnt_threshold = Roma::Config::ROUTING_FAIL_CNT_THRESHOLD
384
389
  end
@@ -386,6 +391,8 @@ module Roma
386
391
  @rttable.fail_cnt_gap = Roma::Config::ROUTING_FAIL_CNT_GAP
387
392
  end
388
393
  @rttable.lost_action = Roma::Config::DEFAULT_LOST_ACTION
394
+ @rttable.auto_recover = Roma::Config::AUTO_RECOVER if defined?(Roma::Config::AUTO_RECOVER)
395
+
389
396
  @rttable.enabled_failover = false
390
397
  @rttable.set_leave_proc{|nid|
391
398
  Roma::Messaging::ConPool.instance.close_same_host(nid)
@@ -399,6 +406,13 @@ module Roma
399
406
  @log.error("Romad has stopped, so that lose data.")
400
407
  end
401
408
  }
409
+ @rttable.set_recover_proc{|action|
410
+ if (@rttable.lost_action == :shutdown || @rttable.lost_action == :auto_assign) && @rttable.auto_recover == true
411
+ Roma::AsyncProcess::queue.push(Roma::AsyncMessage.new("#{action}"))
412
+ elsif
413
+ @log.error("AUTO_RECOVER is off or Unavailable value is set to [DEFAULT_LOST_ACTION] => #{@rttable.lost_action}")
414
+ end
415
+ }
402
416
  end
403
417
 
404
418
  def initialize_rttable_join
@@ -507,6 +521,8 @@ module Roma
507
521
  @stats.run_storage_clean_up
508
522
  stop_clean_up
509
523
  end
524
+ rescue Exception =>e
525
+ @log.error("#{e}\n#{$@}")
510
526
  end
511
527
 
512
528
  def timer_event_10sec
@@ -525,7 +541,7 @@ module Roma
525
541
  @log.warn("failover disable now!!")
526
542
  else
527
543
  version_check
528
- @rttable.delete_old_trans
544
+ @rttable.delete_old_trans(@stats.routing_trans_timeout)
529
545
  start_sync_routing_process
530
546
  end
531
547