]> git.proxmox.com Git - ceph.git/blame - ceph/doc/dev/osd_internals/erasure_coding/developer_notes.rst
update sources to v12.1.0
[ceph.git] / ceph / doc / dev / osd_internals / erasure_coding / developer_notes.rst
CommitLineData
7c673cae
FG
1============================
2Erasure Code developer notes
3============================
4
5Introduction
6------------
7
8Each chapter of this document explains an aspect of the implementation
9of the erasure code within Ceph. It is mostly based on examples being
10explained to demonstrate how things work.
11
12Reading and writing encoded chunks from and to OSDs
13---------------------------------------------------
14
15An erasure coded pool stores each object as K+M chunks. It is divided
16into K data chunks and M coding chunks. The pool is configured to have
17a size of K+M so that each chunk is stored in an OSD in the acting
18set. The rank of the chunk is stored as an attribute of the object.
19
20Let's say an erasure coded pool is created to use five OSDs ( K+M =
215 ) and sustain the loss of two of them ( M = 2 ).
22
23When the object *NYAN* containing *ABCDEFGHI* is written to it, the
24erasure encoding function splits the content in three data chunks,
25simply by dividing the content in three : the first contains *ABC*,
26the second *DEF* and the last *GHI*. The content will be padded if the
27content length is not a multiple of K. The function also creates two
28coding chunks : the fourth with *YXY* and the fifth with *GQC*. Each
29chunk is stored in an OSD in the acting set. The chunks are stored in
30objects that have the same name ( *NYAN* ) but reside on different
31OSDs. The order in which the chunks were created must be preserved and
32is stored as an attribute of the object ( shard_t ), in addition to its
33name. Chunk *1* contains *ABC* and is stored on *OSD5* while chunk *4*
34contains *YXY* and is stored on *OSD3*.
35
36::
37
38 +-------------------+
39 name | NYAN |
40 +-------------------+
41 content | ABCDEFGHI |
42 +--------+----------+
43 |
44 |
45 v
46 +------+------+
47 +---------------+ encode(3,2) +-----------+
48 | +--+--+---+---+ |
49 | | | | |
50 | +-------+ | +-----+ |
51 | | | | |
52 +--v---+ +--v---+ +--v---+ +--v---+ +--v---+
53 name | NYAN | | NYAN | | NYAN | | NYAN | | NYAN |
54 +------+ +------+ +------+ +------+ +------+
55 shard | 1 | | 2 | | 3 | | 4 | | 5 |
56 +------+ +------+ +------+ +------+ +------+
57 content | ABC | | DEF | | GHI | | YXY | | QGC |
58 +--+---+ +--+---+ +--+---+ +--+---+ +--+---+
59 | | | | |
60 | | | | |
61 | | +--+---+ | |
62 | | | OSD1 | | |
63 | | +------+ | |
64 | | +------+ | |
65 | +------>| OSD2 | | |
66 | +------+ | |
67 | +------+ | |
68 | | OSD3 |<----+ |
69 | +------+ |
70 | +------+ |
71 | | OSD4 |<--------------+
72 | +------+
73 | +------+
74 +----------------->| OSD5 |
75 +------+
76
77
78
79
80When the object *NYAN* is read from the erasure coded pool, the
81decoding function reads three chunks : chunk *1* containing *ABC*,
82chunk *3* containing *GHI* and chunk *4* containing *YXY* and rebuild
83the original content of the object *ABCDEFGHI*. The decoding function
84is informed that the chunks *2* and *5* are missing ( they are called
85*erasures* ). The chunk *5* could not be read because the *OSD4* is
86*out*.
87
88The decoding function could be called as soon as three chunks are
89read : *OSD2* was the slowest and its chunk does not need to be taken into
90account. This optimization is not implemented in Firefly.
91
92::
93
94 +-------------------+
95 name | NYAN |
96 +-------------------+
97 content | ABCDEFGHI |
98 +--------+----------+
99 ^
100 |
101 |
102 +------+------+
103 | decode(3,2) |
104 | erasures 2,5|
105 +-------------->| |
106 | +-------------+
107 | ^ ^
108 | | +-----+
109 | | |
110 +--+---+ +------+ +--+---+ +--+---+
111 name | NYAN | | NYAN | | NYAN | | NYAN |
112 +------+ +------+ +------+ +------+
113 shard | 1 | | 2 | | 3 | | 4 |
114 +------+ +------+ +------+ +------+
115 content | ABC | | DEF | | GHI | | YXY |
116 +--+---+ +--+---+ +--+---+ +--+---+
117 ^ . ^ ^
118 | TOO . | |
119 | SLOW . +--+---+ |
120 | ^ | OSD1 | |
121 | | +------+ |
122 | | +------+ |
123 | +-------| OSD2 | |
124 | +------+ |
125 | +------+ |
126 | | OSD3 |-----+
127 | +------+
128 | +------+
129 | | OSD4 | OUT
130 | +------+
131 | +------+
132 +------------------| OSD5 |
133 +------+
134
135
136Erasure code library
137--------------------
138
139Using `Reed-Solomon <https://en.wikipedia.org/wiki/Reed_Solomon>`_,
140with parameters K+M, object O is encoded by dividing it into chunks O1,
141O2, ... OM and computing coding chunks P1, P2, ... PK. Any K chunks
142out of the available K+M chunks can be used to obtain the original
143object. If data chunk O2 or coding chunk P2 are lost, they can be
144repaired using any K chunks out of the K+M chunks. If more than M
145chunks are lost, it is not possible to recover the object.
146
147Reading the original content of object O can be a simple
148concatenation of O1, O2, ... OM, because the plugins are using
149`systematic codes
150<http://en.wikipedia.org/wiki/Systematic_code>`_. Otherwise the chunks
151must be given to the erasure code library *decode* method to retrieve
152the content of the object.
153
154Performance depend on the parameters to the encoding functions and
155is also influenced by the packet sizes used when calling the encoding
156functions ( for Cauchy or Liberation for instance ): smaller packets
157means more calls and more overhead.
158
159Although Reed-Solomon is provided as a default, Ceph uses it via an
160`abstract API <https://github.com/ceph/ceph/blob/v0.78/src/erasure-code/ErasureCodeInterface.h>`_ designed to
161allow each pool to choose the plugin that implements it using
162key=value pairs stored in an `erasure code profile`_.
163
164.. _erasure code profile: ../../../erasure-coded-pool
165
166::
167
168 $ ceph osd erasure-code-profile set myprofile \
169 ruleset-failure-domain=osd
170 $ ceph osd erasure-code-profile get myprofile
171 directory=/usr/lib/ceph/erasure-code
172 k=2
173 m=1
174 plugin=jerasure
175 technique=reed_sol_van
176 ruleset-failure-domain=osd
177 $ ceph osd pool create ecpool 12 12 erasure myprofile
178
179The *plugin* is dynamically loaded from *directory* and expected to
180implement the *int __erasure_code_init(char *plugin_name, char *directory)* function
181which is responsible for registering an object derived from *ErasureCodePlugin*
182in the registry. The `ErasureCodePluginExample <https://github.com/ceph/ceph/blob/v0.78/src/test/erasure-code/ErasureCodePluginExample.cc>`_ plugin reads:
183
184::
185
186 ErasureCodePluginRegistry &instance =
187 ErasureCodePluginRegistry::instance();
188 instance.add(plugin_name, new ErasureCodePluginExample());
189
190The *ErasureCodePlugin* derived object must provide a factory method
191from which the concrete implementation of the *ErasureCodeInterface*
31f18b77 192object can be generated. The `ErasureCodePluginExample plugin <https://github.com/ceph/ceph/blob/v0.78/src/test/erasure-code/ErasureCodePluginExample.cc>`_ reads:
7c673cae
FG
193
194::
195
196 virtual int factory(const map<std::string,std::string> &parameters,
197 ErasureCodeInterfaceRef *erasure_code) {
198 *erasure_code = ErasureCodeInterfaceRef(new ErasureCodeExample(parameters));
199 return 0;
200 }
201
202The *parameters* argument is the list of *key=value* pairs that were
203set in the erasure code profile, before the pool was created.
204
205::
206
207 ceph osd erasure-code-profile set myprofile \
208 directory=<dir> \ # mandatory
209 plugin=jerasure \ # mandatory
210 m=10 \ # optional and plugin dependant
211 k=3 \ # optional and plugin dependant
212 technique=reed_sol_van \ # optional and plugin dependant
213
214Notes
215-----
216
217If the objects are large, it may be impractical to encode and decode
218them in memory. However, when using *RBD* a 1TB device is divided in
219many individual 4MB objects and *RGW* does the same.
220
221Encoding and decoding is implemented in the OSD. Although it could be
222implemented client side for read write, the OSD must be able to encode
223and decode on its own when scrubbing.