roma 0.8.10 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # eval begin;load('roma/live_patch-20120302-001.rb');rescue Excption=>e;e.inspect;end
3
- #
4
- log = Roma::Logging::RLogger.instance
5
- log.info("live_patch-20120302-001:loading")
6
-
7
- Roma::Command::Receiver.class_eval{
8
- def forward_get_context(nid, k)
9
- con = get_connection(nid)
10
- con.send("fget_context #{k}\r\n")
11
- res = con.gets
12
- if res == nil
13
- @rttable.proc_failed(nid)
14
- @log.error("forward get_context failed:nid=#{nid} key=#{k}")
15
- return nil
16
- elsif res == "NOT_EXIST\r\n"
17
- elsif res.start_with?("ERROR")
18
- @rttable.proc_succeed(nid)
19
- con.close_connection
20
- return nil
21
- else
22
- while((buf = con.gets) != "END\r\n")
23
- res << buf
24
- end
25
- res << "END\r\n"
26
- end
27
- return_connection(nid, con)
28
- @rttable.proc_succeed(nid)
29
- res
30
- rescue => e
31
- @rttable.proc_failed(nid) if e.message != "no connection"
32
- @log.error("#{e.inspect}/#{$@}")
33
- @log.error("forward get_context failed:nid=#{nid} key=#{k}")
34
- nil
35
- end
36
-
37
- def ev_get_context(s)
38
- key,hname = s[1].split("\e")
39
- hname ||= @defhash
40
- d = Digest::SHA1.hexdigest(key).hex % @rttable.hbits
41
- vn = @rttable.get_vnode_id(d)
42
- nodes = @rttable.search_nodes_for_write(vn)
43
- if nodes[0] != @nid
44
- @log.warn("forward #{s[0]} key=#{key} vn=#{vn} to #{nodes[0]}")
45
- res = forward_get_context(nodes[0], s[1])
46
- if res
47
- return send_data("#{res}")
48
- end
49
- return send_data("SERVER_ERROR Message forward failed.\r\n")
50
- end
51
-
52
- unless @storages.key?(hname)
53
- send_data("SERVER_ERROR #{hname} dose not exists.\r\n")
54
- return
55
- end
56
-
57
- ret = @storages[hname].get_raw(vn, key, d)
58
- if ret
59
- send_data("nid = #{@nid}\r\n")
60
- send_data("vn = #{ret[0]}\r\n")
61
- send_data("t = #{ret[1]}\r\n")
62
- send_data("clk = #{ret[2]}\r\n")
63
- send_data("expt = #{ret[3]}\r\n")
64
- send_data("v.length = #{ret[4].length}\r\n") if ret[4]
65
- send_data("END\r\n")
66
- else
67
- return send_data("NOT_EXIST\r\n")
68
- end
69
- end
70
-
71
- def ev_fget_context(s)
72
- key,hname = s[1].split("\e")
73
- hname ||= @defhash
74
- d = Digest::SHA1.hexdigest(key).hex % @rttable.hbits
75
- vn = @rttable.get_vnode_id(d)
76
- nodes = @rttable.search_nodes_for_write(vn)
77
- if nodes.include?(@nid) == false
78
- @log.error("#{s[0]} failed key = #{s[1]} vn = #{vn}")
79
- return send_data("SERVER_ERROR Routing table is inconsistent.\r\n")
80
- end
81
-
82
- unless @storages.key?(hname)
83
- send_data("SERVER_ERROR #{hname} dose not exists.\r\n")
84
- return
85
- end
86
-
87
- ret = @storages[hname].get_raw(vn, key, d)
88
- if ret
89
- send_data("nid = #{@nid}\r\n")
90
- send_data("vn = #{ret[0]}\r\n")
91
- send_data("t = #{ret[1]}\r\n")
92
- send_data("clk = #{ret[2]}\r\n")
93
- send_data("expt = #{ret[3]}\r\n")
94
- send_data("v.length = #{ret[4].length}\r\n") if ret[4]
95
- send_data("END\r\n")
96
- else
97
- return send_data("NOT_EXIST\r\n")
98
- end
99
- end
100
- }
101
-
102
- Roma::Event::Handler.class_eval{
103
- @@ev_list['get_context'] = :ev_get_context
104
- @@ev_list['fget_context'] = :ev_fget_context
105
- }
106
-
107
- log.info("live_patch-20120302-001:has loaded")