roma 0.8.10 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ *0.8.11 (Aug 8 2012)*
2
+
3
+ * Allocate cmd_aliases plugin. [firejun] f7555c2
4
+ * Add a tool for log. [firejun] bea6c87
5
+ * Fix timezone of mapcount plugin and add tests. [Hiroki Matsue] 11f36b8
6
+ * Make TCMemStorage available to set options. [Hiroki Matsue] 0fef58b
7
+ * Correct end status of release command. [Hiroki Matsue] fc9a4bc
8
+ * Fix release command feature in a small nodes. [Hiroki Matsue] c765358
9
+ * fix:[can't add a new key into hash during iteration] occurring in leter then ruby 1.9.1 fixed. [junji torii] 2987536
10
+ * Fix result view of mkconfig. [Hiroki Matsue] bfb0f4a
11
+
1
12
  *0.8.10 (Feb 20 2012)*
2
13
 
3
14
  * Add authors and homepage info to gem. [Hiroki Matsue] 35c5db4
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ path = File.dirname(File.expand_path($PROGRAM_NAME))
4
+ $LOAD_PATH << path + "/../lib"
5
+
6
+ require 'roma/tools/log_merger'
@@ -259,7 +259,7 @@ module Roma
259
259
  rescue => e
260
260
  @log.error("asyncev_start_release_process:#{e.inspect} #{$@}")
261
261
  end
262
- @stats.run_relase = false
262
+ @stats.run_release = false
263
263
  }
264
264
  t[:name] = __method__
265
265
  end
@@ -443,16 +443,20 @@ module Roma
443
443
  def release_process
444
444
  @log.info("release_process:start.")
445
445
  nodes = @rttable.nodes
446
-
446
+ nodes.delete(@stats.ap_str)
447
+ hosts = []
448
+
447
449
  unless @stats.enabled_repetition_host_in_routing
448
- host = @stats.ap_str.split(/[:_]/)[0]
449
- nodes.delete_if{|nid| nid.split(/[:_]/)[0] == host }
450
+ nodes.each{ |node|
451
+ host = node.split(/[:_]/)[0]
452
+ hosts << host unless hosts.include?(host)
453
+ }
450
454
  else
451
- nodes.delete(@stats.ap_str)
455
+ hosts = nodes
452
456
  end
453
-
454
- if nodes.length < @rttable.rn
455
- @log.error("Physcal node dose not found.")
457
+
458
+ if hosts.length < @rttable.rn
459
+ @log.error("Sufficient nodes do not found.")
456
460
  return
457
461
  end
458
462
 
@@ -463,9 +467,12 @@ module Roma
463
467
  buf = nodes.clone
464
468
 
465
469
  unless @stats.enabled_repetition_host_in_routing
466
- hosts = []
467
- nids.each{|nid| hosts << nid.split(/[:_]/)[0]}
468
- buf.delete_if{|nid| hosts.include?(nid.split(/[:_]/)[0])}
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])}
469
476
  else
470
477
  nids.each{|nid| buf.delete(nid) }
471
478
  end
@@ -0,0 +1,43 @@
1
+
2
+ module Roma
3
+ module CommandPlugin
4
+
5
+ module PluginCommandAliases
6
+ include ::Roma::CommandPlugin
7
+
8
+ # shutdown [reason]
9
+ def ev_shutdown(s)
10
+ send_data("*** ARE YOU REALLY SURE TO SHUTDOWN? *** (yes/no)\r\n")
11
+ if gets != "yes\r\n"
12
+ close_connection_after_writing
13
+ return
14
+ end
15
+
16
+ if s.length == 2
17
+ @log.info("Receive a shutdown #{s[1]}")
18
+ else
19
+ @log.info("Receive a shutdown command.")
20
+ end
21
+ @rttable.enabled_failover = false
22
+ res = broadcast_cmd("rshutdown\r\n")
23
+ send_data("#{res.inspect}\r\n")
24
+ close_connection_after_writing
25
+ @stop_event_loop = true
26
+ end
27
+
28
+ # rshutdown [reason]
29
+ def ev_rshutdown(s)
30
+ if s.length == 2
31
+ @log.info("Receive a rshutdown #{s[1]}")
32
+ else
33
+ @log.info("Receive a rshutdown command.")
34
+ end
35
+ @rttable.enabled_failover = false
36
+ send_data("BYE\r\n")
37
+ close_connection_after_writing
38
+ @stop_event_loop = true
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -100,7 +100,7 @@ module Roma
100
100
  end
