ls4 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/AUTHORS +1 -0
  2. data/COPYING +661 -0
  3. data/ChangeLog +9 -0
  4. data/NOTICE +8 -0
  5. data/README.rdoc +61 -0
  6. data/bin/ls4-cs +3 -0
  7. data/bin/ls4-ds +3 -0
  8. data/bin/ls4-gw +3 -0
  9. data/bin/ls4-standalone +3 -0
  10. data/bin/ls4cmd +3 -0
  11. data/bin/ls4ctl +3 -0
  12. data/bin/ls4rpc +3 -0
  13. data/bin/ls4stat +3 -0
  14. data/bin/ls4top +3 -0
  15. data/lib/ls4/command/cmd.rb +241 -0
  16. data/lib/ls4/command/cs.rb +190 -0
  17. data/lib/ls4/command/ctl.rb +278 -0
  18. data/lib/ls4/command/ds.rb +335 -0
  19. data/lib/ls4/command/gw.rb +256 -0
  20. data/lib/ls4/command/rpc.rb +172 -0
  21. data/lib/ls4/command/standalone.rb +318 -0
  22. data/lib/ls4/command/stat.rb +244 -0
  23. data/lib/ls4/command/top.rb +291 -0
  24. data/lib/ls4/default.rb +26 -0
  25. data/lib/ls4/lib/cclog.rb +220 -0
  26. data/lib/ls4/lib/ebus.rb +553 -0
  27. data/lib/ls4/lib/vbcode.rb +228 -0
  28. data/lib/ls4/logic/fault_detector.rb +212 -0
  29. data/lib/ls4/logic/membership.rb +253 -0
  30. data/lib/ls4/logic/node.rb +66 -0
  31. data/lib/ls4/logic/okey.rb +45 -0
  32. data/lib/ls4/logic/tsv_data.rb +81 -0
  33. data/lib/ls4/logic/weight.rb +166 -0
  34. data/lib/ls4/service/balance.rb +62 -0
  35. data/lib/ls4/service/base.rb +29 -0
  36. data/lib/ls4/service/bus.rb +37 -0
  37. data/lib/ls4/service/config.rb +63 -0
  38. data/lib/ls4/service/config_cs.rb +33 -0
  39. data/lib/ls4/service/config_ds.rb +56 -0
  40. data/lib/ls4/service/config_gw.rb +42 -0
  41. data/lib/ls4/service/data_client.rb +122 -0
  42. data/lib/ls4/service/data_server.rb +168 -0
  43. data/lib/ls4/service/data_server_url.rb +83 -0
  44. data/lib/ls4/service/gateway.rb +375 -0
  45. data/lib/ls4/service/gateway_ro.rb +91 -0
  46. data/lib/ls4/service/gw_http.rb +821 -0
  47. data/lib/ls4/service/heartbeat.rb +182 -0
  48. data/lib/ls4/service/log.rb +81 -0
  49. data/lib/ls4/service/master_select.rb +148 -0
  50. data/lib/ls4/service/mds.rb +292 -0
  51. data/lib/ls4/service/mds_cache.rb +294 -0
  52. data/lib/ls4/service/mds_cache_mem.rb +63 -0
  53. data/lib/ls4/service/mds_cache_memcached.rb +65 -0
  54. data/lib/ls4/service/mds_ha.rb +176 -0
  55. data/lib/ls4/service/mds_memcache.rb +209 -0
  56. data/lib/ls4/service/mds_tc.rb +508 -0
  57. data/lib/ls4/service/mds_tt.rb +472 -0
  58. data/lib/ls4/service/membership.rb +331 -0
  59. data/lib/ls4/service/process.rb +90 -0
  60. data/lib/ls4/service/rpc.rb +50 -0
  61. data/lib/ls4/service/rpc_cs.rb +101 -0
  62. data/lib/ls4/service/rpc_ds.rb +96 -0
  63. data/lib/ls4/service/rpc_gw.rb +255 -0
  64. data/lib/ls4/service/rts.rb +94 -0
  65. data/lib/ls4/service/rts_file.rb +76 -0
  66. data/lib/ls4/service/rts_memory.rb +55 -0
  67. data/lib/ls4/service/slave.rb +132 -0
  68. data/lib/ls4/service/stat.rb +91 -0
  69. data/lib/ls4/service/stat_cs.rb +25 -0
  70. data/lib/ls4/service/stat_ds.rb +40 -0
  71. data/lib/ls4/service/stat_gw.rb +25 -0
  72. data/lib/ls4/service/storage.rb +116 -0
  73. data/lib/ls4/service/storage_dir.rb +201 -0
  74. data/lib/ls4/service/sync.rb +206 -0
  75. data/lib/ls4/service/time_check.rb +80 -0
  76. data/lib/ls4/service/ulog.rb +159 -0
  77. data/lib/ls4/service/ulog_file.rb +398 -0
  78. data/lib/ls4/service/ulog_memory.rb +53 -0
  79. data/lib/ls4/service/weight.rb +134 -0
  80. data/lib/ls4/version.rb +5 -0
  81. data/test/01_add_get_remove.rt +84 -0
  82. data/test/02_read.rt +61 -0
  83. data/test/03_getd_readd.rt +69 -0
  84. data/test/04_version_time.rt +170 -0
  85. data/test/05_version_name.rt +161 -0
  86. data/test/06_http_get_set_remove_1.rt +119 -0
  87. data/test/07_http_get_set_remove_2.rt +116 -0
  88. data/test/08_read_only_time.rt +177 -0
  89. data/test/09_read_only_name.rt +173 -0
  90. data/test/10_http_get_set_remove_3.rt +73 -0
  91. data/test/11_mds_cache_memcached.rt +88 -0
  92. data/test/12_mds_cache_local_memory.rt +86 -0
  93. data/test/13_memcache_mds.rt +84 -0
  94. data/test/14_delete.rt +63 -0
  95. data/test/15_standalone.rt +71 -0
  96. data/test/chukan.rb +516 -0
  97. data/test/common.rb +250 -0
  98. data/test/load_test.rb +79 -0
  99. data/test/load_test_offload.rb +86 -0
  100. metadata +295 -0
