背景
看到有这个需求,具体碰到什么场景了不太清楚,之前做过rbd的重构的研究,既然能重构,那么修改应该是比重构还要简单一点的,我们具体看下怎么操作
数据结构分析
rbd的元数据信息
[root@lab104 ~]# rbd create testrbd --size 1T
[root@lab104 ~]# rbd info testrbd
rbd image 'testrbd':
size 1 TiB in 262144 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 5f0c22d39dda
block_name_prefix: rbd_data.5f0c22d39dda
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Thu Apr 10 11:01:08 2025
access_timestamp: Thu Apr 10 11:01:08 2025
modify_timestamp: Thu Apr 10 11:01:08 2025
[root@lab104 ~]# rbd rm testrbd
Removing image: 100% complete...done.
[root@lab104 ~]# rbd create testrbd --size 1T
[root@lab104 ~]# rbd info testrbd
rbd image 'testrbd':
size 1 TiB in 262144 objects
order 22 (4 MiB objects)
snapshot_count: 0
id: 5f57bde3f24c
block_name_prefix: rbd_data.5f57bde3f24c
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
op_features:
flags:
create_timestamp: Thu Apr 10 11:07:17 2025
access_timestamp: Thu Apr 10 11:07:17 2025
modify_timestamp: Thu Apr 10 11:07:17 2025
这个id信息就是那个block_name_prefix里面的,可以看到,同样的名称同样的大小,重建一次,这个信息就发生了改变了,说明这个信息是随机性的,并没有固定算法,这些信息是在几个地方有记录的我们把这几个地方找出来
rbd相关的对象
rbd_id.testrbd
rbd_directory
rbd_header.5f57bde3f24c
rbd_object_map.5f57bde3f24c
这几个是元数据的对象,其它就是数据的信息,我们假如要改id名称,需要先处理元数据
rbd_data.5f57bde3f24c.xxxxxxxx
数据存储是这样的
[root@lab104 ~]# rados -p rbd listomapvals rbd_directory
id_5f57bde3f24c
value (11 bytes) :
00000000 07 00 00 00 74 65 73 74 72 62 64 |....testrbd|
0000000b
name_testrbd
value (16 bytes) :
00000000 0c 00 00 00 35 66 35 37 62 64 65 33 66 32 34 63 |....5f57bde3f24c|
00000010
rbd_directory通过omap老存储id和名称的对应关系
[root@lab104 ~]# rados -p rbd listomapvals rbd_header.5f57bde3f24c
access_timestamp
value (8 bytes) :
00000000 e5 35 f7 67 95 6f 07 08 |.5.g.o..|
00000008
create_timestamp
value (8 bytes) :
00000000 e5 35 f7 67 95 6f 07 08 |.5.g.o..|
00000008
features
value (8 bytes) :
00000000 3d 00 00 00 00 00 00 00 |=.......|
00000008
modify_timestamp
value (8 bytes) :
00000000 e5 35 f7 67 95 6f 07 08 |.5.g.o..|
00000008
object_prefix
value (25 bytes) :
00000000 15 00 00 00 72 62 64 5f 64 61 74 61 2e 35 66 35 |....rbd_data.5f5|
00000010 37 62 64 65 33 66 32