forked from memcached/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslabs_reassign.t
78 lines (60 loc) · 2.56 KB
/
slabs_reassign.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 131;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
# Enable manual slab reassign, cap at 6 slabs
my $server = new_memcached('-o slab_reassign -m 4');
my $stats = mem_stats($server->sock, ' settings');
is($stats->{slab_reassign}, "yes");
my $sock = $server->sock;
# Fill a largeish slab until it evicts (honors the -m 6)
my $bigdata = 'x' x 70000; # slab 31
for (1 .. 60) {
print $sock "set bfoo$_ 0 0 70000\r\n", $bigdata, "\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
}
# Fill a smaller slab until it evicts
my $smalldata = 'y' x 20000; # slab 25
for (1 .. 60) {
print $sock "set sfoo$_ 0 0 20000\r\n", $smalldata, "\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
}
my $items_before = mem_stats($sock, "items");
isnt($items_before->{"items:31:evicted"}, 0, "slab 31 evicted is nonzero");
isnt($items_before->{"items:25:evicted"}, 0, "slab 25 evicted is nonzero");
my $slabs_before = mem_stats($sock, "slabs");
# Invalid argument test
print $sock "slabs reassign invalid1 invalid2\r\n";
is(scalar <$sock>, "CLIENT_ERROR bad command line format\r\n");
# Move a large slab to the smaller slab
print $sock "slabs reassign 31 25\r\n";
is(scalar <$sock>, "OK\r\n", "slab rebalancer started");
# Still working out how/if to signal the thread. For now, just sleep.
sleep 2;
# Check that stats counters increased
my $slabs_after = mem_stats($sock, "slabs");
$stats = mem_stats($sock);
isnt($stats->{slabs_moved}, 0, "slabs moved is nonzero");
# Check that slab stats reflect the change
ok($slabs_before->{"31:total_pages"} != $slabs_after->{"31:total_pages"},
"slab 31 pagecount changed");
ok($slabs_before->{"25:total_pages"} != $slabs_after->{"25:total_pages"},
"slab 25 pagecount changed");
# Try to move another slab, see that you can move two in a row
print $sock "slabs reassign 31 25\r\n";
like(scalar <$sock>, qr/^OK/, "Cannot re-run against class with empty space");
# Try to move a page backwards. Should complain that source class isn't "safe"
# to move from.
# TODO: Wait until the above command completes, then try to move it back?
# Seems pointless...
#print $sock "slabs reassign 25 31\r\n";
#like(scalar <$sock>, qr/^UNSAFE/, "Cannot move an unsafe slab back");
# Try to insert items into both slabs
print $sock "set bfoo51 0 0 70000\r\n", $bigdata, "\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
print $sock "set sfoo51 0 0 20000\r\n", $smalldata, "\r\n";
is(scalar <$sock>, "STORED\r\n", "stored key");
# Do need to come up with better automated tests for this.