# create new dircd /sys/fs/cgroup
mkdir test# creat loop.sh for testing cpu quotavim loop.sh
while :
do :
done# lunch loop.sh, generate pid -> 2584068nohup sh loop.sh &# echo pid to cgroup.procsecho2584068 > test/cgroup.procs
# set cpu, at lease 0.1echo100010000 > test/cpu.max
# check top
# recovery allkill2584068rmdir test
# create new schemacreate schema test;use test;# create table testcreate table user
( id int primary key,
age int
);alter table user
add index age_idx (age);# insert some test datainsert into user
values (3, 10),
(5, 20),
(8, 30);
2. 间隙锁测试
1. 使用主键索引,指定行存在
1
2
3
4
5
6
7
8
9
# session 1, the row is exist for id = 3 , so it doesn't lock.begin;select * from user where id=3for update;# session 2, execute successful.begin;insert into user value (1, 20);
2. 使用主键索引,指定行不存在
1
2
3
4
5
6
7
8
9
# session 1, the row isn't exist for id = 2, so it locks range (,3]begin;select * from user where id=2for update;# session 2, execute block.begin;insert into user value (1, 20);
3. 使用主键索引,范围查找
1
2
3
4
5
6
7
8
9
# session 1, it locks range [1,5] begin;select * from user where id >=1 and id <=5for update;# session 2, execute blockbegin;insert into user value (2, 20);
4. 使用二级索引,指定行存在
1
2
3
4
5
6
7
8
9
# session 1, it locks range [3,8]begin;select * from user where age=20for update;# session 2, execute block.begin;insert into user value (4, 20);
5. 使用二级索引,指定行不存在
1
2
3
4
5
6
7
8
9
# session 1, it locks range [3,5]begin;select * from user where age=15for update;# session 2, execute block.begin;insert into user value (4, 20);
6. 使用二级索引,范围查询
1
2
3
4
5
6
7
8
9
# session 1, it locks range [3,8]begin;select * from user where age >=12 and age <=28for update;# session 2, execute block.begin;insert into user value (4, 20);
# create ns1, ns2ip netns add ns1
ip netns add ns2
# create veth1, veth2ip link add veth1 type veth peer name veth2
# set veth1 for ns1, set veth2 for ns2ip link set dev veth1 netns ns1
ip link set dev veth2 netns ns2
# set veth1 ip, set veth2 ipip netns exec ns1 ip addr add 172.16.0.1/24 dev veth1
ip netns exec ns2 ip addr add 172.16.0.2/24 dev veth2
# set veth1 up, set veth2 upip netns exec ns1 ip link set dev veth1 up
ip netns exec ns2 ip link set dev veth2 up
# show ip addressip netns exec ns1 ip addr
ip netns exec ns2 ip addr
# test for ping ip netns exec ns1 ping 172.16.0.2
ip netns exec ns2 ping 172.16.0.1
# recovery all setting ip netns delete ns1
ip netns delete ns2
# create ns1ip netns add ns1
# create veth0, veth1ip link add veth0 type veth peer name veth1
# create bridge0ip link add bridge0 type bridge
# set veth1 for ns1ip link set dev veth1 netns ns1
# set veth0 for bridge0ip link set dev veth0 master bridge0
# set veth0 ip addressip addr add 172.16.0.1/24 dev veth0
# set bridge0 ip addressip addr add 172.16.0.0/24 dev bridge0
# set veth1 ip addressip netns exec ns1 ip addr add 172.16.0.2/24 dev veth1
# set veth0, veth1, bridge0 upip link set dev veth0 up
ip link set dev bridge0 up
ip netns exec ns1 ip link set dev veth1 up
# delete veth0 routeip route del 172.16.0.0/24 dev veth0
# show ip addressip addr
ip netns exec ns1 ip addr
# test for ping ping 172.16.0.2
ip netns exec ns1 ping 172.16.0.1
# recovery all setting ip netns del ns1
ip link del bridge0