ceph文件布局
2018-09-10 本文已影响3人
f0fe6e336bd7
文件布局
文件布局可控制如何把文件内容映射到各 Ceph RADOS 对象,你可以用虚拟扩展属性或 xattrs 来读、写某一文件的布局。
布局 xattrs 的名字取决于此文件是常规文件还是目录,常规文件的布局 xattrs 叫作 ceph.file.layout
、目录的布局 xattrs 叫作 ceph.dir.layout
。因此后续实例中若用的是 ceph.file.layout
,处理目录时就要替换为 dir
。
布局字段
pool
字符串,可指定 ID 或名字。它是文件的数据对象所在的 RADOS 存储池。
stripe_unit
字节数、整数。一个文件的数据块按照此尺寸(字节)像 RAID 0 一样分布。一文件所有条带单元的尺寸一样,最后一个条带单元通常不完整——即它包含文件末尾的数据、还有数据末端到固定条带单元尺寸之间的未使用“空间”。
stripe_count
整数。组成 RAID 0 “条带”数据的连续条带单元数量。
object_size
整数个字节。文件数据按此尺寸分块为 RADOS 对象。
用 GETFATTR
读取布局
读出的布局信息表示为单个字符串:
# 使用示例
touch file
getfattr -n ceph.file.layout file
#输出为:
# file: file
ceph.file.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=fs_data"
读取单个布局字段:
#读取文件所在存储池
getfattr -n ceph.file.layout.pool file
输出为:
ceph.file.layout.pool="fs_data"
#读取文件的条带大小
getfattr -n ceph.file.layout.stripe_unit file
输出为:
ceph.file.layout.stripe_unit="4194304"
#读取文件的条带数量
getfattr -n ceph.file.layout.stripe_count file
输出为:
ceph.file.layout.stripe_count="1"
#读取文件分块大小
getfattr -n ceph.file.layout.object_size file
输出为:
ceph.file.layout.object_size="4194304"
#读取目录的布局
$ mkdir dir
$ getfattr -n ceph.dir.layout dir
dir: ceph.dir.layout: No such attribute
$ setfattr -n ceph.dir.layout.stripe_count -v 2 dir
$ getfattr -n ceph.dir.layout dir
# file: dir
ceph.dir.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
普通的目录是没有布局的,所以需要自行设定文件的布局
用 SETFATTR
设置布局
布局字段可用 setfattr
修改:
touch file2
setfattr -n ceph.file.layout.stripe_unit -v 1048576 file2
setfattr -n ceph.file.layout.stripe_count -v 8 file2
setfattr -n ceph.file.layout.object_size -v 10485760 file2
setfattr -n ceph.file.layout.pool -v 2 file2
setfattr -n ceph.file.layout.pool -v fs_data file2
布局的继承
***文件会在创建时继承其父目录的布局,然而之后对父目录布局的更改不会影响其子孙。
***如果中层目录没有设置布局,那么内层目录中创建的文件也会继承此目录的布局
CephFS Layout
Cephfs支持配置目录、文件的layout和stripe,这些元数据信息保存在目录和文件的xattr中。
- 目录的layout xattrs为:ceph.dir.layout
- 文件的layout xattrs为:ceph.file.layout
CephFS支持的layout配置项有:
- pool
数据存储到指定pool - namespace
数据存储到指定namespace,比pool更细的粒度(rbd/rgw/cephfs都还不支持) - stripe_unit
条带大小,单位Byte - stripe_count
条带个数
默认文件/目录继承父目录的layout和striping
示例: 配置一个目录的Layout
setfattr -n ceph.dir.layout -v "stripe_unit=524288 stripe_count=8 object_size=4194304 pool=cephfs_data2" /mnt/mike512K/