Ceph官方文档告诉咱们Ceph本质上也是对象存储。并且了解到,Ceph的块存储其实在客户端也会被分为若干个对象进行处理。函数
一. 实验和步骤
$ ceph osd pool create test_pool 256 256
$ rados -p test_pool ls
结果为空:证实create pool之后,没有object产生。code
$ rbd create test_pool/test_image --size 1024
$ rbd info test_pool/test_image rbd image 'test_image': size 1024 MB in 256 objects order 22 (4096 kB objects) block_name_prefix: rbd_data.100f74b0dc51 format: 2 features: layering, exclusive-lock, object-map, fast-diff, deep-flatten flags:
里面比较重要的一个字段:
block_name_prefix: rbd_data.100f74b0dc51
这个字段将做为该image每一个object的前缀。orm
$ rados -p test_pool ls rbd_directory rbd_object_map.100f74b0dc51 rbd_id.test_image rbd_header.100f74b0dc51
$rbd-nbd map test_pool/test_image /dev/nbd0
$ dd if=/dev/zero of=/dev/nbd0 bs=4M count=1 seek=0 $ rados -p test_pool ls rbd_data.100f74b0dc51.0000000000000000 rbd_directory rbd_object_map.100f74b0dc51 rbd_id.test_image rbd_header.100f74b0dc51
$ dd if=/dev/zero of=/dev/nbd0 bs=4M count=1 seek=10 $ rados -p test_pool ls rbd_directory rbd_object_map.100f74b0dc51 rbd_id.test_image rbd_header.100f74b0dc51 rbd_data.100f74b0dc51.000000000000000a
二. 原理解释
建立卷: 使用Rados API建立一个Header Object,将这个卷的元数据如id, size, snaps, name, seq等信息写入。而后将自身(id)注册到一个”RBD_DIRECTORY”的Object里。 记录元数据信息:
1)
key: rbd_id.test_image
value: 100f74b0dc51
备注:image name到image id的映射。image id是用rand()函数,按必定规则生成。 这个object文件的大小为16 byte。对象
key: rbd_header.100f74b0dc51
value: size : 10240
order : 22
object_prefix: rbd_data.100f74b0dc51
snap_seq: 0
备注:记录元信息Order是用来计算block size,如order为22,block size为1<<22 = 4M 该object的大小为0。文档
key: rbd_directory
value: ……
name_test_image: id_100f74b0dc51
Id_100f74b0dc51: name_test_image
备注:rbd_directory中记录了全部image的name和id的双向映射关系。 该object的大小为0。get
根据image id取得image name的方法:ast
$ rados -p test_pool getomapval rbd_directory id_100f74b0dc51 value (14 bytes) : 00000000 0a 00 00 00 74 65 73 74 5f 69 6d 61 67 65 |....test_image| 0000000e
三. Object的数据文件form
root@ubu-machine:/etc/ceph/osd.0/current# ls 0.0_head 0.18_head 0.20_head 0.29_head 0.31_head 0.3a_head 0.6_head 0.f_head 1.17_head 1.1_head 1.28_head 1.30_head 1.39_head 1.5_head 1.e_head 0.0_TEMP 0.18_TEMP 0.20_TEMP 0.29_TEMP 0.31_TEMP 0.3a_TEMP 0.6_TEMP 0.f_TEMP 1.17_TEMP 1.1_TEMP 1.28_TEMP 1.30_TEMP 1.39_TEMP 1.5_TEMP 1.e_TEMP 0.10_head 0.19_head 0.21_head 0.2a_head 0.32_head 0.3b_head 0.7_head 1.0_head 1.18_head 1.20_head 1.29_head 1.31_head 1.3a_head 1.6_head 1.f_head
其中0.0_head,存储0.0这个PG的object。test
root@ubu-machine:/etc/ceph/osd.0/current/1.1c_head# ll -h total 4.1M drwxr-xr-x 2 root root 4.0K 3月 15 21:54 ./ drwxr-xr-x 260 root root 8.0K 3月 15 21:52 ../ -rw-r--r-- 1 root root 0 3月 15 21:52 __head_0000001C__1 -rw-r--r-- 1 root root 4.0M 3月 15 21:54 rbd\udata.100f6b8b4567.0000000000000009__head_6E33BC5C__1 -rw-r--r-- 1 root root 0 3月 15 21:54 rbd\udirectory__head_30A98C1C__1