防止ceph 集群 IO hang

在ceph集群的使用过程中,经常会遇到一种情况,当ceph集群出现故障,比如网络故障,导致集群无法链接时,作为客户端,所有的IO都会出现hang的现象。

这样的现象对于生产业务来说是很不能忍受的。举例如下:

环境

./vstart.sh -l -k --bluestore

id:     338b8b2e-fe88-4f2c-af4d-2359994a7da9

        application not enabled on 1 pool(s)

mon: 3 daemons, quorum a,b,c

mds: cephfs_a-1/1/1 up  {0=b=up:active}, 2 up:standby

osd: 3 osds: 3 up, 3 in

pools:   3 pools, 24 pgs

objects: 74 objects, 115 MB

usage:   3617 MB used, 27294 MB / 30911 MB avail

pgs:     24 active+clean

[root@atest-guest build]# rbd info test1

    size 20480 MB in 5120 objects

    order 22 (4096 kB objects)

    block_name_prefix: rbd_data.103a2ae8944a

    features: layering, exclusive-lock, object-map

    flags: object map invalid

    create_timestamp: Wed Mar 14 08:40:39 2018

ps -ef|grep -E “ceph-mon|ceph-osd”|gawk ‘{print "kill -9 "$2}’|bash

(1)rbd 命令

这时,如果我们如果执行rbd命令,就会发现命令hang住了。
rbd ls

分析

打开debug之后可以看到,这个命令一直在做auth操作,也就是说一直去发送认证,然后卡住了,导致hang。

解决

为了解决这个问题,ceph社区引入了timeout机制,简单来说就是,每个请求都有一个timeout,如果超过这个时间限制,我们就直接取消这个request,然后返回错误。

参数如下: client_mount_timeout = 5

结果如下:

2018-03-15 07:58:28.714157 7f76c817fd40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:58:28.714606 7f76c817fd40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:58:28.746878 7f76c817fd40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:58:33.750431 7f76c817fd40 0 monclient(hunting): authenticate timed out after 5

2018-03-15 07:58:33.750489 7f76c817fd40 0 librados: client.admin authentication error (110) Connection timed out

rbd: couldn’t connect to the cluster!

rbd: list: (110) Connection timed out

(2)IO hang

但是上述命令只是在auth的时候timeout,如果我已经开始读写之后,集群发生异常,不会去做auth操作,岂不是还会有问题?

[root@atest-guest build]# rbd bench --io-type write --io-size 4 --io-threads 1 test1

2018-03-15 07:52:37.735520 7f2bdb81bd40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:52:37.735941 7f2bdb81bd40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:52:37.769038 7f2bdb81bd40 -1 WARNING: all dangerous and experimental features are enabled.

bench type write io_size 4 io_threads 1 bytes 1073741824 pattern sequential

SEC       OPS   OPS/SEC   BYTES/SEC

1        75     75.51    302.05

2       140     70.25    280.98

3       198     66.01    264.04

4       249     62.35    249.42

5       299     59.82    239.28

6       351     55.23    220.92

7       401     52.25    208.99

不出所料,在第七秒的时候,将ceph-osd和ceph-mon都kill掉,rbd bench就一直hang在这个地方,无法退出。
为了解决这个问题,ceph社区引入了两个参数

    rados osd op timeout = 5
    rados mon op timeout = 5

如果设置了这两个参数,我们发出去的请求就会在五秒之后退出,返回错误。

结果如下:

rbd bench --io-type write --io-size 4 --io-threads 1 test1

2018-03-15 07:54:11.243056 7fad2c936d40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:54:11.243513 7fad2c936d40 -1 WARNING: all dangerous and experimental features are enabled.

2018-03-15 07:54:11.276004 7fad2c936d40 -1 WARNING: all dangerous and experimental features are enabled.

bench type write io_size 4 io_threads 1 bytes 1073741824 pattern sequential

SEC       OPS   OPS/SEC   BYTES/SEC

1        41     41.99    167.96

2        91     45.53    182.12

3       139     46.63    186.53

4       190     47.62    190.47

5       240     48.11    192.43

6       293     50.31    201.25

write error: (110) Connection timed out

(3)kernel rbd
以上两种情况都解决的情况下, 我们来到另一个领域,kernel rbd。没有错,如果集群发生异常,我们的kernel rbd社区无法链接集群的话,是没有办法卸载的。

同时,当我们想要重启来卸载这个设备的时候,你会发现重启卡住了。OMG,WTF。原因还是因为关机需要卸载rbd设备,在卸载rbd 设备的时候需要去链接

ceph集群,但是链接不上,导致一直hang住。

为了解决这个问题,kernel rbd也提供了一个参数可以设置:osd_request_timeout.

可惜的是我们在rbd map的时候不能指定这个参数。直到 https://github.com/ceph/ceph/pull/20792 这个merge之后,我们可以通过如下命令来设置参数。

rbd map -o osd_request_timeout=30 test

这样,我们可以正常重启,或者通过rbd unmap -o force test 来卸载rbd 设备。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章