Ceph最新的EC-CLAY插件調(diào)研-上
CLAY 簡介
Clay Codes ( Clay Codes: Moulding MDS Codes to Yield an MSR Code ) 是FAST18 上提出的一種編碼方法,文章地址,Clay 碼能夠?qū)⒁话愕腗DS 碼(最優(yōu)容錯)轉(zhuǎn)化為具有最優(yōu)修復(fù)的編碼方法,具有以下性質(zhì):
Minimum Storage (最小存儲開銷,同經(jīng)典RS碼和最小存儲再生碼,MSR)
Maximum Failure Tolerance(最大容錯,即 (n,k)-Clay 碼可以容任意n-k 失效)
Optimal Repair Bandwidth (最優(yōu)修復(fù)開銷,能夠達(dá)到理論最優(yōu)值)
All-Node Optimal Repair (最小開銷修復(fù)所有節(jié)點(diǎn)的數(shù)據(jù),包括原始數(shù)據(jù)和校驗(yàn)數(shù)據(jù))
Disk Read Optimal (最優(yōu)磁盤讀)
Low Sub-packetization (低分包數(shù),即碼字長度短)
參考資料1:http://blog.foool.net/2018/05/clay-codes-%E4%BB%8E%E7%94%9F%E6%88%90%E7%9F%A9%E9%98%B5%E7%9A%84%E8%A7%92%E5%BA%A6%E6%9D%A5%E7%9C%8B/
參考資料2:https://blog.acolyer.org/2018/03/01/clay-codes-moulding-mds-codes-to-yield-an-msr-code/
從ceph官方的介紹,可以確認(rèn)以下幾點(diǎn):
向下兼容:CLAY插件與jerasure、ISA、SHEC插件兼容,這里可以理解為Clay是在這幾個插件的基礎(chǔ)上做的一層更高層面的數(shù)據(jù)組成抽象,能夠更加細(xì)致的控制數(shù)據(jù)的分布粒度,從而實(shí)現(xiàn)對原有的幾個插件在數(shù)據(jù)恢復(fù)場景下的性能優(yōu)化。這也就是是上面提到的“Clay 碼能夠?qū)⒁话愕腗DS 碼(最優(yōu)容錯)轉(zhuǎn)化為具有最優(yōu)修復(fù)的編碼方法”。
修復(fù)性能優(yōu)化"在底層已有的jerasure、ISA、SHEC幾個的插件基礎(chǔ)上,做了編碼優(yōu)化,能夠在異常發(fā)生,需要進(jìn)行數(shù)據(jù)恢復(fù)的情況下顯著的降低磁盤&網(wǎng)絡(luò)帶寬的消耗。這個也是CLAY EC插件的最大價值所在。
從Ceph 14版本開始提供,理論上這個特性可以向下backport到低版本。
從clay插件的初始化配置部分的函數(shù)實(shí)現(xiàn),也能看到一些與其他插件在兼容適配上的限制
#src/erasure-code/clay/ErasureCodeClay.cc
int?ErasureCodeClay::parse(ErasureCodeProfile?&profile,
???????????????ostream?*ss)
{
??int?err?=?0;
??err?=?ErasureCode::parse(profile,?ss);
??err?|=?to_int("k",?profile,?&k,?DEFAULT_K,?ss);
??err?|=?to_int("m",?profile,?&m,?DEFAULT_M,?ss);
??err?|=?sanity_check_k_m(k,?m,?ss);
??err?|=?to_int("d",?profile,?&d,?std::to_string(k+m-1),?ss);
??//?check?for?scalar_mds?in?profile?input
?//默認(rèn)采用jerasure插件進(jìn)行編碼
??if?(profile.find("scalar_mds")?==?profile.end()?||
??????profile.find("scalar_mds")->second.empty())?{?
????mds.profile["plugin"]?=?"jerasure";?
????pft.profile["plugin"]?=?"jerasure";
??}?else?{
????std::string?p?=?profile.find("scalar_mds")->second;
???//底層只支持jerasure、isa、shec三種插件
????if?((p?==?"jerasure")?||?(p?==?"isa")?||?(p?==?"shec"))?{
??????mds.profile["plugin"]?=?p;?
??????pft.profile["plugin"]?=?p;
????}?else?{
????????*ss?<"scalar_mds?"?<"plugin"]?<<
???????????????"is?not?currently?supported,?use?one?of?'jerasure',"<<
???????????????"?'isa',?'shec'"?<std::endl;
????????err?=?-EINVAL;
????????return?err;
????}
??}
??if?(profile.find("technique")?==?profile.end()?||
??????profile.find("technique")->second.empty())?{
????if?((mds.profile["plugin"]=="jerasure")?||?(mds.profile["plugin"]=="isa")?)?{
??????mds.profile["technique"]?=?"reed_sol_van";
??????pft.profile["technique"]?=?"reed_sol_van";
????}?else?{
??????mds.profile["technique"]?=?"single";
??????pft.profile["technique"]?=?"single";
????}
??}?else?{
????std::string?p?=?profile.find("technique")->second;
????//Supported?techniques?are?‘reed_sol_van’,?‘reed_sol_r6_op’,‘cauchy_orig’,?‘cauchy_good’,?‘liber8tion’?for?jerasure,?
????if?(mds.profile["plugin"]?==?"jerasure")?{
??????if?(?(p?==?"reed_sol_van")?||?(p?==?"reed_sol_r6_op")?||?(p?==?"cauchy_orig")
???????????||?(p?==?"cauchy_good")?||?(p?==?"liber8tion"))?{
????????mds.profile["technique"]?=?p;
????????pft.profile["technique"]?=?p;
??????}?else?{
????????*ss?<"technique?"?<"is?not?currently?supported,?use?one?of?"
????????<"reed_sol_van',?'reed_sol_r6_op','cauchy_orig',"
????????<"'cauchy_good','liber8tion'"<std::endl;
????????err?=?-EINVAL;
????????return?err;
??????}
??????//‘reed_sol_van’,?‘cauchy’?for?isa?
????}?else?if?(mds.profile["plugin"]?==?"isa")?{
??????if?(?(p?==?"reed_sol_van")?||?(p?==?"cauchy"))?{
????????mds.profile["technique"]?=?p;
????????pft.profile["technique"]?=?p;
??????}?else?{
????????*ss?<"technique?"?<"is?not?currently?supported,?use?one?of"
????????<"'reed_sol_van','cauchy'"<std::endl;
????????err?=?-EINVAL;
????????return?err;
??????}
????}?else?{
????//?‘single’,‘multiple’?for?shec.
??????if?(?(p?==?"single")?||?(p?==?"multiple"))?{
????????mds.profile["technique"]?=?p;
????????pft.profile["technique"]?=?p;
??????}?else?{
????????*ss?<"technique?"?<"is?not?currently?supported,?use?one?of"<<
???????????????"'single','multiple'"<std::endl;
????????err?=?-EINVAL;
????????return?err;
??????}
????}
??}
??if?((d??k?+?m?-?1))?{
????*ss?<"value?of?d?"?<????????<"?must?be?within?[?"?<","?<-1?<"]"?<std::endl;
????err?=?-EINVAL;
????return?err;
??}
??q?=?d?-?k?+?1;
??if?((k?+?m)?%?q)?{
????nu?=?q?-?(k?+?m)?%?q;
??}?else?{
????nu?=?0;
??}
//注意分塊規(guī)則限定k+m+nu總和不能超過254
??if?(k+m+nu?>?254)?{
????err?=?-EINVAL;
????return?err;
??}
??if?(mds.profile["plugin"]?==?"shec")?{
????mds.profile["c"]?=?'2';
????pft.profile["c"]?=?'2';
??}
??mds.profile["k"]?=?std::to_string(k+nu);
??mds.profile["m"]?=?std::to_string(m);
??mds.profile["w"]?=?'8';
??pft.profile["k"]?=?'2';
??pft.profile["m"]?=?'2';
??pft.profile["w"]?=?'8';
??t?=?(k?+?m?+?nu)?/?q;
??sub_chunk_no?=?pow_int(q,?t);
??dout(10)?<???????<"?(q,t,nu)=("?<","?<","?<")"?<
??return?err;
}
故障恢復(fù)時的帶寬&磁盤消耗對比
以EC場景下,假設(shè) d = 發(fā)生故障時,需要參與數(shù)據(jù)恢復(fù)的OSD數(shù)量
在jerasure配置 k=8 m=4的情況下,發(fā)生一塊磁盤故障,需要讀取d=8磁盤才能完成數(shù)據(jù)的恢復(fù)。如果需要恢復(fù)的數(shù)據(jù)的容量為1G,那么需要總共讀取 8 x 1 GB = 8GB的數(shù)據(jù)容量(這也意味著需要同時通過網(wǎng)絡(luò)傳輸8GB的數(shù)據(jù))。
在clay的插件配置中,d的設(shè)置需要滿足 k+1 <= d <= k+m-1 的限制,為了滿足使d最大化節(jié)省磁盤和網(wǎng)絡(luò)帶寬消耗,clay選取d=k+m-1作為默認(rèn)配置。在k=8,m=4的場景下,根據(jù)公式推導(dǎo)可以得到d=8+4-1=11。其中磁盤需要恢復(fù)的數(shù)據(jù)量計算公式如下。其中K為故障時刻需要恢復(fù)的數(shù)據(jù)總量。