101
101
  end
102
102
 
103
- v["last_updated_date"] = Time.now.gmtime.strftime(DATE_FORMAT)
103
+ v["last_updated_date"] = Time.now.strftime(DATE_FORMAT)
104
104
  expt = chg_time_expt(ctx.argv[2].to_i)
105
105
 
106
106
  ret_str = return_str(v, stype)
@@ -116,7 +116,7 @@ module Roma
116
116
 
117
117
  v = {}
118
118
  v = data_load(ctx.stored.value)
119
- v["last_updated_date"] = Time.now.gmtime.strftime(DATE_FORMAT)
119
+ v["last_updated_date"] = Time.now.strftime(DATE_FORMAT)
120
120
 
121
121
  if v.is_a?(Hash)
122
122
  args = ctx.params.value.split(/\s*,\s*/)
@@ -19,6 +19,86 @@ module Roma
19
19
  }
20
20
  end
21
21
 
22
+ if RUBY_VERSION >= '1.9.2'
23
+ def each_clean_up(t, vnhash)
24
+ @do_clean_up = true
25
+ nt = Time.now.to_i
26
+ @hdb.each{ |hdb|
27
+ keys = hdb.keys
28
+ keys.each{ |k|
29
+ v = hdb[k]
30
+ return unless @do_clean_up
31
+ vn, last, clk, expt = unpack_header(v)
32
+ vn_stat = vnhash[vn]
33
+ if vn_stat == :primary && ( (expt != 0 && nt > expt) || (expt == 0 && t > last) )
34
+ yield k, vn
35
+ hdb.out(k) if hdb.get(k) == v
36
+ elsif vn_stat == nil && t > last
37
+ yield k, vn
38
+ hdb.out(k) if hdb.get(k) == v
39
+ end
40
+ sleep @each_clean_up_sleep
41
+ }
42
+ }
43
+ end
44
+
45
+ def each_vn_dump(target_vn)
46
+ count = 0
47
+ @divnum.times{|i|
48
+ tn = Time.now.to_i
49
+ keys = @hdb[i].keys
50
+ keys.each{|k|
51
+ v = @hdb[i][k]
52
+ vn, last, clk, expt, val = unpack_data(v)
53
+ if vn != target_vn || (expt != 0 && tn > expt)
54
+ count += 1
55
+ sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0
56
+ next
57
+ end
58
+ if val
59
+ yield [vn, last, clk, expt, k.length, k, val.length, val].pack("NNNNNa#{k.length}Na#{val.length}")
60
+ else
61
+ yield [vn, last, clk, expt, k.length, k, 0].pack("NNNNNa#{k.length}N")
62
+ end
63
+ }
64
+ }
65
+ end
66
+
67
+ def each_hdb_dump(i,except_vnh = nil)
68
+ count = 0
69
+ keys = @hdb[i].keys
70
+ keys.each{|k|
71
+ v = @hdb[i][k]
72
+ vn, last, clk, expt, val = unpack_data(v)
73
+ if except_vnh && except_vnh.key?(vn) || Time.now.to_i > expt
74
+ count += 1
75
+ sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0
76
+ else
77
+ yield [vn, last, clk, expt, k.length, k, val.length, val].pack("NNNNNa#{k.length}Na#{val.length}")
78
+ sleep @each_vn_dump_sleep
79
+ end
80
+ }
81
+ end
82
+
83
+ # Create vnode dump.
84
+ def get_vnode_hash(vn)
85
+ buf = {}
86
+ count = 0
87
+ hdb = @hdb[@hdiv[vn]]
88
+ keys = hdb.keys
89
+ keys.each{ |k|
90
+ v = hdb[k]
91
+ count += 1
92
+ sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0
93
+ dat = unpack_data(v) #v.unpack('NNNN')
94
+ buf[k] = v if dat[0] == vn
95
+ }
96
+ return buf
97
+ end
98
+ private :get_vnode_hash
99
+
100
+ end
101
+
22
102
  private
