1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
7 * Copyright (C) 2014 Red Hat <contact@redhat.com>
9 * Author: Loic Dachary <loic@dachary.org>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
21 #include "include/str_map.h"
22 #include "common/debug.h"
23 #include "crush/CrushWrapper.h"
24 #include "osd/osd_types.h"
25 #include "include/stringify.h"
26 #include "erasure-code/ErasureCodePlugin.h"
27 #include "json_spirit/json_spirit_writer.h"
29 #include "ErasureCodeLrc.h"
31 // re-include our assert to clobber boost's
32 #include "include/assert.h"
34 #define dout_context g_ceph_context
35 #define dout_subsys ceph_subsys_osd
37 #define dout_prefix _prefix(_dout)
41 static ostream
& _prefix(std::ostream
* _dout
)
43 return *_dout
<< "ErasureCodeLrc: ";
46 int ErasureCodeLrc::create_rule(const string
&name
,
50 if (crush
.rule_exists(name
)) {
51 *ss
<< "rule " << name
<< " exists";
54 if (!crush
.name_exists(rule_root
)) {
55 *ss
<< "root item " << rule_root
<< " does not exist";
58 int root
= crush
.get_item_id(rule_root
);
59 if (rule_device_class
.size()) {
60 if (!crush
.class_exists(rule_device_class
)) {
61 *ss
<< "device class " << rule_device_class
<< " does not exist";
64 int c
= crush
.get_class_id(rule_device_class
);
65 if (crush
.class_bucket
.count(root
) == 0 ||
66 crush
.class_bucket
[root
].count(c
) == 0) {
67 *ss
<< "root item " << rule_root
<< " has no devices with class "
71 root
= crush
.class_bucket
[root
][c
];
76 for (rno
= 0; rno
< crush
.get_max_rules(); rno
++) {
77 if (!crush
.rule_exists(rno
) && !crush
.ruleset_exists(rno
))
82 int steps
= 4 + rule_steps
.size();
84 int max_rep
= get_chunk_count();
86 ret
= crush
.add_rule(steps
, rule
, pg_pool_t::TYPE_ERASURE
,
87 min_rep
, max_rep
, rno
);
91 ret
= crush
.set_rule_step(rno
, step
++, CRUSH_RULE_SET_CHOOSELEAF_TRIES
, 5, 0);
93 ret
= crush
.set_rule_step(rno
, step
++, CRUSH_RULE_SET_CHOOSE_TRIES
, 100, 0);
95 ret
= crush
.set_rule_step(rno
, step
++, CRUSH_RULE_TAKE
, root
, 0);
97 // [ [ "choose", "rack", 2 ],
98 // [ "chooseleaf", "host", 5 ] ]
99 for (vector
<Step
>::const_iterator i
= rule_steps
.begin();
100 i
!= rule_steps
.end();
102 int op
= i
->op
== "chooseleaf" ?
103 CRUSH_RULE_CHOOSELEAF_INDEP
: CRUSH_RULE_CHOOSE_INDEP
;
104 int type
= crush
.get_type_id(i
->type
);
106 *ss
<< "unknown crush type " << i
->type
;
109 ret
= crush
.set_rule_step(rno
, step
++, op
, i
->n
, type
);
112 ret
= crush
.set_rule_step(rno
, step
++, CRUSH_RULE_EMIT
, 0, 0);
114 crush
.set_rule_name(rno
, name
);
118 int ErasureCodeLrc::layers_description(const ErasureCodeProfile
&profile
,
119 json_spirit::mArray
*description
,
122 if (profile
.count("layers") == 0) {
123 *ss
<< "could not find 'layers' in " << profile
<< std::endl
;
124 return ERROR_LRC_DESCRIPTION
;
126 string str
= profile
.find("layers")->second
;
128 json_spirit::mValue json
;
129 json_spirit::read_or_throw(str
, json
);
131 if (json
.type() != json_spirit::array_type
) {
132 *ss
<< "layers='" << str
133 << "' must be a JSON array but is of type "
134 << json
.type() << " instead" << std::endl
;
135 return ERROR_LRC_ARRAY
;
137 *description
= json
.get_array();
138 } catch (json_spirit::Error_position
&e
) {
139 *ss
<< "failed to parse layers='" << str
<< "'"
140 << " at line " << e
.line_
<< ", column " << e
.column_
141 << " : " << e
.reason_
<< std::endl
;
142 return ERROR_LRC_PARSE_JSON
;
147 int ErasureCodeLrc::layers_parse(string description_string
,
148 json_spirit::mArray description
,
152 for (vector
<json_spirit::mValue
>::iterator i
= description
.begin();
153 i
!= description
.end();
155 if (i
->type() != json_spirit::array_type
) {
156 stringstream json_string
;
157 json_spirit::write(*i
, json_string
);
158 *ss
<< "each element of the array "
159 << description_string
<< " must be a JSON array but "
160 << json_string
.str() << " at position " << position
161 << " is of type " << i
->type() << " instead" << std::endl
;
162 return ERROR_LRC_ARRAY
;
164 json_spirit::mArray layer_json
= i
->get_array();
165 ErasureCodeProfile profile
;
167 for (vector
<json_spirit::mValue
>::iterator j
= layer_json
.begin();
168 j
!= layer_json
.end();
171 if (j
->type() != json_spirit::str_type
) {
172 stringstream element
;
173 json_spirit::write(*j
, element
);
174 *ss
<< "the first element of the entry "
175 << element
.str() << " (first is zero) "
176 << position
<< " in " << description_string
177 << " is of type " << (*j
).type() << " instead of string" << std::endl
;
178 return ERROR_LRC_STR
;
180 layers
.push_back(Layer(j
->get_str()));
181 Layer
&layer
= layers
.back();
182 layer
.chunks_map
= j
->get_str();
183 } else if(index
== 1) {
184 Layer
&layer
= layers
.back();
185 if (j
->type() != json_spirit::str_type
&&
186 j
->type() != json_spirit::obj_type
) {
187 stringstream element
;
188 json_spirit::write(*j
, element
);
189 *ss
<< "the second element of the entry "
190 << element
.str() << " (first is zero) "
191 << position
<< " in " << description_string
192 << " is of type " << (*j
).type() << " instead of string or object"
194 return ERROR_LRC_CONFIG_OPTIONS
;
196 if (j
->type() == json_spirit::str_type
) {
197 int err
= get_json_str_map(j
->get_str(), *ss
, &layer
.profile
);
200 } else if (j
->type() == json_spirit::obj_type
) {
201 json_spirit::mObject o
= j
->get_obj();
203 for (map
<string
, json_spirit::mValue
>::iterator i
= o
.begin();
206 layer
.profile
[i
->first
] = i
->second
.get_str();
210 // ignore trailing elements
217 int ErasureCodeLrc::layers_init(ostream
*ss
)
219 ErasureCodePluginRegistry
®istry
= ErasureCodePluginRegistry::instance();
220 for (unsigned int i
= 0; i
< layers
.size(); i
++) {
221 Layer
&layer
= layers
[i
];
223 for(std::string::iterator it
= layer
.chunks_map
.begin();
224 it
!= layer
.chunks_map
.end();
227 layer
.data
.push_back(position
);
229 layer
.coding
.push_back(position
);
230 if (*it
== 'c' || *it
== 'D')
231 layer
.chunks_as_set
.insert(position
);
234 layer
.chunks
= layer
.data
;
235 layer
.chunks
.insert(layer
.chunks
.end(),
236 layer
.coding
.begin(), layer
.coding
.end());
237 if (layer
.profile
.find("k") == layer
.profile
.end())
238 layer
.profile
["k"] = stringify(layer
.data
.size());
239 if (layer
.profile
.find("m") == layer
.profile
.end())
240 layer
.profile
["m"] = stringify(layer
.coding
.size());
241 if (layer
.profile
.find("plugin") == layer
.profile
.end())
242 layer
.profile
["plugin"] = "jerasure";
243 if (layer
.profile
.find("technique") == layer
.profile
.end())
244 layer
.profile
["technique"] = "reed_sol_van";
245 int err
= registry
.factory(layer
.profile
["plugin"],
256 int ErasureCodeLrc::layers_sanity_checks(string description_string
,
261 if (layers
.size() < 1) {
262 *ss
<< "layers parameter has " << layers
.size()
263 << " which is less than the minimum of one. "
264 << description_string
<< std::endl
;
265 return ERROR_LRC_LAYERS_COUNT
;
267 for (vector
<Layer
>::const_iterator layer
= layers
.begin();
268 layer
!= layers
.end();
270 if (chunk_count
!= layer
->chunks_map
.length()) {
271 *ss
<< "the first element of the array at position "
272 << position
<< " (starting from zero) "
273 << " is the string '" << layer
->chunks_map
274 << " found in the layers parameter "
275 << description_string
<< ". It is expected to be "
276 << chunk_count
<< " characters long but is "
277 << layer
->chunks_map
.length() << " characters long instead "
279 return ERROR_LRC_MAPPING_SIZE
;
285 int ErasureCodeLrc::parse(ErasureCodeProfile
&profile
,
288 int r
= ErasureCode::parse(profile
, ss
);
292 return parse_rule(profile
, ss
);
295 const string
ErasureCodeLrc::DEFAULT_KML("-1");
297 int ErasureCodeLrc::parse_kml(ErasureCodeProfile
&profile
,
300 int err
= ErasureCode::parse(profile
, ss
);
301 const int DEFAULT_INT
= -1;
303 err
|= to_int("k", profile
, &k
, DEFAULT_KML
, ss
);
304 err
|= to_int("m", profile
, &m
, DEFAULT_KML
, ss
);
305 err
|= to_int("l", profile
, &l
, DEFAULT_KML
, ss
);
307 if (k
== DEFAULT_INT
&& m
== DEFAULT_INT
&& l
== DEFAULT_INT
)
310 if ((k
!= DEFAULT_INT
|| m
!= DEFAULT_INT
|| l
!= DEFAULT_INT
) &&
311 (k
== DEFAULT_INT
|| m
== DEFAULT_INT
|| l
== DEFAULT_INT
)) {
312 *ss
<< "All of k, m, l must be set or none of them in "
313 << profile
<< std::endl
;
314 return ERROR_LRC_ALL_OR_NOTHING
;
317 const char *generated
[] = { "mapping",
321 for (int i
= 0; i
< 3; i
++) {
322 if (profile
.count(generated
[i
])) {
323 *ss
<< "The " << generated
[i
] << " parameter cannot be set "
324 << "when k, m, l are set in " << profile
<< std::endl
;
325 return ERROR_LRC_GENERATED
;
330 *ss
<< "k + m must be a multiple of l in "
331 << profile
<< std::endl
;
332 return ERROR_LRC_K_M_MODULO
;
335 int local_group_count
= (k
+ m
) / l
;
337 if (k
% local_group_count
) {
338 *ss
<< "k must be a multiple of (k + m) / l in "
339 << profile
<< std::endl
;
340 return ERROR_LRC_K_MODULO
;
343 if (m
% local_group_count
) {
344 *ss
<< "m must be a multiple of (k + m) / l in "
345 << profile
<< std::endl
;
346 return ERROR_LRC_M_MODULO
;
350 for (int i
= 0; i
< local_group_count
; i
++) {
351 mapping
+= string(k
/ local_group_count
, 'D') +
352 string(m
/ local_group_count
, '_') + "_";
354 profile
["mapping"] = mapping
;
356 string layers
= "[ ";
360 for (int i
= 0; i
< local_group_count
; i
++) {
361 layers
+= string(k
/ local_group_count
, 'D') +
362 string(m
/ local_group_count
, 'c') + "_";
364 layers
+= "\", \"\" ],";
367 for (int i
= 0; i
< local_group_count
; i
++) {
369 for (int j
= 0; j
< local_group_count
; j
++) {
371 layers
+= string(l
, 'D') + "c";
373 layers
+= string(l
+ 1, '_');
375 layers
+= "\", \"\" ],";
377 profile
["layers"] = layers
+ "]";
379 ErasureCodeProfile::const_iterator parameter
;
380 string rule_locality
;
381 parameter
= profile
.find("crush-locality");
382 if (parameter
!= profile
.end())
383 rule_locality
= parameter
->second
;
384 string rule_failure_domain
= "host";
385 parameter
= profile
.find("crush-failure-domain");
386 if (parameter
!= profile
.end())
387 rule_failure_domain
= parameter
->second
;
389 if (rule_locality
!= "") {
391 rule_steps
.push_back(Step("choose", rule_locality
,
393 rule_steps
.push_back(Step("chooseleaf", rule_failure_domain
,
395 } else if (rule_failure_domain
!= "") {
397 rule_steps
.push_back(Step("chooseleaf", rule_failure_domain
, 0));
403 int ErasureCodeLrc::parse_rule(ErasureCodeProfile
&profile
,
407 err
|= to_string("crush-root", profile
,
410 err
|= to_string("crush-device-class", profile
,
414 if (profile
.count("crush-steps") != 0) {
416 string str
= profile
.find("crush-steps")->second
;
417 json_spirit::mArray description
;
419 json_spirit::mValue json
;
420 json_spirit::read_or_throw(str
, json
);
422 if (json
.type() != json_spirit::array_type
) {
423 *ss
<< "crush-steps='" << str
424 << "' must be a JSON array but is of type "
425 << json
.type() << " instead" << std::endl
;
426 return ERROR_LRC_ARRAY
;
428 description
= json
.get_array();
429 } catch (json_spirit::Error_position
&e
) {
430 *ss
<< "failed to parse crush-steps='" << str
<< "'"
431 << " at line " << e
.line_
<< ", column " << e
.column_
432 << " : " << e
.reason_
<< std::endl
;
433 return ERROR_LRC_PARSE_JSON
;
437 for (vector
<json_spirit::mValue
>::iterator i
= description
.begin();
438 i
!= description
.end();
440 if (i
->type() != json_spirit::array_type
) {
441 stringstream json_string
;
442 json_spirit::write(*i
, json_string
);
443 *ss
<< "element of the array "
444 << str
<< " must be a JSON array but "
445 << json_string
.str() << " at position " << position
446 << " is of type " << i
->type() << " instead" << std::endl
;
447 return ERROR_LRC_ARRAY
;
449 int r
= parse_rule_step(str
, i
->get_array(), ss
);
457 int ErasureCodeLrc::parse_rule_step(string description_string
,
458 json_spirit::mArray description
,
461 stringstream json_string
;
462 json_spirit::write(description
, json_string
);
467 for (vector
<json_spirit::mValue
>::iterator i
= description
.begin();
468 i
!= description
.end();
470 if ((position
== 0 || position
== 1) &&
471 i
->type() != json_spirit::str_type
) {
472 *ss
<< "element " << position
<< " of the array "
473 << json_string
.str() << " found in " << description_string
474 << " must be a JSON string but is of type "
475 << i
->type() << " instead" << std::endl
;
476 return position
== 0 ? ERROR_LRC_RULE_OP
: ERROR_LRC_RULE_TYPE
;
478 if (position
== 2 && i
->type() != json_spirit::int_type
) {
479 *ss
<< "element " << position
<< " of the array "
480 << json_string
.str() << " found in " << description_string
481 << " must be a JSON int but is of type "
482 << i
->type() << " instead" << std::endl
;
483 return ERROR_LRC_RULE_N
;
493 rule_steps
.push_back(Step(op
, type
, n
));
497 int ErasureCodeLrc::init(ErasureCodeProfile
&profile
,
502 r
= parse_kml(profile
, ss
);
506 r
= parse(profile
, ss
);
510 json_spirit::mArray description
;
511 r
= layers_description(profile
, &description
, ss
);
515 string description_string
= profile
.find("layers")->second
;
517 dout(10) << "init(" << description_string
<< ")" << dendl
;
519 r
= layers_parse(description_string
, description
, ss
);
527 if (profile
.count("mapping") == 0) {
528 *ss
<< "the 'mapping' profile is missing from " << profile
;
529 return ERROR_LRC_MAPPING
;
531 string mapping
= profile
.find("mapping")->second
;
532 data_chunk_count
= 0;
533 for(std::string::iterator it
= mapping
.begin(); it
!= mapping
.end(); ++it
) {
537 chunk_count
= mapping
.length();
539 r
= layers_sanity_checks(description_string
, ss
);
544 // When initialized with kml, the profile parameters
545 // that were generated should not be stored because
546 // they would otherwise be exposed to the caller.
548 if (profile
.find("l") != profile
.end() &&
549 profile
.find("l")->second
!= DEFAULT_KML
) {
550 profile
.erase("mapping");
551 profile
.erase("layers");
553 ErasureCode::init(profile
, ss
);
557 set
<int> ErasureCodeLrc::get_erasures(const set
<int> &want
,
558 const set
<int> &available
) const
561 set_difference(want
.begin(), want
.end(),
562 available
.begin(), available
.end(),
563 inserter(result
, result
.end()));
567 unsigned int ErasureCodeLrc::get_chunk_size(unsigned int object_size
) const
569 return layers
.front().erasure_code
->get_chunk_size(object_size
);
572 void p(const set
<int> &s
) { cerr
<< s
; } // for gdb
574 int ErasureCodeLrc::minimum_to_decode(const set
<int> &want_to_read
,
575 const set
<int> &available_chunks
,
578 dout(20) << __func__
<< " want_to_read " << want_to_read
579 << " available_chunks " << available_chunks
<< dendl
;
581 set
<int> erasures_total
;
582 set
<int> erasures_not_recovered
;
583 set
<int> erasures_want
;
584 for (unsigned int i
= 0; i
< get_chunk_count(); ++i
) {
585 if (available_chunks
.count(i
) == 0) {
586 erasures_total
.insert(i
);
587 erasures_not_recovered
.insert(i
);
588 if (want_to_read
.count(i
) != 0)
589 erasures_want
.insert(i
);
596 // When no chunk is missing there is no need to read more than what
599 if (erasures_want
.empty()) {
600 *minimum
= want_to_read
;
601 dout(20) << __func__
<< " minimum == want_to_read == "
602 << want_to_read
<< dendl
;
609 // Try to recover erasures with as few chunks as possible.
611 for (vector
<Layer
>::reverse_iterator i
= layers
.rbegin();
615 // If this layer has no chunk that we want, skip it.
618 set_intersection(want_to_read
.begin(), want_to_read
.end(),
619 i
->chunks_as_set
.begin(), i
->chunks_as_set
.end(),
620 inserter(layer_want
, layer_want
.end()));
621 if (layer_want
.empty())
624 // Are some of the chunks we want missing ?
626 set
<int> layer_erasures
;
627 set_intersection(layer_want
.begin(), layer_want
.end(),
628 erasures_want
.begin(), erasures_want
.end(),
629 inserter(layer_erasures
, layer_erasures
.end()));
630 set
<int> layer_minimum
;
631 if (layer_erasures
.empty()) {
633 // The chunks we want are available, this is the minimum we need
636 layer_minimum
= layer_want
;
639 set_intersection(i
->chunks_as_set
.begin(), i
->chunks_as_set
.end(),
640 erasures_not_recovered
.begin(), erasures_not_recovered
.end(),
641 inserter(erasures
, erasures
.end()));
643 if (erasures
.size() > i
->erasure_code
->get_coding_chunk_count()) {
645 // There are too many erasures for this layer to recover: skip
646 // it and hope that an upper layer will be do better.
651 // Get all available chunks in that layer to recover the
654 set_difference(i
->chunks_as_set
.begin(), i
->chunks_as_set
.end(),
655 erasures_not_recovered
.begin(), erasures_not_recovered
.end(),
656 inserter(layer_minimum
, layer_minimum
.end()));
658 // Chunks recovered by this layer are removed from the list of
659 // erasures so that upper levels do not attempt to recover
662 for (set
<int>::const_iterator j
= erasures
.begin();
665 erasures_not_recovered
.erase(*j
);
666 if (erasures_want
.count(*j
))
667 erasures_want
.erase(*j
);
671 minimum
->insert(layer_minimum
.begin(), layer_minimum
.end());
673 if (erasures_want
.empty()) {
674 minimum
->insert(want_to_read
.begin(), want_to_read
.end());
675 for (set
<int>::const_iterator i
= erasures_total
.begin();
676 i
!= erasures_total
.end();
678 if (minimum
->count(*i
))
681 dout(20) << __func__
<< " minimum = " << *minimum
<< dendl
;
690 // The previous strategy failed to recover from all erasures.
692 // Try to recover as many chunks as possible, even from layers
693 // that do not contain chunks that we want, in the hope that it
694 // will help the upper layers.
696 set
<int> erasures_total
;
697 for (unsigned int i
= 0; i
< get_chunk_count(); ++i
) {
698 if (available_chunks
.count(i
) == 0)
699 erasures_total
.insert(i
);
702 for (vector
<Layer
>::reverse_iterator i
= layers
.rbegin();
705 set
<int> layer_erasures
;
706 set_intersection(i
->chunks_as_set
.begin(), i
->chunks_as_set
.end(),
707 erasures_total
.begin(), erasures_total
.end(),
708 inserter(layer_erasures
, layer_erasures
.end()));
710 // If this layer has no erasure, skip it
712 if (layer_erasures
.empty())
715 if (layer_erasures
.size() > 0 &&
716 layer_erasures
.size() <= i
->erasure_code
->get_coding_chunk_count()) {
718 // chunks recovered by this layer are removed from the list of
719 // erasures so that upper levels know they can rely on their
722 for (set
<int>::const_iterator j
= layer_erasures
.begin();
723 j
!= layer_erasures
.end();
725 erasures_total
.erase(*j
);
729 if (erasures_total
.empty()) {
731 // Do not try to be smart about what chunks are necessary to
732 // recover, use all available chunks.
734 *minimum
= available_chunks
;
735 dout(20) << __func__
<< " minimum == available_chunks == "
736 << available_chunks
<< dendl
;
741 derr
<< __func__
<< " not enough chunks in " << available_chunks
742 << " to read " << want_to_read
<< dendl
;
746 int ErasureCodeLrc::encode_chunks(const set
<int> &want_to_encode
,
747 map
<int, bufferlist
> *encoded
)
749 unsigned int top
= layers
.size();
750 for (vector
<Layer
>::reverse_iterator i
= layers
.rbegin();
754 if (includes(i
->chunks_as_set
.begin(), i
->chunks_as_set
.end(),
755 want_to_encode
.begin(), want_to_encode
.end()))
759 for (unsigned int i
= top
; i
< layers
.size(); ++i
) {
760 const Layer
&layer
= layers
[i
];
761 set
<int> layer_want_to_encode
;
762 map
<int, bufferlist
> layer_encoded
;
764 for (vector
<int>::const_iterator c
= layer
.chunks
.begin();
765 c
!= layer
.chunks
.end();
767 layer_encoded
[j
] = (*encoded
)[*c
];
768 if (want_to_encode
.find(*c
) != want_to_encode
.end())
769 layer_want_to_encode
.insert(j
);
772 int err
= layer
.erasure_code
->encode_chunks(layer_want_to_encode
,
775 derr
<< __func__
<< " layer " << layer
.chunks_map
776 << " failed with " << err
<< " trying to encode "
777 << layer_want_to_encode
<< dendl
;
784 int ErasureCodeLrc::decode_chunks(const set
<int> &want_to_read
,
785 const map
<int, bufferlist
> &chunks
,
786 map
<int, bufferlist
> *decoded
)
788 set
<int> available_chunks
;
790 for (unsigned int i
= 0; i
< get_chunk_count(); ++i
) {
791 if (chunks
.count(i
) != 0)
792 available_chunks
.insert(i
);
797 set
<int> want_to_read_erasures
;
799 for (vector
<Layer
>::reverse_iterator layer
= layers
.rbegin();
800 layer
!= layers
.rend();
802 set
<int> layer_erasures
;
803 set_intersection(layer
->chunks_as_set
.begin(), layer
->chunks_as_set
.end(),
804 erasures
.begin(), erasures
.end(),
805 inserter(layer_erasures
, layer_erasures
.end()));
807 if (layer_erasures
.size() >
808 layer
->erasure_code
->get_coding_chunk_count()) {
809 // skip because there are too many erasures for this layer to recover
810 } else if(layer_erasures
.size() == 0) {
811 // skip because all chunks are already available
813 set
<int> layer_want_to_read
;
814 map
<int, bufferlist
> layer_chunks
;
815 map
<int, bufferlist
> layer_decoded
;
817 for (vector
<int>::const_iterator c
= layer
->chunks
.begin();
818 c
!= layer
->chunks
.end();
821 // Pick chunks from *decoded* instead of *chunks* to re-use
822 // chunks recovered by previous layers. In other words
823 // *chunks* does not change but *decoded* gradually improves
824 // as more layers recover from erasures.
826 if (erasures
.count(*c
) == 0)
827 layer_chunks
[j
] = (*decoded
)[*c
];
828 if (want_to_read
.count(*c
) != 0)
829 layer_want_to_read
.insert(j
);
830 layer_decoded
[j
] = (*decoded
)[*c
];
833 int err
= layer
->erasure_code
->decode_chunks(layer_want_to_read
,
837 derr
<< __func__
<< " layer " << layer
->chunks_map
838 << " failed with " << err
<< " trying to decode "
839 << layer_want_to_read
<< " with " << available_chunks
<< dendl
;
843 for (vector
<int>::const_iterator c
= layer
->chunks
.begin();
844 c
!= layer
->chunks
.end();
846 (*decoded
)[*c
] = layer_decoded
[j
];
848 if (erasures
.count(*c
) != 0)
851 want_to_read_erasures
.clear();
852 set_intersection(erasures
.begin(), erasures
.end(),
853 want_to_read
.begin(), want_to_read
.end(),
854 inserter(want_to_read_erasures
, want_to_read_erasures
.end()));
855 if (want_to_read_erasures
.size() == 0)
860 if (want_to_read_erasures
.size() > 0) {
861 derr
<< __func__
<< " want to read " << want_to_read
862 << " with available_chunks = " << available_chunks
863 << " end up being unable to read " << want_to_read_erasures
<< dendl
;