@@ -0,0 +1,94 @@
1
+ #
2
+ # LS4
3
+ # Copyright (C) 2010-2011 FURUHASHI Sadayuki
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ module LS4
19
+
20
+
21
+ class RelayTimeStampBus < Bus
22
+ call_slot :init
23
+
24
+ call_slot :open
25
+ end
26
+
27
+
28
+ module RelayTimeStamp
29
+ #def close
30
+ #end
31
+
32
+ #def get
33
+ #end
34
+
35
+ #def set(pos, &block)
36
+ #end
37
+ end
38
+
39
+
40
+ class RelayTimeStampSelector
41
+ IMPLS = {}
42
+
43
+ def self.register(name, klass)
44
+ IMPLS[name.to_sym] = klass
45
+ nil
46
+ end
47
+
48
+ def self.select_class(uri)
49
+ uri ||= "mem:"
50
+
51
+ if m = /^(\w{1,8})\:(.*)/.match(uri)
52
+ type = m[1].to_sym
53
+ expr = m[2]
54
+ else
55
+ type = :file
56
+ expr = uri
57
+ end
58
+
59
+ klass = IMPLS[type]
60
+
61
+ unless klass
62
+ "unknown RelayTimeStamp type: #{type}"
63
+ end
64
+
65
+ return klass, expr
66
+ end
67
+
68
+ def self.select!(uri)
69
+ klass, expr = select_class(uri)
70
+ klass.init
71
+
72
+ RelayTimeStampBus.init(expr)
73
+ end
74
+
75
+ def self.open!
76
+ select!(ConfigBus.get_rts_path)
77
+ end
78
+ end
79
+
80
+
81
+ class RelayTimeStampService < Service
82
+ #def init(expr)
83
+ #end
84
+
85
+ #def open(nid)
86
+ #end
87
+
88
+ ebus_connect :RelayTimeStampBus,
89
+ :open,
90
+ :init
91
+ end
92
+
93
+
94
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # LS4
3
+ # Copyright (C) 2010-2011 FURUHASHI Sadayuki
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ module LS4
19
+
20
+
21
+ class FileRelayTimeStampService < RelayTimeStampService
22
+ RelayTimeStampSelector.register(:file, self)
23
+
24
+ def init(expr)
25
+ @dir = expr
26
+ end
27
+
28
+ class Stamp
29
+ include RelayTimeStamp
30
+
31
+ def initialize(path)
32
+ @path = path
33
+ @tmp_path = "#{@path}.tmp"
34
+ @file = nil
35
+ end
36
+
37
+ def close
38
+ if @file
39
+ @file.close
40
+ @file = nil
41
+ end
42
+ nil
43
+ end
44
+
45
+ def get
46
+ unless @file
47
+ @file = File.open(@path)
48
+ end
49
+ @file.pos = 0
50
+ @file.read.to_i
51
+ rescue
52
+ 0
53
+ end
54
+
55
+ def set(pos, &block)
56
+ close
57
+
58
+ File.open(@tmp_path, "w") {|f|
59
+ f.write(pos.to_s)
60
+ }
61
+
62
+ block.call if block
63
+
64
+ File.rename(@tmp_path, @path)
65
+
66
+ nil
67
+ end
68
+ end
69
+
70
+ def open(nid)
71
+ Stamp.new("#{@dir}/rts-#{nid}")
72
+ end
73
+ end
74
+
75
+
76
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # LS4
3
+ # Copyright (C) 2010-2011 FURUHASHI Sadayuki
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ module LS4
19
+
20
+
21
+ class MemoryRelayTimeStampService < RelayTimeStampService
22
+ RelayTimeStampSelector.register(:mem, self)
23
+
24
+ def init(expr)
25
+ @hash = {}
26
+ end
27
+
28
+ class Stamp
29
+ include RelayTimeStamp
30
+
31
+ def initialize
32
+ @mem = 0
33
+ end
34
+
35
+ def close
36
+ end
37
+
38
+ def get
39
+ @mem
40
+ end
41
+
42
+ def set(pos, &block)
43
+ block.call if block
44
+ @mem = pos
45
+ nil
46
+ end
47
+ end
48
+
49
+ def open(nid)
50
+ @hash[nid] ||= Stamp.new
51
+ end
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,132 @@
1
+ #
2
+ # LS4
3
+ # Copyright (C) 2010-2011 FURUHASHI Sadayuki
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ module LS4
19
+
20
+
21
+ class SlaveBus < Bus
22
+ call_slot :open
23
+ call_slot :close
24
+ call_slot :try_replicate
25
+ end
26
+
27
+
28
+ class SlaveService < Service
29
+ class Replicator
30
+ def initialize(storage, nid, rts)
31
+ @storage = storage
32
+ @nid = nid
33
+ @rts = rts
34
+ @pulling = false
35
+ end
36
+
37
+ def close
38
+ @rts.close
39
+ end
40
+
41
+ def try_replicate(session, limit)
42
+ if @pulling
43
+ return nil
44
+ end
45
+ @pulling = true
46
+
47
+ begin
48
+ pos = @rts.get
49
+ session.callback(:replicate_pull, pos, limit) do |future|
50
+ ack_replicate_pull(future)
51
+ end
52
+
53
+ rescue
54
+ $log.error "try replicate #{$!}"
55
+ $log.debug_backtrace $!.backtrace
56
+ @pulling = false
57
+ raise
58
+ end
59
+ end
60
+
61
+ private
62
+ def ack_replicate_pull(future)
63
+ npos, msgs = future.get
64
+
65
+ return if msgs.empty?
66
+
67
+ msgs.each {|vtime,key,offset,data|
68
+ apply(vtime, key, offset, data)
69
+ }
70
+
71
+ @rts.set(npos)
72
+
73
+ rescue
74
+ # FIXME log
75
+ $log.error "try pull from nid=#{@nid}: #{$!}"
76
+ $log.debug_backtrace $!.backtrace
77
+ raise
78
+ ensure
79
+ @pulling = false
80
+ end
81
+
82
+ def apply(vtime, key, offset, data)
83
+ if data
84
+ if offset
85
+ @storage.write(vtime, key, offset, data)
86
+ else
87
+ @storage.set(vtime, key, data)
88
+ end
89
+ else
90
+ @storage.delete(vtime, key)
91
+ end
92
+ end
93
+ end
94
+
95
+ def initialize
96
+ @repls = {} # {nid => Replicator}
97
+ end
98
+
99
+ def open
100
+ end
101
+
102
+ def close
103
+ @repls.each_pair {|nid, repl|
104
+ repl.close
105
+ }
106
+ end
107
+
108
+ def try_replicate(nid, session)
109
+ repl = open_replicator(nid)
110
+ repl.try_replicate(session, PULL_LIMIT)
111
+ end
112
+
113
+ ebus_connect :SlaveBus,
114
+ :open,
115
+ :close,
116
+ :try_replicate
117
+
118
+ private
119
+ PULL_LIMIT = 128*1024*1024 # 128MB
120
+
121
+ def open_replicator(nid)
122
+ if repl = @repls[nid]
123
+ return repl
124
+ end
125
+ rts = RelayTimeStampBus.open(nid)
126
+ repl = Replicator.new(StorageBus, nid, rts)
127
+ @repls[nid] = repl
128
+ end
129
+ end
130
+
131
+
132
+ end
@@ -0,0 +1,91 @@
1
+ #
2
+ # LS4
3
+ # Copyright (C) 2010-2011 FURUHASHI Sadayuki
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as
7
+ # published by the Free Software Foundation, either version 3 of the
8
+ # License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ module LS4
19
+
20
+
21
+ class StatBus < Bus
22
+ call_slot :membership_info
23
+ call_slot :fault_info
24
+ call_slot :replset_info
25
+
26
+ call_slot :db_items
27
+ call_slot :cmd_read
28
+ call_slot :cmd_write
29
+ call_slot :cmd_delete
30
+ end
31
+
32
+
33
+ class StatService < Service
34
+ def initialize
35
+ @methods = {}
36
+ public_methods.each {|name|
37
+ if name =~ /^stat_(.*)$/
38
+ @methods[$~[1]] = method(name)
39
+ end
40
+ }
41
+
42
+ @start_time = Time.now
43
+ end
44
+
45
+ def rpc_stat(cmd)
46
+ if m = @methods[cmd]
47
+ m.call
48
+ else
49
+ raise "no such status"
50
+ end
51
+ end
52
+
53
+ def stat_uptime
54
+ uptime = Time.now - @start_time
55
+ uptime.to_i
56
+ end
57
+
58
+ def stat_time
59
+ Time.now.utc.to_i
60
+ end
61
+
62
+ def stat_pid
63
+ Process.pid
64
+ end
65
+
66
+ def stat_version
67
+ VERSION
68
+ end
69
+
70
+ def stat_cs_address
71
+ ConfigBus.get_cs_address
72
+ end
73
+
74
+ def stat_nodes
75
+ StatBus.membership_info
76
+ end
77
+
78
+ def stat_fault
79
+ StatBus.fault_info
80
+ end
81
+
82
+ def stat_replset
83
+ StatBus.replset_info
84
+ end
85
+
86
+ ebus_connect :RPCBus,
87
+ :stat => :rpc_stat
88
+ end
89
+
90
+
91
+ end