23
103
 
24
104
  def open_db(fname)
@@ -39,6 +39,7 @@ module Roma
39
39
  @ext_name = 'tc'
40
40
  end
41
41
 
42
+ alias get_stat_org get_stat
42
43
  def get_stat
43
44
  ret = super
44
45
  @hdb.each_with_index{|hdb,idx|
@@ -174,14 +175,47 @@ module Roma
174
175
  end # class TCAsyncStorage
175
176
 
176
177
 
177
- class TCMemStorage < BasicStorage
178
+ class TCMemStorage < TCStorage
178
179
  include TokyoCabinet
179
180
 
181
+ def get_stat
182
+ ret = get_stat_org
183
+ @hdb.each_with_index{|hdb,idx|
184
+ ret["storage[#{idx}].rnum"] = hdb.rnum
185
+ ret["storage[#{idx}].size"] = hdb.size
186
+ }
187
+ ret
188
+ end
189
+
190
+ protected
191
+
192
+ def get_options(hdb)
193
+ prop = parse_options
194
+
195
+ prop.each_key{|k|
196
+ unless /^(bnum|capnum|capsiz)$/ =~ k
197
+ raise RuntimeError.new("Syntax error, unexpected option #{k}")
198
+ end
199
+ }
200
+
201
+ opts = ""
202
+ opts += "#bnum=#{prop['bnum']}" if prop.key?('bnum')
203
+ opts += "#capnum=#{prop['capnum']}" if prop.key?('capnum')
204
+ opts += "#capsiz=#{prop['capsiz']}" if prop.key?('capsiz')
205
+ opts = nil unless opts.length > 0
206
+ opts
207
+ end
208
+
180
209
  private
181
210
 
182
211
  def open_db(fname)
183
212
  hdb = ADB::new
184
- hdb.open("*")
213
+
214
+ options = get_options(hdb)
215
+ dbname = "*"
216
+ dbname += options if options
217
+
218
+ hdb.open(dbname)
185
219
  hdb
186
220
  end
187
221
 
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ class ReadLog
5
+ def initialize(fn)
6
+ @f = open(fn)
7
+ @buff = ''
8
+ @prev = @f.gets
9
+ @s_date = ''
10
+ end
11
+
12
+ def read_line
13
+ begin
14
+ if /^#\sLogfile\screated\son.+/ =~ @prev then
15
+ @prev = @f.gets
16
+ end
17
+
18
+ @buff = @prev
19
+ @prev = @f.gets
20
+
21
+ while !(match_line(@prev)) && !(@prev.nil?) do
22
+ @buff << @prev
23
+ @prev = @f.gets
24
+ end
25
+
26
+ match_line(@buff)
27
+ rescue
28
+ unless @f.closed?
29
+ @f.close
30
+ end
31
+ end
32
+ end
33
+
34
+ def get_line
35
+ @buff
36
+ end
37
+
38
+ def get_date
39
+ @s_date
40
+ end
41
+
42
+ def match_line(l)
43
+ if /^[TDIWEFU],\s\[(\d{4})\-(\d{2})\-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d+)\s#\d+\].+/ =~ l then
44
+ @s_date = $1 << $2 << $3 << $4 << $5 << $6 << $7
45
+ true
46
+ else
47
+ @s_date = nil
48
+ false
49
+ end
50
+ end
51
+ end
52
+
53
+ class WriteLog
54
+ def initialize(fn)
55
+ if fn == $stdout then
56
+ @f = $stdout
57
+ else
58
+ @f = open(fn, "w")
59
+ end
60
+ end
61
+
62
+ def write_line(th, l)
63
+ buff = th << ',' << l
64
+ @f.write(buff)
65
+ end
66
+
67
+ def close_file
68
+ unless @f.closed?
69
+ @f.close
70
+ end
71
+ end
72
+ end
73
+
74
+ $save_fn = $stdout
75
+ $log_l = 'TRACE'
76
+ $start_date = '00000000000000000000'
77
+ $end_date = '99999999999999999999'
78
+ o = OptionParser.new
79
+ o.banner = "Usage : #{__FILE__} [log_file1]..[log_fileN] [-o output_file] [-l log_level]"
80
+ o.on('-o output_file', '[output file name]', '(default=STDOUT)') {|v| $save_fn = v }
81
+ o.on('-l log_level', '[TRACE | DEBUG | INFO | WARN | ERROR | FATAL | UNKNOWN]', '(default=TRACE)') {|v| $log_l = v}
82
+ o.on('-s start_date', '[YYYYMMDDHHMMSS]') {|v| $start_date = v.ljust(20, "0").to_s}
83
+ o.on('-e end_date', '[YYYYMMDDHHMMSS]') {|v| $end_date = v.ljust(20, "9").to_s}
84
+ begin
85
+ o.parse!
86
+ rescue
87
+ STDERR.puts o.help
88
+ puts "ERROR : unrecognized option"
89
+ exit
90
+ end
91
+
92
+ if ARGV.length == 0 then
93
+ STDERR.puts o.help
94
+ exit
95
+ end
96
+
97
+ r = Array.new()
98
+ w = WriteLog.new($save_fn)
99
+ h = Hash.new()
100
+ tmp = Hash.new()
101
+ e_lv = nil
102
+
103
+ case $log_l
104
+ when 'DEBUG' then
105
+ e_lv = 'DIWEFU'
106
+ when 'INFO' then
107
+ e_lv = 'IWEFU'
108
+ when 'WARN' then
109
+ e_lv = 'WEFU'
110
+ when 'ERROR' then
111
+ e_lv = 'EFU'
112
+ when 'FATAL' then
113
+ e_lv = 'FU'
114
+ when 'UNKNOWN' then
115
+ e_lv = 'U'
116
+ else
117
+ e_lv = 'TDIWEFU'
118
+ end
119
+
120
+ ARGV.length.times do |i|
121
+ r[i] = ReadLog.new(ARGV[i])
122
+ r[i].read_line
123
+ if $start_date != '00000000000000000000' then
124
+ while !(r[i].get_date.nil?) && $start_date > r[i].get_date do
125
+ r[i].read_line
126
+ end
127
+ end
128
+ end
129
+
130
+ begin
131
+ h.clear
132
+ tmp.clear
133
+ ARGV.length.times do |i|
134
+ unless r[i].get_line.nil? then
135
+ tmp[i] = r[i].get_date
136
+ end
137
+ end
138
+ if tmp.length > 0 then
139
+ h = tmp.sort_by{|a, b| b}
140
+ if /^[#{e_lv}],.+/ =~ r[h[0][0]].get_line then
141
+ if ($start_date <= h[0][1]) && ($end_date >= h[0][1]) then
142
+ w.write_line(File.basename(ARGV[h[0][0]].dup), r[h[0][0]].get_line)
143
+ end
144
+ end
145
+ r[h[0][0]].read_line
146
+ end
147
+ end while tmp.length > 0
148
+
149
+ w.close_file
150
+ exit
@@ -500,7 +500,7 @@ module Roma
500
500
  puts "Before"
501
501
  Box.print_with_box(@defaults)
502
502
 
503
- re_require(CONFIG_PATH, CONFIG_FULL_PATH, Config)
503
+ re_require(CONFIG_OUT_PATH, Config)
504
504
  results = load_config([:STORAGE_CLASS, :STORAGE_OPTION, :PLUGIN_FILES])
505
505
  print "\r\nAfter\r\n"
506
506
  Box.print_with_box(results)
@@ -523,12 +523,12 @@ module Roma
523
523
  end
524
524
  end
525
525
 
526
- def re_require(lib_path, path, c_obj)
526
+ def re_require(path, c_obj)
527
527
  $".delete(File.expand_path(path))
528
528
  c_obj.constants.each do |cnst|
529
529
  c_obj.class_eval { remove_const cnst }
530
530
  end
531
- require lib_path
531
+ require path
532
532
  end
533
533
 
534
534
  end # Mkconfig
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Roma
3
- VERSION = "0.8.10"
3
+ VERSION = "0.8.11"
4
4
  end