當(dāng)一個osd故障時,d=11,以需要恢復(fù)的數(shù)據(jù)總量為1GB為例,此時需要恢復(fù)下載的磁盤數(shù)據(jù)總量為
jerasure/isa=?8*?1GB?=?8GB
caly?=?(11*1GB)/(11-8+1)?=?11?/?4?=?2.75GB
對比看到caly能夠顯著的減少磁盤讀取數(shù)據(jù)和網(wǎng)絡(luò)傳輸帶寬的消耗,caly只用到了isa一類插件的的2.75/8≈34%的資源消耗。
同樣的場景下,以k=4,m=2為例,此時d=4+2-1=5,caly只用到了isa一類插件的的2.5/4≈62.5%的資源消耗。
jerasure/isa=?4*?1GB?=?4GB
caly?=?(5*1GB)/(5-4+1)?=?5?/?2?=?2.5GB
依次類推,匯總表格如下:
| 名稱 | K | M | D | 3副本得盤率 | EC得盤率 | 硬件成本節(jié)約比率 | 磁盤數(shù)據(jù)遷移量(ISA) | 磁盤數(shù)據(jù)遷移量(CLAY) | 數(shù)據(jù)恢復(fù)負(fù)載降低比率 | 4M sub-chunk size(KB) | sub-chunk count |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2+1 | 2 | 1 | 2 | 33.33333333 | 66.66666667 | 200 | 2 | 2 | 0 | 2048 | 1 |
| 2+2 | 2 | 2 | 3 | 33.33333333 | 50 | 150 | 2 | 1.5 | 25 | 512 | 4 |
| 3+1 | 3 | 1 | 3 | 33.33333333 | 75 | 225 | 3 | 3 | 0 | 1365.333333 | 1 |
| 3+2 | 3 | 2 | 4 | 33.33333333 | 60 | 180 | 3 | 2 | 33.33333333 | 170.6666667 | 8 |
| 3+3 | 3 | 3 | 5 | 33.33333333 | 50 | 150 | 3 | 1.666666667 | 44.44444444 | 151.7037037 | 9 |
| 4+1 | 4 | 1 | 4 | 33.33333333 | 80 | 240 | 4 | 4 | 0 | 1024 | 1 |
| 4+2 | 4 | 2 | 5 | 33.33333333 | 66.66666667 | 200 | 4 | 2.5 | 37.5 | 128 | 8 |
| 4+3 | 4 | 3 | 6 | 33.33333333 | 57.14285714 | 171.4285714 | 4 | 2 | 50 | 37.92592593 | 27 |
| 4+4 | 4 | 4 | 7 | 33.33333333 | 50 | 150 | 4 | 1.75 | 56.25 | 64 | 16 |
| 5+1 | 5 | 1 | 5 | 33.33333333 | 83.33333333 | 250 | 5 | 5 | 0 | 819.2 | 1 |
| 5+2 | 5 | 2 | 6 | 33.33333333 | 71.42857143 | 214.2857143 | 5 | 3 | 40 | 51.2 | 16 |
| 5+3 | 5 | 3 | 7 | 33.33333333 | 62.5 | 187.5 | 5 | 2.333333333 | 53.33333333 | 30.34074074 | 27 |
| 5+4 | 5 | 4 | 8 | 33.33333333 | 55.55555556 | 166.6666667 | 5 | 2 | 60 | 12.8 | 64 |
| 5+5 | 5 | 5 | 9 | 33.33333333 | 50 | 150 | 5 | 1.8 | 64 | 32.768 | 25 |
| 6+1 | 6 | 1 | 6 | 33.33333333 | 85.71428571 | 257.1428571 | 6 | 6 | 0 | 682.6666667 | 1 |
| 6+2 | 6 | 2 | 7 | 33.33333333 | 75 | 225 | 6 | 3.5 | 41.66666667 | 42.66666667 | 16 |
| 6+3 | 6 | 3 | 8 | 33.33333333 | 66.66666667 | 200 | 6 | 2.666666667 | 55.55555556 | 25.28395062 | 27 |
| 6+4 | 6 | 4 | 9 | 33.33333333 | 60 | 180 | 6 | 2.25 | 62.5 | 10.66666667 | 64 |
| 6+5 | 6 | 5 | 10 | 33.33333333 | 54.54545455 | 163.6363636 | 6 | 2 | 66.66666667 | 5.461333333 | 125 |
| 6+6 | 6 | 6 | 11 | 33.33333333 | 50 | 150 | 6 | 1.833333333 | 69.44444444 | 18.96296296 | 36 |
| 7+1 | 7 | 1 | 7 | 33.33333333 | 87.5 | 262.5 | 7 | 7 | 0 | 585.1428571 | 1 |
| 7+2 | 7 | 2 | 8 | 33.33333333 | 77.77777778 | 233.3333333 | 7 | 4 | 42.85714286 | 18.28571429 | 32 |
| 7+3 | 7 | 3 | 9 | 33.33333333 | 70 | 210 | 7 | 3 | 57.14285714 | 7.223985891 | 81 |
| 7+4 | 7 | 4 | 10 | 33.33333333 | 63.63636364 | 190.9090909 | 7 | 2.5 | 64.28571429 | 9.142857143 | 64 |
| 7+5 | 7 | 5 | 11 | 33.33333333 | 58.33333333 | 175 | 7 | 2.2 | 68.57142857 | 4.681142857 | 125 |
| 7+6 | 7 | 6 | 12 | 33.33333333 | 53.84615385 | 161.5384615 | 7 | 2 | 71.42857143 | 2.708994709 | 216 |
| 7+7 | 7 | 7 | 13 | 33.33333333 | 50 | 150 | 7 | 1.857142857 | 73.46938776 | 11.94169096 | 49 |
| 8+1 | 8 | 1 | 8 | 33.33333333 | 88.88888889 | 266.6666667 | 8 | 8 | 0 | 512 | 1 |
| 8+2 | 8 | 2 | 9 | 33.33333333 | 80 | 240 | 8 | 4.5 | 43.75 | 16 | 32 |
| 8+3 | 8 | 3 | 10 | 33.33333333 | 72.72727273 | 218.1818182 | 8 | 3.333333333 | 58.33333333 | 6.320987654 | 81 |
| 8+4 | 8 | 4 | 11 | 33.33333333 | 66.66666667 | 200 | 8 | 2.75 | 65.625 | 8 | 64 |
| 8+5 | 8 | 5 | 12 | 33.33333333 | 61.53846154 | 184.6153846 | 8 | 2.4 | 70 | 4.096 | 125 |
| 8+6 | 8 | 6 | 13 | 33.33333333 | 57.14285714 | 171.4285714 | 8 | 2.166666667 | 72.91666667 | 2.37037037 | 216 |
| 8+7 | 8 | 7 | 14 | 33.33333333 | 53.33333333 | 160 | 8 | 2 | 75 | 1.49271137 | 343 |
| 8+8 | 8 | 8 | 15 | 33.33333333 | 50 | 150 | 8 | 1.875 | 76.5625 | 8 | 64 |
| 9+1 | 9 | 1 | 9 | 33.33333333 | 90 | 270 | 9 | 9 | 0 | 455.1111111 | 1 |
| 9+2 | 9 | 2 | 10 | 33.33333333 | 81.81818182 | 245.4545455 | 9 | 5 | 44.44444444 | 7.111111111 | 64 |
| 9+3 | 9 | 3 | 11 | 33.33333333 | 75 | 225 | 9 | 3.666666667 | 59.25925926 | 5.618655693 | 81 |
| 9+4 | 9 | 4 | 12 | 33.33333333 | 69.23076923 | 207.6923077 | 9 | 3 | 66.66666667 | 1.777777778 | 256 |
| 9+5 | 9 | 5 | 13 | 33.33333333 | 64.28571429 | 192.8571429 | 9 | 2.6 | 71.11111111 | 3.640888889 | 125 |
| 9+6 | 9 | 6 | 14 | 33.33333333 | 60 | 180 | 9 | 2.333333333 | 74.07407407 | 2.106995885 | 216 |
| 9+7 | 9 | 7 | 15 | 33.33333333 | 56.25 | 168.75 | 9 | 2.142857143 | 76.19047619 | 1.326854551 | 343 |
| 9+8 | 9 | 8 | 16 | 33.33333333 | 52.94117647 | 158.8235294 | 9 | 2 | 77.77777778 | 0.888888889 | 512 |
| 9+9 | 9 | 9 | 17 | 33.33333333 | 50 | 150 | 9 | 1.888888889 | 79.01234568 | 5.618655693 | 81 |
| 10+1 | 10 | 1 | 10 | 33.33333333 | 90.90909091 | 272.7272727 | 10 | 10 | 0 | 409.6 | 1 |
| 10+2 | 10 | 2 | 11 | 33.33333333 | 83.33333333 | 250 | 10 | 5.5 | 45 | 6.4 | 64 |
| 10+3 | 10 | 3 | 12 | 33.33333333 | 76.92307692 | 230.7692308 | 10 | 4 | 60 | 1.685596708 | 243 |
| 10+4 | 10 | 4 | 13 | 33.33333333 | 71.42857143 | 214.2857143 | 10 | 3.25 | 67.5 | 1.6 | 256 |
| 10+5 | 10 | 5 | 14 | 33.33333333 | 66.66666667 | 200 | 10 | 2.8 | 72 | 3.2768 | 125 |
| 10+6 | 10 | 6 | 15 | 33.33333333 | 62.5 | 187.5 | 10 | 2.5 | 75 | 1.896296296 | 216 |
| 10+7 | 10 | 7 | 16 | 33.33333333 | 58.82352941 | 176.4705882 | 10 | 2.285714286 | 77.14285714 | 1.194169096 | 343 |
| 10+8 | 10 | 8 | 17 | 33.33333333 | 55.55555556 | 166.6666667 | 10 | 2.125 | 78.75 | 0.8 | 512 |
| 10+9 | 10 | 9 | 18 | 33.33333333 | 52.63157895 | 157.8947368 | 10 | 2 | 80 | 0.561865569 | 729 |
| 10+10 | 10 | 10 | 19 | 33.33333333 | 50 | 150 | 10 | 1.9 | 81 | 4.096 | 100 |
| 11+1 | 11 | 1 | 11 | 33.33333333 | 91.66666667 | 275 | 11 | 11 | 0 | 372.3636364 | 1 |
| 11+2 | 11 | 2 | 12 | 33.33333333 | 84.61538462 | 253.8461538 | 11 | 6 | 45.45454545 | 2.909090909 | 128 |
| 11+3 | 11 | 3 | 13 | 33.33333333 | 78.57142857 | 235.7142857 | 11 | 4.333333333 | 60.60606061 | 1.532360643 | 243 |
| 11+4 | 11 | 4 | 14 | 33.33333333 | 73.33333333 | 220 | 11 | 3.5 | 68.18181818 | 1.454545455 | 256 |
| 11+5 | 11 | 5 | 15 | 33.33333333 | 68.75 | 206.25 | 11 | 3 | 72.72727273 | 0.595781818 | 625 |
| 11+6 | 11 | 6 | 16 | 33.33333333 | 64.70588235 | 194.1176471 | 11 | 2.666666667 | 75.75757576 | 1.723905724 | 216 |
| 11+7 | 11 | 7 | 17 | 33.33333333 | 61.11111111 | 183.3333333 | 11 | 2.428571429 | 77.92207792 | 1.085608269 | 343 |
| 11+8 | 11 | 8 | 18 | 33.33333333 | 57.89473684 | 173.6842105 | 11 | 2.25 | 79.54545455 | 0.727272727 | 512 |
| 11+9 | 11 | 9 | 19 | 33.33333333 | 55 | 165 | 11 | 2.111111111 | 80.80808081 | 0.510786881 | 729 |
| 11+10 | 11 | 10 | 20 | 33.33333333 | 52.38095238 | 157.1428571 | 11 | 2 | 81.81818182 | 0.372363636 | 1000 |
| 11+11 | 11 | 11 | 21 | 33.33333333 | 50 | 150 | 11 | 1.909090909 | 82.6446281 | 3.077385424 | 121 |
| 11+12 | 11 | 12 | 22 | 33.33333333 | 47.82608696 | 143.4782609 | 11 | 1.833333333 | 83.33333333 | 2.585858586 | 144 |
| 12+1 | 12 | 1 | 12 | 33.33333333 | 92.30769231 | 276.9230769 | 12 | 12 | 0 | 341.3333333 | 1 |
| 12+2 | 12 | 2 | 13 | 33.33333333 | 85.71428571 | 257.1428571 | 12 | 6.5 | 45.83333333 | 2.666666667 | 128 |
| 12+3 | 12 | 3 | 14 | 33.33333333 | 80 | 240 | 12 | 4.666666667 | 61.11111111 | 1.404663923 | 243 |
| 12+4 | 12 | 4 | 15 | 33.33333333 | 75 | 225 | 12 | 3.75 | 68.75 | 1.333333333 | 256 |
| 12+5 | 12 | 5 | 16 | 33.33333333 | 70.58823529 | 211.7647059 | 12 | 3.2 | 73.33333333 | 0.546133333 | 625 |
| 12+6 | 12 | 6 | 17 | 33.33333333 | 66.66666667 | 200 | 12 | 2.833333333 | 76.38888889 | 1.580246914 | 216 |
| 12+7 | 12 | 7 | 18 | 33.33333333 | 63.15789474 | 189.4736842 | 12 | 2.571428571 | 78.57142857 | 0.995140914 | 343 |
| 12+8 | 12 | 8 | 19 | 33.33333333 | 60 | 180 | 12 | 2.375 | 80.20833333 | 0.666666667 | 512 |
| 12+9 | 12 | 9 | 20 | 33.33333333 | 57.14285714 | 171.4285714 | 12 | 2.222222222 | 81.48148148 | 0.468221308 | 729 |
| 12+10 | 12 | 10 | 21 | 33.33333333 | 54.54545455 | 163.6363636 | 12 | 2.1 | 82.5 | 0.341333333 | 1000 |
| 12+11 | 12 | 11 | 22 | 33.33333333 | 52.17391304 | 156.5217391 | 12 | 2 | 83.33333333 | 0.256448785 | 1331 |
| 12+12 | 12 | 12 | 23 | 33.33333333 | 50 | 150 | 12 | 1.916666667 | 84.02777778 | 2.37037037 | 144 |
