roma 0.8.13 → 0.8.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +20 -0
- data/Gemfile +17 -0
- data/Rakefile +2 -2
- data/ruby/server/bin/cpdb +6 -0
- data/ruby/server/bin/safecopy_integration_test +10 -0
- data/ruby/server/bin/safecopy_test +10 -0
- data/ruby/server/lib/roma/async_process.rb +87 -3
- data/ruby/server/lib/roma/command/sys_command_receiver.rb +181 -5
- data/ruby/server/lib/roma/command/vn_command_receiver.rb +9 -3
- data/ruby/server/lib/roma/event/con_pool.rb +1 -1
- data/ruby/server/lib/roma/event/handler.rb +11 -5
- data/ruby/server/lib/roma/messaging/con_pool.rb +1 -1
- data/ruby/server/lib/roma/romad.rb +3 -1
- data/ruby/server/lib/roma/stats.rb +19 -1
- data/ruby/server/lib/roma/storage/basic_storage.rb +342 -82
- data/ruby/server/lib/roma/storage/dummy_storage.rb +0 -2
- data/ruby/server/lib/roma/storage/rh_storage.rb +13 -12
- data/ruby/server/lib/roma/storage/sqlite3_storage.rb +4 -0
- data/ruby/server/lib/roma/storage/tc_storage.rb +6 -20
- data/ruby/server/lib/roma/tools/cpdb.rb +103 -0
- data/ruby/server/lib/roma/tools/safecopy_integration_test.rb +247 -0
- data/ruby/server/lib/roma/tools/safecopy_test.rb +184 -0
- data/ruby/server/lib/roma/tools/simple_bench.rb +16 -16
- data/ruby/server/lib/roma/version.rb +1 -1
- data/ruby/server/test/t_storage.rb +223 -41
- metadata +25 -20
@@ -0,0 +1,184 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'date'
|
4
|
+
require 'roma/client/rclient'
|
5
|
+
|
6
|
+
@cnt = 0
|
7
|
+
@tmax = 0
|
8
|
+
@tmin = 100
|
9
|
+
|
10
|
+
Thread.new do
|
11
|
+
sleep_time=10
|
12
|
+
while(true)
|
13
|
+
sleep sleep_time
|
14
|
+
printf("qps=%d max=%f min=%f ave=%f\n",@cnt/sleep_time,@tmax,@tmin,sleep_time/@cnt.to_f)
|
15
|
+
@cnt=0
|
16
|
+
@tmax=0
|
17
|
+
@tmin=100
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def random_rquest_sender(ini_nodes, n)
|
22
|
+
puts __method__
|
23
|
+
rc=Roma::Client::RomaClient.new(ini_nodes)
|
24
|
+
|
25
|
+
loop do
|
26
|
+
i=rand(n)
|
27
|
+
ts = DateTime.now
|
28
|
+
case rand(3)
|
29
|
+
when 0
|
30
|
+
res=rc.set(i.to_s,'hoge'+i.to_s)
|
31
|
+
puts "set k=#{i} #{res}" if res==nil || res.chomp != 'STORED'
|
32
|
+
when 1
|
33
|
+
res=rc.get(i.to_s)
|
34
|
+
puts "get k=#{i} #{res}" if res == :error
|
35
|
+
when 2
|
36
|
+
res=rc.delete(i.to_s)
|
37
|
+
puts "del k=#{i} #{res}" if res != 'DELETED' && res != 'NOT_FOUND'
|
38
|
+
end
|
39
|
+
t=(DateTime.now - ts).to_f * 86400.0
|
40
|
+
@tmax=t if t > @tmax
|
41
|
+
@tmin=t if t < @tmin
|
42
|
+
@cnt+=1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_counts(ini_nodes, range, c)
|
47
|
+
puts "#{__method__} #{range} #{c}"
|
48
|
+
rc=Roma::Client::RomaClient.new(ini_nodes)
|
49
|
+
|
50
|
+
range.each do |i|
|
51
|
+
ts = DateTime.now
|
52
|
+
res=rc.set("key_#{i}","#{c}")
|
53
|
+
puts "set k=#{i} #{res}" if res==nil || res.chomp != 'STORED'
|
54
|
+
t=(DateTime.now - ts).to_f * 86400.0
|
55
|
+
@tmax=t if t > @tmax
|
56
|
+
@tmin=t if t < @tmin
|
57
|
+
@cnt+=1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_count(ini_nodes, range, c)
|
62
|
+
puts "#{__method__} #{range} #{c}"
|
63
|
+
rc=Roma::Client::RomaClient.new(ini_nodes)
|
64
|
+
|
65
|
+
range.each do |i|
|
66
|
+
ts = DateTime.now
|
67
|
+
res = rc.get("key_#{i}")
|
68
|
+
if res != c.to_s
|
69
|
+
puts "error k=key_#{i} #{res}"
|
70
|
+
end
|
71
|
+
t=(DateTime.now - ts).to_f * 86400.0
|
72
|
+
@tmax=t if t > @tmax
|
73
|
+
@tmin=t if t < @tmin
|
74
|
+
@cnt+=1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def send_cmd(nid, cmd)
|
79
|
+
conn = Roma::Client::ConPool.instance.get_connection(nid)
|
80
|
+
conn.write "#{cmd}\r\n"
|
81
|
+
ret = conn.gets
|
82
|
+
Roma::Client::ConPool.instance.return_connection(nid, conn)
|
83
|
+
ret
|
84
|
+
rescue =>e
|
85
|
+
STDERR.puts "#{nid} #{cmd} #{e.inspect}"
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def stats(nid, regexp=nil)
|
90
|
+
conn = Roma::Client::ConPool.instance.get_connection(nid)
|
91
|
+
if regexp
|
92
|
+
conn.write "stats #{regexp}\r\n"
|
93
|
+
else
|
94
|
+
conn.write "stats\r\n"
|
95
|
+
end
|
96
|
+
ret = ""
|
97
|
+
while(conn.gets != "END\r\n")
|
98
|
+
ret << $_
|
99
|
+
end
|
100
|
+
Roma::Client::ConPool.instance.return_connection(nid, conn)
|
101
|
+
ret
|
102
|
+
rescue =>e
|
103
|
+
STDERR.puts "#{nid} #{e.inspect}"
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
def safecopy_stats(nid)
|
108
|
+
ret = stats(nid, 'storage.safecopy_stats')
|
109
|
+
return eval $1 if ret =~ /^.+\s(\[.+\])/
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_storage_status(nid, fno, stat)
|
114
|
+
send_cmd(ARGV[0], "set_storage_status #{fno} #{stat}")
|
115
|
+
end
|
116
|
+
|
117
|
+
def wait_status(nid, fno, stat)
|
118
|
+
while safecopy_stats(nid)[fno] != stat
|
119
|
+
sleep 5
|
120
|
+
end
|
121
|
+
stat
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_change_status
|
126
|
+
|
127
|
+
puts "write (0...10000) = 0"
|
128
|
+
set_counts(ARGV, 0...10000, 0)
|
129
|
+
Thread.new { random_rquest_sender(ARGV, 10000) }
|
130
|
+
|
131
|
+
nid = ARGV[0]
|
132
|
+
|
133
|
+
sleep(5)
|
134
|
+
|
135
|
+
10.times do |n|
|
136
|
+
t = Thread.new { set_counts(ARGV, (n * 1000)...(n * 1000 + 2000), n * 10 + 1) }
|
137
|
+
p set_storage_status(nid, n, 'safecopy')
|
138
|
+
p wait_status(nid, n, :safecopy_flushed)
|
139
|
+
t.join
|
140
|
+
p safecopy_stats(nid)
|
141
|
+
|
142
|
+
#sleep(30)
|
143
|
+
t = Thread.new { set_counts(ARGV, (n * 1000 + 500)...(n * 1000 + 2000), n * 10 + 2) }
|
144
|
+
p set_storage_status(nid, n, 'normal')
|
145
|
+
p wait_status(nid, n, :normal)
|
146
|
+
t.join
|
147
|
+
p safecopy_stats(nid)
|
148
|
+
check_count(ARGV, (n * 1000)...(n * 1000 + 500), n * 10 + 1)
|
149
|
+
check_count(ARGV, (n * 1000 + 500)...(n * 1000 + 2000), n * 10 + 2)
|
150
|
+
if (n * 1000 + 2000) < 10000
|
151
|
+
check_count(ARGV, (n * 1000 + 2000)...10000, 0)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_round
|
157
|
+
n = 0
|
158
|
+
1000.times do |i|
|
159
|
+
set_counts(ARGV, 0...10000, i)
|
160
|
+
check_count(ARGV, 0...10000, i)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
param = { :num=>10000, :th=>1 }
|
165
|
+
|
166
|
+
opts = OptionParser.new
|
167
|
+
|
168
|
+
opts.on("-r", "--round", "round request"){|v| param[:round] = v }
|
169
|
+
|
170
|
+
opts.banner = "usage:#{File.basename($0)} [options] addr:port"
|
171
|
+
opts.parse!(ARGV)
|
172
|
+
|
173
|
+
if ARGV.length == 0
|
174
|
+
STDERR.puts opts.help
|
175
|
+
exit
|
176
|
+
end
|
177
|
+
|
178
|
+
if param.key?(:round)
|
179
|
+
test_round
|
180
|
+
else
|
181
|
+
test_change_status
|
182
|
+
end
|
183
|
+
|
184
|
+
puts "#{File.basename($0)} has done."
|
@@ -3,18 +3,18 @@ require 'optparse'
|
|
3
3
|
require 'date'
|
4
4
|
require 'roma/client/rclient'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
@cnt = 0
|
7
|
+
@tmax = 0
|
8
|
+
@tmin = 100
|
9
9
|
|
10
10
|
Thread.new do
|
11
11
|
sleep_time=10
|
12
12
|
while(true)
|
13
13
|
sleep sleep_time
|
14
|
-
printf("qps=%d max=%f min=%f ave=%f\n"
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
printf("qps=%d max=%f min=%f ave=%f\n",@cnt/sleep_time,@tmax,@tmin,sleep_time/@cnt.to_f)
|
15
|
+
@cnt=0
|
16
|
+
@tmax=0
|
17
|
+
@tmin=100
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -37,9 +37,9 @@ def random_request_sender(ini_nodes, n)
|
|
37
37
|
puts "del k=#{i} #{res}" if res != 'DELETED' && res != 'NOT_FOUND'
|
38
38
|
end
|
39
39
|
t=(DateTime.now - ts).to_f * 86400.0
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
@tmax=t if t > @tmax
|
41
|
+
@tmin=t if t < @tmin
|
42
|
+
@cnt+=1
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -52,9 +52,9 @@ def set_sequence(ini_nodes, n)
|
|
52
52
|
res=rc.set("key_#{i}","value_#{i}")
|
53
53
|
puts "set k=#{i} #{res}" if res==nil || res.chomp != 'STORED'
|
54
54
|
t=(DateTime.now - ts).to_f * 86400.0
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
@tmax=t if t > @tmax
|
56
|
+
@tmin=t if t < @tmin
|
57
|
+
@cnt+=1
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -67,9 +67,9 @@ def get_sequence(ini_nodes, n)
|
|
67
67
|
res=rc.get("key_#{i}")
|
68
68
|
puts "get #{i} #{res}" if res != "value_#{i}"
|
69
69
|
t=(DateTime.now - ts).to_f * 86400.0
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
@tmax=t if t > @tmax
|
71
|
+
@tmin=t if t < @tmin
|
72
|
+
@cnt+=1
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -36,7 +36,7 @@ class TCStorageTest < Test::Unit::TestCase
|
|
36
36
|
|
37
37
|
def test_set_get
|
38
38
|
assert_equal( 'abc_data',@st.set(0,'abc',0,0xffffffff,'abc_data')[4])
|
39
|
-
assert_equal( 'abc_data', @st.get(0,'abc',0)
|
39
|
+
assert_equal( 'abc_data', @st.get(0,'abc',0) )
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_set_delete
|
@@ -435,61 +435,63 @@ class TCStorageTest < Test::Unit::TestCase
|
|
435
435
|
}
|
436
436
|
end
|
437
437
|
|
438
|
-
def
|
438
|
+
def test_each_vn_dump_in_normal
|
439
439
|
n=100
|
440
440
|
n.times{|i|
|
441
441
|
@st.set(0,"key#{i}",0,0x7fffffff,"val#{i}")
|
442
442
|
}
|
443
|
-
|
444
|
-
|
445
|
-
count = 0
|
446
|
-
open("storage_test_dump/#{@st.hdiv[0]}.dump",'rb'){|f|
|
447
|
-
until(f.eof?)
|
448
|
-
b1 = f.read(5 * 4)
|
449
|
-
vn, last, clk, expt, klen = b1.unpack('NNNNN')
|
450
|
-
key = f.read(klen)
|
451
|
-
b2 = f.read(4)
|
452
|
-
vlen = b2.unpack('N')[0]
|
453
|
-
val = f.read(vlen)
|
454
|
-
|
455
|
-
count += 1
|
456
|
-
assert_equal('key',key[0..2])
|
457
|
-
assert_equal('val',val[0..2])
|
458
|
-
assert_equal(val[3..-1],key[3..-1] )
|
459
|
-
end
|
443
|
+
(90..99).each{|i|
|
444
|
+
@st.delete(0, "key#{i}", 0)
|
460
445
|
}
|
461
|
-
assert_equal(n,count)
|
462
|
-
rmtestdir('storage_test_dump')
|
463
|
-
|
464
|
-
@st.dump_file('storage_test_dump',{0=>0})
|
465
446
|
count = 0
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
assert_equal(val[3..-1],key[3..-1] )
|
479
|
-
end
|
447
|
+
@st.each_vn_dump(0){|data|
|
448
|
+
vn, last, clk, expt, klen = data.slice!(0..19).unpack('NNNNN')
|
449
|
+
k = data.slice!(0..(klen-1))
|
450
|
+
vlen, = data.slice!(0..3).unpack('N')
|
451
|
+
v = data
|
452
|
+
count += 1
|
453
|
+
# puts "#{vn} #{last} #{clk} #{expt} #{klen} #{k} #{vlen} #{v}"
|
454
|
+
assert_equal('key',k[0..2])
|
455
|
+
assert_equal('val',v[0..2]) if k[3..-1].to_i < 90
|
456
|
+
|
457
|
+
assert_nil( @st.load_stream_dump(vn, last, clk, expt, k, v) )
|
458
|
+
@st.load_stream_dump(2, last, clk, expt, k, v)
|
480
459
|
}
|
460
|
+
assert_equal(100,count)
|
461
|
+
|
462
|
+
count = 0
|
463
|
+
@st.each_vn_dump(1){|data| count += 1 }
|
481
464
|
assert_equal(0,count )
|
482
|
-
|
465
|
+
|
466
|
+
count = 0
|
467
|
+
@st.each_vn_dump(2){|data| count += 1 }
|
468
|
+
assert_equal(100,count )
|
483
469
|
end
|
484
470
|
|
485
|
-
def
|
471
|
+
def test_each_vn_dump_not_normal
|
472
|
+
dn = @st.instance_eval{ @hdiv[0] }
|
473
|
+
|
486
474
|
n=100
|
487
475
|
n.times{|i|
|
488
476
|
@st.set(0,"key#{i}",0,0x7fffffff,"val#{i}")
|
489
477
|
}
|
478
|
+
|
479
|
+
# :normal -> :safecopy_flushing
|
480
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
481
|
+
# :safecopy_flushing -> :safecopy_flushed
|
482
|
+
assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
|
483
|
+
|
484
|
+
(80..99).each{|i|
|
485
|
+
@st.set(0,"key#{i}",0,0x7fffffff,"val#{i + 1}")
|
486
|
+
}
|
487
|
+
|
488
|
+
# :safecopy_flushed -> :cachecleaning
|
489
|
+
assert_equal(:cachecleaning, @st.set_db_stat(dn, :cachecleaning))
|
490
|
+
|
490
491
|
(90..99).each{|i|
|
491
492
|
@st.delete(0, "key#{i}", 0)
|
492
493
|
}
|
494
|
+
|
493
495
|
count = 0
|
494
496
|
@st.each_vn_dump(0){|data|
|
495
497
|
vn, last, clk, expt, klen = data.slice!(0..19).unpack('NNNNN')
|
@@ -498,8 +500,14 @@ class TCStorageTest < Test::Unit::TestCase
|
|
498
500
|
v = data
|
499
501
|
count += 1
|
500
502
|
# puts "#{vn} #{last} #{clk} #{expt} #{klen} #{k} #{vlen} #{v}"
|
501
|
-
|
502
|
-
|
503
|
+
assert_match(/key\d/, k)
|
504
|
+
if k[3..-1].to_i < 80
|
505
|
+
assert_match("val#{k[3..-1]}", v)
|
506
|
+
elsif k[3..-1].to_i < 90
|
507
|
+
assert_match("val#{k[3..-1].to_i + 1}", v)
|
508
|
+
else
|
509
|
+
assert(vlen == 0)
|
510
|
+
end
|
503
511
|
|
504
512
|
assert_nil( @st.load_stream_dump(vn, last, clk, expt, k, v) )
|
505
513
|
@st.load_stream_dump(2, last, clk, expt, k, v)
|
@@ -515,6 +523,180 @@ class TCStorageTest < Test::Unit::TestCase
|
|
515
523
|
assert_equal(100,count )
|
516
524
|
end
|
517
525
|
|
526
|
+
def test_db_stat
|
527
|
+
assert_nil(@st.instance_eval{ @hdbc[0] })
|
528
|
+
# :normal -> error case
|
529
|
+
assert_equal(false, @st.set_db_stat(0, :safecopy_flushed))
|
530
|
+
assert_equal(false, @st.set_db_stat(0, :cachecleaning))
|
531
|
+
assert_equal(false, @st.set_db_stat(0, :normal))
|
532
|
+
# :normal -> :safecopy_flushing
|
533
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(0, :safecopy_flushing))
|
534
|
+
assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[0] })
|
535
|
+
assert(@st.instance_eval{ @hdbc[0] })
|
536
|
+
|
537
|
+
# :safecopy_flushing -> error case
|
538
|
+
assert_equal(false, @st.set_db_stat(0, :safecopy_flushing))
|
539
|
+
assert_equal(false, @st.set_db_stat(0, :cachecleaning))
|
540
|
+
assert_equal(false, @st.set_db_stat(0, :normal))
|
541
|
+
# :safecopy_flushing -> :safecopy_flushed
|
542
|
+
assert_equal(:safecopy_flushed, @st.set_db_stat(0, :safecopy_flushed))
|
543
|
+
assert_equal(:safecopy_flushed, @st.instance_eval{ @dbs[0] })
|
544
|
+
assert(@st.instance_eval{ @hdbc[0] })
|
545
|
+
|
546
|
+
# :safecopy_flushed -> error case
|
547
|
+
assert_equal(false, @st.set_db_stat(0, :safecopy_flushing))
|
548
|
+
assert_equal(false, @st.set_db_stat(0, :safecopy_flushed))
|
549
|
+
assert_equal(false, @st.set_db_stat(0, :normal))
|
550
|
+
# :safecopy_flushed -> :cachecleaning
|
551
|
+
assert_equal(:cachecleaning, @st.set_db_stat(0, :cachecleaning))
|
552
|
+
assert_equal(:cachecleaning, @st.instance_eval{ @dbs[0] })
|
553
|
+
assert(@st.instance_eval{ @hdbc[0] })
|
554
|
+
|
555
|
+
# :cachecleaning -> error case
|
556
|
+
assert_equal(false, @st.set_db_stat(0, :safecopy_flushed))
|
557
|
+
assert_equal(false, @st.set_db_stat(0, :cachecleaning))
|
558
|
+
# :cachecleaning -> :safecopy_flushing
|
559
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(0, :safecopy_flushing))
|
560
|
+
assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[0] })
|
561
|
+
assert_equal(:safecopy_flushed, @st.set_db_stat(0, :safecopy_flushed))
|
562
|
+
assert_equal(:cachecleaning, @st.set_db_stat(0, :cachecleaning))
|
563
|
+
assert(@st.instance_eval{ @hdbc[0] })
|
564
|
+
# :cachecleaning -> :normal
|
565
|
+
assert_equal(:normal, @st.set_db_stat(0, :normal))
|
566
|
+
assert_equal(:normal, @st.instance_eval{ @dbs[0] })
|
567
|
+
assert_nil(@st.instance_eval{ @hdbc[0] })
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_clock_along_status
|
571
|
+
vn = 0
|
572
|
+
dn = @st.instance_eval{ @hdiv[vn] }
|
573
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
574
|
+
assert( @st.get_context(vn, 'abc', 0)[2] == 0 )
|
575
|
+
# :normal -> :safecopy_flushing
|
576
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
577
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
578
|
+
assert( @st.get_context(vn, 'abc', 0)[2] == 1 )
|
579
|
+
# :safecopy_flushing -> :safecopy_flushed
|
580
|
+
assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
|
581
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
582
|
+
assert( @st.get_context(vn, 'abc', 0)[2] == 2 )
|
583
|
+
# :safecopy_flushed -> :cachecleaning
|
584
|
+
assert_equal(:cachecleaning, @st.set_db_stat(dn, :cachecleaning))
|
585
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
586
|
+
assert( @st.get_context(vn, 'abc', 0)[2] == 3 )
|
587
|
+
# :cachecleaning -> :normal
|
588
|
+
assert_equal(:normal, @st.set_db_stat(dn, :normal))
|
589
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
590
|
+
assert( @st.get_context(vn, 'abc', 0)[2] == 4 )
|
591
|
+
end
|
592
|
+
|
593
|
+
def test_set_get_in_safecopy
|
594
|
+
vn = 0
|
595
|
+
dn = @st.instance_eval{ @hdiv[vn] }
|
596
|
+
# :normal -> :safecopy_flushing
|
597
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
598
|
+
assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[dn] })
|
599
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
600
|
+
assert_equal('abc_data', @st.get(vn,'abc',0) )
|
601
|
+
# not stored
|
602
|
+
assert_nil(@st.instance_eval{ @hdb[dn].get('abc') })
|
603
|
+
# stored
|
604
|
+
assert(@st.instance_eval{ @hdbc[dn].get('abc') })
|
605
|
+
|
606
|
+
# :safecopy_flushing -> :safecopy_flushed
|
607
|
+
assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
|
608
|
+
assert_equal(:safecopy_flushed, @st.instance_eval{ @dbs[dn] })
|
609
|
+
assert_equal('def_data', @st.set(vn,'def',0,0xffffffff,'def_data')[4])
|
610
|
+
assert_equal('def_data', @st.get(vn,'def',0) )
|
611
|
+
# not stored
|
612
|
+
assert_nil(@st.instance_eval{ @hdb[dn].get('def') })
|
613
|
+
# stored
|
614
|
+
assert(@st.instance_eval{ @hdbc[dn].get('def') })
|
615
|
+
end
|
616
|
+
|
617
|
+
def test_set_get_in_cachecleaning
|
618
|
+
vn = 0
|
619
|
+
dn = @st.instance_eval{ @hdiv[vn] }
|
620
|
+
assert_equal( 'abc_data',@st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
621
|
+
assert_equal( 'abc_data', @st.get(vn,'abc',0) ) # database
|
622
|
+
# :normal -> :safecopy_flushing
|
623
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
624
|
+
# :safecopy_flushing -> :safecopy_flushed
|
625
|
+
assert_equal(:safecopy_flushed, @st.set_db_stat(dn, :safecopy_flushed))
|
626
|
+
assert_equal( 'abc_data1',@st.set(vn,'abc',0,0xffffffff,'abc_data1')[4])
|
627
|
+
assert_equal( 'abc_data1', @st.get(vn,'abc',0) ) # cache
|
628
|
+
# :safecopy_flushed -> :cachecleaning
|
629
|
+
assert_equal(:cachecleaning, @st.set_db_stat(dn, :cachecleaning))
|
630
|
+
assert_equal( 'abc_data1', @st.get(vn,'abc',0) ) # cache
|
631
|
+
assert_equal( 'abc_data2',@st.set(vn,'abc',0,0xffffffff,'abc_data2')[4])
|
632
|
+
assert_equal( 'abc_data2', @st.get(vn,'abc',0) ) # database
|
633
|
+
end
|
634
|
+
|
635
|
+
def test_out_cache
|
636
|
+
vn = 0
|
637
|
+
dn = @st.instance_eval{ @hdiv[vn] }
|
638
|
+
# :normal -> :safecopy_flushing
|
639
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
640
|
+
assert_equal(:safecopy_flushing, @st.instance_eval{ @dbs[dn] })
|
641
|
+
assert_equal('abc_data', @st.set(vn,'abc',0,0xffffffff,'abc_data')[4])
|
642
|
+
assert_equal('abc_data', @st.get(vn,'abc',0) )
|
643
|
+
# not stored
|
644
|
+
assert_nil(@st.instance_eval{ @hdb[dn].get('abc') })
|
645
|
+
# stored
|
646
|
+
assert(@st.instance_eval{ @hdbc[dn].get('abc') })
|
647
|
+
# out
|
648
|
+
@st.out_cache(dn, 'abc')
|
649
|
+
# not stored
|
650
|
+
assert_nil(@st.instance_eval{ @hdb[dn].get('abc') })
|
651
|
+
# not stored
|
652
|
+
assert_nil(@st.instance_eval{ @hdbc[dn].get('abc') })
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_each_cache_dump_pack
|
656
|
+
vn = 0
|
657
|
+
dn = @st.instance_eval{ @hdiv[vn] }
|
658
|
+
# :normal -> :safecopy_flushing
|
659
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
660
|
+
keys = []
|
661
|
+
10.times do |i|
|
662
|
+
k = "key#{i}"
|
663
|
+
v = "val#{i}"
|
664
|
+
assert_equal(v, @st.set(vn,k,0,0xffffffff,v)[4])
|
665
|
+
keys << k
|
666
|
+
end
|
667
|
+
@st.each_cache_dump_pack(dn, keys) do |data|
|
668
|
+
vn, last, clk, expt, klen = data.slice!(0..19).unpack('NNNNN')
|
669
|
+
k = data.slice!(0..(klen-1))
|
670
|
+
vlen, = data.slice!(0..3).unpack('N')
|
671
|
+
v = data
|
672
|
+
# puts "#{vn} #{last} #{clk} #{expt} #{klen} #{k} #{vlen} #{v}"
|
673
|
+
assert_match(/key\d/, k)
|
674
|
+
assert_match("val#{k[3..-1]}", v)
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
678
|
+
def test_get_keys_in_cache
|
679
|
+
vn = 0
|
680
|
+
dn = @st.instance_eval{ @hdiv[vn] }
|
681
|
+
# :normal -> :safecopy_flushing
|
682
|
+
assert_equal(:safecopy_flushing, @st.set_db_stat(dn, :safecopy_flushing))
|
683
|
+
keys = []
|
684
|
+
100.times do |i|
|
685
|
+
k = "key#{i}"
|
686
|
+
v = "val#{i}"
|
687
|
+
assert_equal(v, @st.set(vn,k,0,0xffffffff,v)[4])
|
688
|
+
end
|
689
|
+
|
690
|
+
assert(@st.instance_eval{ @hdbc[dn].rnum } == 100)
|
691
|
+
10.times do
|
692
|
+
keys = @st.get_keys_in_cache(dn, 10)
|
693
|
+
assert(keys.length == 10)
|
694
|
+
keys.each do |k|
|
695
|
+
@st.out_cache(dn, k)
|
696
|
+
end
|
697
|
+
end
|
698
|
+
assert(@st.instance_eval{ @hdbc[dn].rnum } == 0)
|
699
|
+
end
|
518
700
|
end
|
519
701
|
|
520
702
|
class DbmStorageTest < TCStorageTest
|