module Roma::Command::RoutingCommandReceiver
Public Instance Methods
ev_add_rttable_sub_nid(s)
click to toggle source
add_rttable_sub_nid <netmask> <regexp> <replace>
# File lib/roma/command/rt_command_receiver.rb 251 def ev_add_rttable_sub_nid(s) 252 if s.length != 4 253 return send_data("usage:add_rttable_sub_nid <netmask> <regexp> <replace>\r\n") 254 end 255 res = broadcast_cmd("radd_rttable_sub_nid #{s[1]} #{s[2]} #{s[3]}\r\n") 256 @rttable.sub_nid[s[1]] = {:regexp => "#{s[2]}", :replace => "#{s[3]}"} 257 res[@stats.ap_str] = "ADDED" 258 send_data("#{res}\r\n") 259 end
ev_clear_rttable_sub_nid(s)
click to toggle source
cleat RTTABLE_SUB_NID map
# File lib/roma/command/rt_command_receiver.rb 238 def ev_clear_rttable_sub_nid(s) 239 res = broadcast_cmd("rclear_rttable_sub_nid\r\n") 240 @rttable.sub_nid.clear() 241 res[@stats.ap_str] = "CLEARED" 242 send_data("#{res}\r\n") 243 end
ev_create_nodes_from_v_idx(s)
click to toggle source
# File lib/roma/command/rt_command_receiver.rb 32 def ev_create_nodes_from_v_idx(s) 33 @rttable.create_nodes_from_v_idx 34 send_data("CREATED\r\n") 35 end
ev_delete_rttable_sub_nid(s)
click to toggle source
delete_rttable_sub_nid <netmask>
# File lib/roma/command/rt_command_receiver.rb 271 def ev_delete_rttable_sub_nid(s) 272 if s.length != 2 273 return send_data("usage:delete_rttable_sub_nid <netmask>\r\n") 274 end 275 276 res = broadcast_cmd("rdelete_rttable_sub_nid #{s[1]}\r\n") 277 unless @rttable.sub_nid.delete s[1] 278 res[@stats.ap_str] = "NOT_FOUND" 279 else 280 res[@stats.ap_str] = "DELETED" 281 end 282 send_data("#{res}\r\n") 283 end
ev_enabled_repetition_in_routing?(s)
click to toggle source
# File lib/roma/command/rt_command_receiver.rb 63 def ev_enabled_repetition_in_routing?(s) 64 rt = @rttable 65 rd = @rttable.sub_nid_rd(@addr) 66 rt = Roma::Routing::RoutingTable.new(rd) if rd 67 68 if s.length == 1 69 repetition = rt.check_repetition_in_routing 70 send_data("#{repetition}\r\n") 71 else 72 send_data("CLIENT_ERROR\r\n") 73 end 74 end
ev_get_key_info(s)
click to toggle source
get_key_info <key>
# File lib/roma/command/rt_command_receiver.rb 299 def ev_get_key_info(s) 300 if s.length != 2 301 return send_data("CLIENT_ERROR number of arguments(0 for 1)\r\n") 302 end 303 304 d = Digest::SHA1.hexdigest(s[1]).hex % @rttable.hbits 305 vn = @rttable.get_vnode_id(d) 306 nodes = @rttable.search_nodes_for_write(vn) 307 send_data(sprintf("d = %s 0x%x\r\n",d,d)) 308 send_data(sprintf("vn = %s 0x%x\r\n",vn,vn)) 309 send_data("nodes = #{nodes.inspect}\r\n") 310 send_data("END\r\n") 311 end
ev_getroute(s)
click to toggle source
getroute <vnode-id>
# File lib/roma/command/rt_command_receiver.rb 100 def ev_getroute(s) 101 if s.length < 2 102 send_data("CLIENT_ERROR\r\n") 103 return 104 end 105 clk,nids = @rttable.search_nodes_with_clk(s[1].to_i) 106 if clk == nil 107 send_data("END\r\n") 108 return 109 end 110 res = "#{clk-1}" 111 nids.each{ |nid| res << " #{nid}" } 112 send_data("#{res}\r\n") 113 end
ev_history_of_lost(s)
click to toggle source
history_of_lost [yyyymmddhhmmss]
# File lib/roma/command/rt_command_receiver.rb 121 def ev_history_of_lost(s) 122 if s.length != 2 123 t = Time.mktime(2000, 1, 1, 0, 0, 0) 124 else 125 t = Time.mktime(s[1][0..3], s[1][4..5], s[1][6..7], s[1][8..9], s[1][10..11], s[1][12..13]) 126 end 127 nodes = @rttable.search_lost_vnodes(t) 128 nodes.each{|vn| send_data("#{vn}\r\n") } 129 send_data("END\r\n") 130 rescue =>e 131 send_data("CLIENT_ERROR\r\n") 132 end
ev_join(s)
click to toggle source
join <node id>
# File lib/roma/command/rt_command_receiver.rb 8 def ev_join(s) 9 @rttable.add_node(s[1]) 10 send_data("ADDED\r\n") 11 end
ev_leave(s)
click to toggle source
leave <node id>
# File lib/roma/command/rt_command_receiver.rb 14 def ev_leave(s) 15 @log.warn("receive a leave #{s[1]} message.") 16 @rttable.leave(s[1]) 17 send_data("DELETED\r\n") 18 end
ev_mklhash(s)
click to toggle source
mklhash <id>
# File lib/roma/command/rt_command_receiver.rb 116 def ev_mklhash(s) 117 send_data("#{@rttable.mtree.get(s[1])}\r\n") 118 end
ev_nodelist(s)
click to toggle source
# File lib/roma/command/rt_command_receiver.rb 20 def ev_nodelist(s) 21 nl = nil 22 @rttable.nodes.each{ |nid| 23 if nl 24 nl << " #{nid}" 25 else 26 nl = nid.clone 27 end 28 } 29 send_data("#{nl}\r\n") 30 end
ev_radd_rttable_sub_nid(s)
click to toggle source
radd_rttable_sub_nid <netmask> <regexp> <replace>
# File lib/roma/command/rt_command_receiver.rb 262 def ev_radd_rttable_sub_nid(s) 263 if s.length != 4 264 return send_data("usage:add_rttable_sub_nid <netmask> <regexp> <replace>\r\n") 265 end 266 @rttable.sub_nid[s[1]] = {:regexp => "#{s[2]}", :replace => "#{s[3]}"} 267 send_data("ADDED\r\n") 268 end
ev_rclear_rttable_sub_nid(s)
click to toggle source
# File lib/roma/command/rt_command_receiver.rb 245 def ev_rclear_rttable_sub_nid(s) 246 @rttable.sub_nid.clear() 247 send_data("CLEARED\r\n") 248 end
ev_rdelete_rttable_sub_nid(s)
click to toggle source
rdelete_rttable_sub_nid <netmask>
# File lib/roma/command/rt_command_receiver.rb 286 def ev_rdelete_rttable_sub_nid(s) 287 if s.length != 2 288 return send_data("usage:delete_rttable_sub_nid <netmask>\r\n") 289 end 290 291 unless @rttable.sub_nid.delete s[1] 292 send_data("NOT_FOUND\r\n") 293 else 294 send_data("DELETED\r\n") 295 end 296 end
ev_routingdump(s)
click to toggle source
routingdump [yaml|json|yamlbytes|bin]rn
# File lib/roma/command/rt_command_receiver.rb 38 def ev_routingdump(s) 39 rt = @rttable 40 rd = @rttable.sub_nid_rd(@addr) 41 rt = Roma::Routing::RoutingTable.new(rd) if rd 42 43 if s.length == 1 44 dmp = rt.dump 45 send_data("#{dmp.length}\r\n#{dmp}\r\nEND\r\n") 46 elsif s[1] == 'yaml' 47 dmp = rt.dump_yaml 48 send_data("#{dmp}\r\nEND\r\n") 49 elsif s[1] == 'json' 50 dmp = rt.dump_json 51 send_data("#{dmp}\r\nEND\r\n") 52 elsif s[1] == 'yamlbytes' 53 dmp = rt.dump_yaml 54 send_data("#{dmp.length + 7}\r\nEND\r\n") 55 elsif s[1] == 'bin' 56 dmp = rt.dump_binary 57 send_data("#{dmp.length}\r\n#{dmp}\r\nEND\r\n") 58 else 59 send_data("CLIENT_ERROR\r\n") 60 end 61 end
ev_rset_auto_recover(s)
click to toggle source
# File lib/roma/command/rt_command_receiver.rb 156 def ev_rset_auto_recover(s) 157 if /^true$|^false$/ !~ s[1] 158 return send_data("CLIENT_ERROR arguments must be true or false #{s[1]} #{s[1].class} \r\n") 159 elsif s.length != 2 && s.length != 3 160 return send_data("CLIENT_ERROR number of arguments(0 for 1)\r\n") 161 elsif s.length == 3 && s[2].to_i < 1 162 return send_data("CLIENT_ERROR length must be greater than zero\r\n") 163 end 164 if s[1] == "true" 165 @rttable.auto_recover = true 166 elsif s[1] == "false" 167 @rttable.auto_recover = false 168 end 169 @rttable.auto_recover_status = "waiting" 170 @rttable.auto_recover_time = s[2].to_i if s[2] 171 send_data("STORED\r\n") 172 end
ev_rset_gap_for_failover(s)
click to toggle source
rset_gap_for_failover
# File lib/roma/command/rt_command_receiver.rb 229 def ev_rset_gap_for_failover(s) 230 if s.length != 2 231 return send_data("usage:rset_gap_for_failover <n>\r\n") 232 end 233 @rttable.fail_cnt_gap = s[1].to_f 234 send_data("STORED\r\n") 235 end
ev_rset_lost_action(s)
click to toggle source
# File lib/roma/command/rt_command_receiver.rb 187 def ev_rset_lost_action(s) 188 if s.length != 2 || /^auto_assign$|^shutdown$/ !~ s[1] 189 return send_data("CLIENT_ERROR changing lost_action must be auto_assign or shutdown\r\n") 190 elsif /^auto_assign$|^shutdown$/ !~ @rttable.lost_action 191 return send_data("CLIENT_ERROR can use this command only current lost action is auto_assign or shutdwn mode\r\n") 192 end 193 @rttable.lost_action = s[1].to_sym 194 send_data("STORED\r\n") 195 end
ev_rset_threshold_for_failover(s)
click to toggle source
rset_threshold_for_failover <n>
# File lib/roma/command/rt_command_receiver.rb 209 def ev_rset_threshold_for_failover(s) 210 if s.length != 2 || s[1].to_i == 0 211 return send_data("usage:set_threshold_for_failover <n>\r\n") 212 end 213 @rttable.fail_cnt_threshold = s[1].to_i 214 send_data("STORED\r\n") 215 end
ev_set_auto_recover(s)
click to toggle source
set_auto_recover [true|false] <sec>
# File lib/roma/command/rt_command_receiver.rb 135 def ev_set_auto_recover(s) 136 #check argument 137 if /^true$|^false$/ !~ s[1] 138 return send_data("CLIENT_ERROR arguments must be true or false\r\n") 139 elsif s.length != 2 && s.length != 3 140 return send_data("CLIENT_ERROR number of arguments(0 for 1)\r\n") 141 elsif s.length == 3 && s[2].to_i < 1 142 return send_data("CLIENT_ERROR length must be greater than zero\r\n") 143 end 144 res = broadcast_cmd("rset_auto_recover #{s[1]} #{s[2]}\r\n") 145 if s[1] == "true" 146 @rttable.auto_recover = true 147 elsif s[1] == "false" 148 @rttable.auto_recover = false 149 end 150 @rttable.auto_recover_status = "waiting" 151 @rttable.auto_recover_time = s[2].to_i if s[2] 152 res[@stats.ap_str] = "STORED" 153 send_data("#{res}\r\n") 154 end
ev_set_gap_for_failover(s)
click to toggle source
set_gap_for_failover
# File lib/roma/command/rt_command_receiver.rb 218 def ev_set_gap_for_failover(s) 219 if s.length != 2 220 return send_data("usage:set_gap_for_failover <n>\r\n") 221 end 222 res = broadcast_cmd("rset_gap_for_failover #{s[1]}\r\n") 223 @rttable.fail_cnt_gap = s[1].to_f 224 res[@stats.ap_str] = "STORED" 225 send_data("#{res}\r\n") 226 end
ev_set_lost_action(s)
click to toggle source
set_lost_action [auto_assign|shutdown]
# File lib/roma/command/rt_command_receiver.rb 175 def ev_set_lost_action(s) 176 if s.length != 2 || /^auto_assign$|^shutdown$/ !~ s[1] 177 return send_data("CLIENT_ERROR changing lost_action must be auto_assign or shutdown\r\n") 178 elsif /^auto_assign$|^shutdown$/ !~ @rttable.lost_action 179 return send_data("CLIENT_ERROR can use this command only current lost action is auto_assign or shutdwn mode\r\n") 180 end 181 res = broadcast_cmd("rset_lost_action #{s[1]}\r\n") 182 @rttable.lost_action = s[1].to_sym 183 res[@stats.ap_str] = "STORED" 184 send_data("#{res}\r\n") 185 end
ev_set_threshold_for_failover(s)
click to toggle source
set_threshold_for_failover <n>
# File lib/roma/command/rt_command_receiver.rb 198 def ev_set_threshold_for_failover(s) 199 if s.length != 2 || s[1].to_i == 0 200 return send_data("usage:set_threshold_for_failover <n>\r\n") 201 end 202 res = broadcast_cmd("rset_threshold_for_failover #{s[1]}\r\n") 203 @rttable.fail_cnt_threshold = s[1].to_i 204 res[@stats.ap_str] = "STORED" 205 send_data("#{res}\r\n") 206 end
ev_setroute(s)
click to toggle source
setroute <vnode-id> <clock> <node-id> …
# File lib/roma/command/rt_command_receiver.rb 77 def ev_setroute(s) 78 if s.length < 4 79 send_data("CLIENT_ERROR\r\n") 80 else 81 nids=[] 82 s[3..-1].each{ |nid| nids << nid } 83 # check irregular node name 84 nids.each{ |nid| 85 if !nid.ascii_only? || nid.empty? 86 send_data("CLIENT_ERROR : irregular node name was input.[\"#{nid}\"]\r\n") 87 return 88 end 89 } 90 res=@rttable.set_route(s[1].to_i, s[2].to_i, nids) 91 if res.is_a?(Integer) 92 send_data("STORED\r\n") 93 else 94 send_data("SERVER_ERROR #{res}\r\n") 95 end 96 end 97 end