ceph块设备的对象简介

Ceph官方文档告诉我们Ceph本质上也是对象存储。而且了解到,Ceph的块存储其实在客户端也会被分为若干个对象进行处理。

一. 实验和步骤
  1. 创建test_pool:
$ ceph osd pool create test_pool 256  256
  1. 查看现在pool中的object
$ rados -p test_pool ls

结果为空:证明create pool以后,没有object产生。

  1. 创建test_image:
$ rbd create test_pool/test_image --size 1024
  1. 查看test_image的信息:
$ 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的前缀。

  1. 查看创建test_image以后,test_pool中的object:
$ rados -p test_pool ls
rbd_directory
rbd_object_map.100f74b0dc51
rbd_id.test_image
rbd_header.100f74b0dc51
  1. 使用rbd-nbd进行map:
$rbd-nbd map test_pool/test_image  
/dev/nbd0
  1. 使用dd,在nbd0的开始位置,生成一个4M的object
$ 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
  1. 使用dd,在nbd0开始的第10个4M处,生成一个4M的object
$ 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。

根据image id取得image name的方法:

$ 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
  1. object_map

三. Object的数据文件

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。

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

转载于:https://my.oschina.net/u/3011935/blog/860251

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值