本文目标:理解ceph存储流程,例如:当client向ceph集群中写入一个文件时,这个文件是如何存储到ceph中的,其存储过程是如何?
graph LR
文件-->对象
对象-->归置组
归置组-->OSD
首先,将file切分成多个object,每个object的大小由RADOS限定(通常为2m或者4m)。每个object都有唯一的id即oid,oid由ino和ono产生的
对oid进行hash然后进行按位与计算得到某一个PG的id。mask为PG的数量减1。这样得到的pgid是随机的。
注:这与PG的数量和文件的数量有关系。在足够量级的程度上数据是均匀分布的。
通过CRUSH算法可以通过pgid得到多个osd,简而言之就是根据集群的OSD状态和存储策略配置动态得到osdid,从而自动化的实现高可靠性和数据均匀分布。在ceph中,数据到底是在哪个osd是通过CRUSH算法计算出来的
root in iscloud163-200 in ~ via 🐍 v2.7.5
➜ rados lspools
summer60sys000
testpool
root in iscloud163-200 in ~ via 🐍 v2.7.5
❯ rados -p testpool put xsw xsw.txt
OBJECT COMMANDS
get <obj-name> [outfile] fetch object
put <obj-name> [infile] write object
root in iscloud163-200 in ~ via 🐍 v2.7.5
➜ rados -p testpool ls | grep xsw
xsw
root in iscloud163-200 in ~ via 🐍 v2.7.5
➜ ceph osd map testpool xsw
osdmap e46 pool 'testpool' (3) object 'xsw' -> pg 3.30bdc57f (3.7) -> up ([3,0], p3) acting ([3,0], p3)
root in iscloud163-200 in ceph-0/current/3.7_head
➜ pwd
/var/lib/ceph/osd/ceph-0/current/3.7_head
root in iscloud163-200 in ceph-0/current/3.7_head
➜ ll
total 20508
-rw-r--r-- 1 root root 4194304 Apr 23 09:51 benchmark\udata\uiscloud163-200\u3243175\uobject20__head_9D317607__3
-rw-r--r-- 1 root root 4194304 Apr 23 09:51 benchmark\udata\uiscloud163-200\u3243175\uobject37__head_F83C35C7__3
-rw-r--r-- 1 root root 4194304 Apr 23 09:51 benchmark\udata\uiscloud163-200\u3243175\uobject43__head_78BB75F7__3
-rw-r--r-- 1 root root 4194304 Apr 23 09:51 benchmark\udata\uiscloud163-200\u3243175\uobject5__head_E2A01F47__3
-rw-r--r-- 1 root root 4194304 Apr 23 09:51 benchmark\udata\uiscloud163-200\u3243175\uobject64__head_98D1E25F__3
-rw-r--r-- 1 root root 0 Apr 23 09:51 __head_00000007__3
-rw-r--r-- 1 root root 502 Apr 23 14:45 xsw__head_30BDC57F__3
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有