ls4 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/COPYING +661 -0
- data/ChangeLog +9 -0
- data/NOTICE +8 -0
- data/README.rdoc +61 -0
- data/bin/ls4-cs +3 -0
- data/bin/ls4-ds +3 -0
- data/bin/ls4-gw +3 -0
- data/bin/ls4-standalone +3 -0
- data/bin/ls4cmd +3 -0
- data/bin/ls4ctl +3 -0
- data/bin/ls4rpc +3 -0
- data/bin/ls4stat +3 -0
- data/bin/ls4top +3 -0
- data/lib/ls4/command/cmd.rb +241 -0
- data/lib/ls4/command/cs.rb +190 -0
- data/lib/ls4/command/ctl.rb +278 -0
- data/lib/ls4/command/ds.rb +335 -0
- data/lib/ls4/command/gw.rb +256 -0
- data/lib/ls4/command/rpc.rb +172 -0
- data/lib/ls4/command/standalone.rb +318 -0
- data/lib/ls4/command/stat.rb +244 -0
- data/lib/ls4/command/top.rb +291 -0
- data/lib/ls4/default.rb +26 -0
- data/lib/ls4/lib/cclog.rb +220 -0
- data/lib/ls4/lib/ebus.rb +553 -0
- data/lib/ls4/lib/vbcode.rb +228 -0
- data/lib/ls4/logic/fault_detector.rb +212 -0
- data/lib/ls4/logic/membership.rb +253 -0
- data/lib/ls4/logic/node.rb +66 -0
- data/lib/ls4/logic/okey.rb +45 -0
- data/lib/ls4/logic/tsv_data.rb +81 -0
- data/lib/ls4/logic/weight.rb +166 -0
- data/lib/ls4/service/balance.rb +62 -0
- data/lib/ls4/service/base.rb +29 -0
- data/lib/ls4/service/bus.rb +37 -0
- data/lib/ls4/service/config.rb +63 -0
- data/lib/ls4/service/config_cs.rb +33 -0
- data/lib/ls4/service/config_ds.rb +56 -0
- data/lib/ls4/service/config_gw.rb +42 -0
- data/lib/ls4/service/data_client.rb +122 -0
- data/lib/ls4/service/data_server.rb +168 -0
- data/lib/ls4/service/data_server_url.rb +83 -0
- data/lib/ls4/service/gateway.rb +375 -0
- data/lib/ls4/service/gateway_ro.rb +91 -0
- data/lib/ls4/service/gw_http.rb +821 -0
- data/lib/ls4/service/heartbeat.rb +182 -0
- data/lib/ls4/service/log.rb +81 -0
- data/lib/ls4/service/master_select.rb +148 -0
- data/lib/ls4/service/mds.rb +292 -0
- data/lib/ls4/service/mds_cache.rb +294 -0
- data/lib/ls4/service/mds_cache_mem.rb +63 -0
- data/lib/ls4/service/mds_cache_memcached.rb +65 -0
- data/lib/ls4/service/mds_ha.rb +176 -0
- data/lib/ls4/service/mds_memcache.rb +209 -0
- data/lib/ls4/service/mds_tc.rb +508 -0
- data/lib/ls4/service/mds_tt.rb +472 -0
- data/lib/ls4/service/membership.rb +331 -0
- data/lib/ls4/service/process.rb +90 -0
- data/lib/ls4/service/rpc.rb +50 -0
- data/lib/ls4/service/rpc_cs.rb +101 -0
- data/lib/ls4/service/rpc_ds.rb +96 -0
- data/lib/ls4/service/rpc_gw.rb +255 -0
- data/lib/ls4/service/rts.rb +94 -0
- data/lib/ls4/service/rts_file.rb +76 -0
- data/lib/ls4/service/rts_memory.rb +55 -0
- data/lib/ls4/service/slave.rb +132 -0
- data/lib/ls4/service/stat.rb +91 -0
- data/lib/ls4/service/stat_cs.rb +25 -0
- data/lib/ls4/service/stat_ds.rb +40 -0
- data/lib/ls4/service/stat_gw.rb +25 -0
- data/lib/ls4/service/storage.rb +116 -0
- data/lib/ls4/service/storage_dir.rb +201 -0
- data/lib/ls4/service/sync.rb +206 -0
- data/lib/ls4/service/time_check.rb +80 -0
- data/lib/ls4/service/ulog.rb +159 -0
- data/lib/ls4/service/ulog_file.rb +398 -0
- data/lib/ls4/service/ulog_memory.rb +53 -0
- data/lib/ls4/service/weight.rb +134 -0
- data/lib/ls4/version.rb +5 -0
- data/test/01_add_get_remove.rt +84 -0
- data/test/02_read.rt +61 -0
- data/test/03_getd_readd.rt +69 -0
- data/test/04_version_time.rt +170 -0
- data/test/05_version_name.rt +161 -0
- data/test/06_http_get_set_remove_1.rt +119 -0
- data/test/07_http_get_set_remove_2.rt +116 -0
- data/test/08_read_only_time.rt +177 -0
- data/test/09_read_only_name.rt +173 -0
- data/test/10_http_get_set_remove_3.rt +73 -0
- data/test/11_mds_cache_memcached.rt +88 -0
- data/test/12_mds_cache_local_memory.rt +86 -0
- data/test/13_memcache_mds.rt +84 -0
- data/test/14_delete.rt +63 -0
- data/test/15_standalone.rt +71 -0
- data/test/chukan.rb +516 -0
- data/test/common.rb +250 -0
- data/test/load_test.rb +79 -0
- data/test/load_test_offload.rb +86 -0
- metadata +295 -0
@@ -0,0 +1,66 @@
|
|
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
|
+
Address = MessagePack::RPC::Address
|
22
|
+
|
23
|
+
class Node
|
24
|
+
def initialize(nid=0, address=nil, name=nil, rsids=[], location=nil)
|
25
|
+
@nid = nid
|
26
|
+
@address = address
|
27
|
+
@name = name
|
28
|
+
@rsids = rsids
|
29
|
+
@location = location
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :nid
|
33
|
+
attr_accessor :address
|
34
|
+
attr_accessor :name
|
35
|
+
attr_accessor :rsids
|
36
|
+
attr_accessor :location
|
37
|
+
|
38
|
+
def session
|
39
|
+
$net.get_session(*@address)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"Node<#{@nid} #{@address} #{@name.dump} #{@rsids.inspect} #{@location.inspect}>"
|
44
|
+
end
|
45
|
+
|
46
|
+
def ==(o)
|
47
|
+
# FIXME
|
48
|
+
@nid == o.nid && @address == o.address
|
49
|
+
end
|
50
|
+
|
51
|
+
public
|
52
|
+
def to_msgpack(out = '')
|
53
|
+
[@nid, @address.dump, @name, @rsids, @location].to_msgpack(out)
|
54
|
+
end
|
55
|
+
def from_msgpack(obj)
|
56
|
+
@nid = obj[0]
|
57
|
+
@address = Address.load(obj[1])
|
58
|
+
@name = obj[2]
|
59
|
+
@rsids = obj[3]
|
60
|
+
@location = obj[4]
|
61
|
+
self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 ObjectKey
|
22
|
+
def initialize(key=nil, vtime=nil, rsid=nil)
|
23
|
+
@key = key
|
24
|
+
@vtime = vtime.to_i
|
25
|
+
@rsid = rsid.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :key
|
29
|
+
attr_reader :vtime
|
30
|
+
attr_reader :rsid
|
31
|
+
|
32
|
+
def to_msgpack(out = '')
|
33
|
+
[@key, @vtime, @rsid].to_msgpack(out)
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_msgpack(obj)
|
37
|
+
@key = obj[0]
|
38
|
+
@vtime = obj[1].to_i
|
39
|
+
@rsid = obj[2].to_i
|
40
|
+
self
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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 TSVData
|
22
|
+
def initialize
|
23
|
+
update_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_hash
|
27
|
+
@hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def open(path)
|
31
|
+
@path = path
|
32
|
+
read
|
33
|
+
end
|
34
|
+
|
35
|
+
def close
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def on_change
|
40
|
+
update_hash
|
41
|
+
write
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_hash
|
45
|
+
@hash = Digest::SHA1.digest(to_msgpack)
|
46
|
+
write
|
47
|
+
end
|
48
|
+
|
49
|
+
if RUBY_VERSION >= "1.9"
|
50
|
+
def tsv_read(path=@path, &block)
|
51
|
+
CSV.open(path, "r", :col_sep => "\t") do |csv|
|
52
|
+
csv.each {|row|
|
53
|
+
yield row
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
def tsv_write(path=@path, &block)
|
58
|
+
tmp_path = "#{path}.tmp"
|
59
|
+
CSV.open(tmp_path, "w", :col_sep => "\t") do |csv|
|
60
|
+
yield csv
|
61
|
+
end
|
62
|
+
File.rename(tmp_path, path)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
def tsv_read(path=@path, &block)
|
66
|
+
CSV.open(path, "r", "\t") do |row|
|
67
|
+
yield row
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def tsv_write(path=@path, &block)
|
71
|
+
tmp_path = "#{path}.tmp"
|
72
|
+
CSV.open(tmp_path, "w", "\t") do |writer|
|
73
|
+
yield writer
|
74
|
+
end
|
75
|
+
File.rename(tmp_path, path)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,166 @@
|
|
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 WeightInfo
|
22
|
+
DEFAULT_WEIGHT = 10
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@map = {} # {rsid => weight}
|
26
|
+
update_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def open(path)
|
30
|
+
@path = path
|
31
|
+
read
|
32
|
+
end
|
33
|
+
|
34
|
+
def close
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_weight(rsid, weight)
|
38
|
+
if @map[rsid] == weight
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
@map[rsid] = weight
|
42
|
+
on_change
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def reset_weight(rsid)
|
47
|
+
unless @map.delete(rsid)
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
on_change
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_defaults(rsids)
|
55
|
+
#@map.reject! {|rsid,weight|
|
56
|
+
# !rsids.include?(rsid)
|
57
|
+
#}
|
58
|
+
rsids.each {|rsid|
|
59
|
+
@map[rsid] ||= DEFAULT_WEIGHT
|
60
|
+
}
|
61
|
+
on_change
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_weight(rsid)
|
66
|
+
@map[rsid] || DEFAULT_WEIGHT
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_registered_rsids
|
70
|
+
@map.keys
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_registered_weights
|
74
|
+
@map.dup
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_all_with_default(rsids)
|
78
|
+
result = {}
|
79
|
+
rsids.each {|rsid|
|
80
|
+
result[rsid] = @map[rsid] || DEFAULT_WEIGHT
|
81
|
+
}
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_hash
|
86
|
+
@hash
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_msgpack(out = '')
|
90
|
+
@map.to_msgpack(out)
|
91
|
+
end
|
92
|
+
|
93
|
+
def from_msgpack(obj)
|
94
|
+
@map = obj
|
95
|
+
on_change
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
def read
|
101
|
+
return nil unless @path
|
102
|
+
# FIXME
|
103
|
+
end
|
104
|
+
|
105
|
+
def write
|
106
|
+
return nil unless @path
|
107
|
+
# FIXME
|
108
|
+
end
|
109
|
+
|
110
|
+
def on_change
|
111
|
+
update_hash
|
112
|
+
write
|
113
|
+
end
|
114
|
+
|
115
|
+
def update_hash
|
116
|
+
@hash = Digest::SHA1.digest(to_msgpack)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
=begin
|
122
|
+
class WeightBalancer < WeightInfo
|
123
|
+
def initialize
|
124
|
+
super
|
125
|
+
@array = []
|
126
|
+
@rsids = []
|
127
|
+
@rr = 0
|
128
|
+
calc
|
129
|
+
end
|
130
|
+
|
131
|
+
def set_rsids(rsids)
|
132
|
+
@rsids = rsids
|
133
|
+
calc
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
|
137
|
+
def select_next_rsid
|
138
|
+
if @array.empty?
|
139
|
+
raise "no replica set is registered"
|
140
|
+
end
|
141
|
+
@rr += 1
|
142
|
+
@rr = 0 if @rr >= @array.size
|
143
|
+
@array[@rr]
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
def on_change
|
148
|
+
super
|
149
|
+
calc
|
150
|
+
end
|
151
|
+
|
152
|
+
def calc
|
153
|
+
array = []
|
154
|
+
@rsids.each {|rsid|
|
155
|
+
weight = @map[rsid] || DEFAULT_WEIGHT
|
156
|
+
weight.times {
|
157
|
+
array << rsid
|
158
|
+
}
|
159
|
+
}
|
160
|
+
@array = array.shuffle
|
161
|
+
end
|
162
|
+
end
|
163
|
+
=end
|
164
|
+
|
165
|
+
|
166
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 BalanceBus < Bus
|
22
|
+
call_slot :select_next_rsid
|
23
|
+
signal_slot :update_weight
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class RoutRobinWeightBalanceService < Service
|
28
|
+
def initialize
|
29
|
+
@array = []
|
30
|
+
#@random = Random.new
|
31
|
+
@rr = 0
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_weight(active_rsids=nil)
|
35
|
+
active_rsids ||= MembershipBus.get_active_rsids
|
36
|
+
array = []
|
37
|
+
active_rsids.each {|rsid|
|
38
|
+
w = WeightBus.get_weight(rsid)
|
39
|
+
w.times {
|
40
|
+
array << rsid
|
41
|
+
}
|
42
|
+
}
|
43
|
+
#@array = array.sort_by {|rsid| @random.rand }
|
44
|
+
@array = array.sort_by {|rsid| rand }
|
45
|
+
end
|
46
|
+
|
47
|
+
def select_next_rsid(key)
|
48
|
+
if @array.empty?
|
49
|
+
raise "no replica set is registered"
|
50
|
+
end
|
51
|
+
@rr += 1
|
52
|
+
@rr = 0 if @rr >= @array.size
|
53
|
+
@array[@rr]
|
54
|
+
end
|
55
|
+
|
56
|
+
ebus_connect :BalanceBus,
|
57
|
+
:select_next_rsid,
|
58
|
+
:update_weight
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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 Service < EventBus::Singleton
|
22
|
+
def self.init
|
23
|
+
ebus_bind!
|
24
|
+
instance
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|