1. 程式人生 > >清晰的理解pg與pgp之間的關係

清晰的理解pg與pgp之間的關係

一、前言

首先來一段英文關於PG和PGP區別的解釋:

PG = Placement Group
PGP = Placement Group for Placement purpose

pg_num = number of placement groups mapped to an OSD

When pg_num is increased for any pool, every PG of this pool splits into half, but they all remain mapped to their parent OSD.

Until this time, Ceph does not start rebalancing. Now, when you increase the pgp_num value for the same pool, PGs start to migrate from the parent to some other OSD, and cluster rebalancing starts. This is how PGP plays an important role.
By Karan Singh

以上是來自郵件列表的 Karan Singh 的PG和PGP的相關解釋,他也是 Learning Ceph 和 Ceph Cookbook 的作者,以上的解釋沒有問題,我們來看下具體在叢集裡面具體作用

二、實踐

環境準備,因為是測試環境,我只準備了兩臺機器,每臺機器4個OSD,所以做了一些引數的設定,讓資料儘量雜湊

osd_crush_chooseleaf_type = 0

 

以上為修改的引數,這個是讓我的環境故障域為OSD分組的

建立測試需要的儲存池
我們初始情況只建立一個名為testpool包含6個PG的儲存池

[[email protected] ceph]# ceph osd pool create testpool 6 6
pool 'testpool' created

 

我們看一下預設建立完了後的PG分佈情況

[[email protected] ceph]# ceph pg dump pgs|grep ^1|awk '{print $1,$2,$15}'
dumped pgs in format plain
1.1 0 [3,6,0]
1.0 0 [7,0,6]
1.3 0 [4,1,2]
1.2 0 [7,4,1]
1.5 0 [4,6,3]
1.4 0 [3,0,4]

 

我們寫入一些物件,因為我們關心的不僅是pg的變動,同樣關心PG內物件有沒有移動,所以需要準備一些測試資料,這個呼叫原生rados介面寫最方便

rados -p testpool bench 20 write --no-cleanup

 

我們再來查詢一次

[[email protected] ceph]# ceph pg dump pgs|grep ^1|awk '{print $1,$2,$15}'
dumped pgs in format plain
1.1 75 [3,6,0]
1.0 83 [7,0,6]
1.3 144 [4,1,2]
1.2 146 [7,4,1]
1.5 86 [4,6,3]
1.4 80 [3,0,4]

 

可以看到寫入了一些資料,其中的第二列為這個PG當中的物件的數目,第三列為PG所在的OSD

增加PG測試

我們來擴大PG再看看

[[email protected] ceph]# ceph osd pool set testpool pg_num 12
set pool 1 pg_num to 12

 

再次查詢

[[email protected] ceph]# ceph pg dump pgs|grep ^1|awk '{print $1,$2,$15}'
dumped pgs in format plain
1.1 37 [3,6,0]
1.9 38 [3,6,0]
1.0 41 [7,0,6]
1.8 42 [7,0,6]
1.3 48 [4,1,2]
1.b 48 [4,1,2]
1.7 48 [4,1,2]
1.2 48 [7,4,1]
1.6 49 [7,4,1]
1.a 49 [7,4,1]
1.5 86 [4,6,3]
1.4 80 [3,0,4]

 

可以看到上面新加上的PG的分佈還是基於老的分佈組合,並沒有出現新的OSD組合,因為我們當前的設定是pgp為6,那麼三個OSD的組合的個數就是6個,因為當前為12個pg,分佈只能從6種組合裡面挑選,所以會有重複的組合

根據上面的分佈情況,可以確定的是,增加PG操作會引起PG內部物件分裂,分裂的份數是根據新增PG組合重複情況來的,比如上面的情況

  • 1.1的物件分成了兩份[3,6,0]
  • 1.3的物件分成了三份[4,1,2]
  • 1.4的物件沒有拆分[3,0,4]

結論:增加PG會引起PG內的物件分裂,也就是在OSD上建立了新的PG目錄,然後進行部分物件的move的操作

增加PGP測試

我們將原來的PGP從6調整到12

[[email protected] ceph]# ceph osd pool set testpool pgp_num 12
[[email protected] ceph]# ceph pg dump pgs|grep ^1|awk '{print $1,$2,$15}'
dumped pgs in format plain
1.a 49 [1,2,6]
1.b 48 [1,6,2]
1.1 37 [3,6,0]
1.0 41 [7,0,6]
1.3 48 [4,1,2]
1.2 48 [7,4,1]
1.5 86 [4,6,3]
1.4 80 [3,0,4]
1.7 48 [1,6,0]
1.6 49 [3,6,7]
1.9 38 [1,4,2]
1.8 42 [1,2,3]

 

可以看到PG裡面的物件並沒有發生變化,而PG所在的對應關係發生了變化
我們看下與調整PGP前的對比

*1.1 37 [3,6,0]          1.1 37 [3,6,0]*
1.9 38 [3,6,0]          1.9 38 [1,4,2]
*1.0 41 [7,0,6]          1.0 41 [7,0,6]*
1.8 42 [7,0,6]          1.8 42 [1,2,3]
*1.3 48 [4,1,2]          1.3 48 [4,1,2]*
1.b 48 [4,1,2]          1.b 48 [1,6,2]
1.7 48 [4,1,2]          1.7 48 [1,6,0]
*1.2 48 [7,4,1]          1.2 48 [7,4,1]*
1.6 49 [7,4,1]          1.6 49 [3,6,7]
1.a 49 [7,4,1]          1.a 49 [1,2,6]
*1.5 86 [4,6,3]          1.5 86 [4,6,3]*
*1.4 80 [3,0,4]          1.4 80 [3,0,4]*

 

可以看到其中最原始的6個PG的分佈並沒有變化(標註了*號),變化的是後增加的PG,也就是將重複的PG分佈進行新分佈,這裡並不是隨機完全打散,而是根據需要去進行重分佈

結論:調整PGP不會引起PG內的物件的分裂,但是會引起PG的分佈的變動

三、總結

  • PG是指定儲存池儲存物件的目錄有多少個,PGP是儲存池PG的OSD分佈組合個數
  • PG的增加會引起PG內的資料進行分裂,分裂到相同的OSD上新生成的PG當中
  • PGP的增加會引起部分PG的分佈進行變化,但是不會引起PG內物件的變動

轉自:https://blog.csdn.net/dengxiafubi/article/details/72957428