Skip to content

Commit f3753fd

Browse files
jamieprydeaainscow
authored andcommitted
erasure-code: Add optimization flags for plugins
Add flags to erasure code plugins to report supported optimizations and new unittest_erasure_code_plugins to test these flags for many permutations of plugins and profiles. Signed-off-by: Bill Scales <[email protected]> [Taken from Bill's fork with permission] Signed-off-by: Jamie Pryde <[email protected]>
1 parent eb4c3bf commit f3753fd

File tree

10 files changed

+583
-0
lines changed

10 files changed

+583
-0
lines changed

src/erasure-code/ErasureCodeInterface.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,78 @@ namespace ceph {
476476
virtual int decode_concat(const std::map<int, bufferlist> &chunks,
477477
bufferlist *decoded) = 0;
478478

479+
using plugin_flags = uint64_t;
480+
481+
/**
482+
* Return a set of flags indicating which EC optimizations are supported
483+
* by the plugin.
484+
*
485+
* @return logical OR of the supported performance optimizations
486+
*/
487+
virtual plugin_flags get_supported_optimizations() const = 0;
488+
enum {
489+
/* Partial read optimization assumes that the erasure code is systematic
490+
* and that concatenating the data chunks in the order returned by
491+
* get_chunk_mapping will create the data encoded for a stripe. The
492+
* optimization permits small reads to read data directly from the data
493+
* chunks without calling decode.
494+
*/
495+
FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION = 1<<0,
496+
/* Partial write optimization assumes that a write to less than one
497+
* chunk only needs to read this fragment from each data chunk in the
498+
* stripe and can then use encode to create the corresponding coding
499+
* fragments.
500+
*/
501+
FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION = 1<<1,
502+
/* Zero input zero output optimization means the erasure code has the
503+
* property that if all the data chunks are zero then the coding parity
504+
* chunks will also be zero.
505+
*/
506+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION = 1<<2,
507+
/* Zero padding optimization permits the encode and decode methods to
508+
* be called with buffers that are zero length. The plugin treats
509+
* this as a chunk of all zeros.
510+
*/
511+
FLAG_EC_PLUGIN_ZERO_PADDING_OPTIMIZATION = 1<<3,
512+
/* Parity delta write optimization means the encode_delta and
513+
* apply_delta methods are supported which allows small updates
514+
* to a stripe to be applied using a read-modify-write of a
515+
* data chunk and the coding parity chunks.
516+
*/
517+
FLAG_EC_PLUGIN_PARITY_DELTA_OPTIMIZATION = 1<<4,
518+
};
519+
static const char *get_optimization_flag_name(const plugin_flags flag) {
520+
switch (flag) {
521+
case FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION: return "partialread";
522+
case FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION: return "partialwrite";
523+
case FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION: return "zeroinout";
524+
case FLAG_EC_PLUGIN_ZERO_PADDING_OPTIMIZATION: return "zeropadding";
525+
case FLAG_EC_PLUGIN_PARITY_DELTA_OPTIMIZATION: return "paritydelta";
526+
default: return "???";
527+
}
528+
}
529+
static std::string get_optimization_flags_string(plugin_flags flags) {
530+
std::string s;
531+
for (unsigned n=0; flags && n<64; ++n) {
532+
if (flags & (1ull << n)) {
533+
if (s.length())
534+
s += ",";
535+
s += get_optimization_flag_name(1ull << n);
536+
flags -= flags & (1ull << n);
537+
}
538+
}
539+
return s;
540+
}
541+
542+
/**
543+
* Return a string describing which EC optimizations are supported
544+
* by the plugin.
545+
*
546+
* @return string of optimizations supported by the plugin
547+
*/
548+
virtual std::string get_optimizations_flags_string() const {
549+
return get_optimization_flags_string(get_supported_optimizations());
550+
}
479551
};
480552

481553
typedef std::shared_ptr<ErasureCodeInterface> ErasureCodeInterfaceRef;

src/erasure-code/clay/ErasureCodeClay.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ class ErasureCodeClay final : public ceph::ErasureCode {
4646

4747
~ErasureCodeClay() override;
4848

49+
uint64_t get_supported_optimizations() const override {
50+
if (m == 1) {
51+
// PARTIAL_WRITE optimization can be supported in
52+
// the corner case of m = 1
53+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION |
54+
FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION |
55+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION;
56+
}
57+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION |
58+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION;
59+
}
60+
4961
unsigned int get_chunk_count() const override {
5062
return k+m;
5163
}

src/erasure-code/isa/ErasureCodeIsa.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class ErasureCodeIsa : public ceph::ErasureCode {
6464
{
6565
}
6666

67+
uint64_t get_supported_optimizations() const override {
68+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION |
69+
FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION |
70+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION;
71+
}
72+
6773
unsigned int
6874
get_chunk_count() const override
6975
{

src/erasure-code/jerasure/ErasureCodeJerasure.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class ErasureCodeJerasure : public ceph::ErasureCode {
4545
{}
4646

4747
~ErasureCodeJerasure() override {}
48+
49+
uint64_t get_supported_optimizations() const override {
50+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION |
51+
FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION |
52+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION;
53+
}
54+
4855

4956
unsigned int get_chunk_count() const override {
5057
return k + m;

src/erasure-code/lrc/ErasureCodeLrc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ class ErasureCodeLrc final : public ceph::ErasureCode {
9595
CrushWrapper &crush,
9696
std::ostream *ss) const override;
9797

98+
uint64_t get_supported_optimizations() const override {
99+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION |
100+
FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION |
101+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION;
102+
}
103+
98104
unsigned int get_chunk_count() const override {
99105
return chunk_count;
100106
}

src/erasure-code/shec/ErasureCodeShec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class ErasureCodeShec : public ceph::ErasureCode {
6161

6262
~ErasureCodeShec() override {}
6363

64+
uint64_t get_supported_optimizations() const override {
65+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION |
66+
FLAG_EC_PLUGIN_PARTIAL_WRITE_OPTIMIZATION |
67+
FLAG_EC_PLUGIN_ZERO_INPUT_ZERO_OUTPUT_OPTIMIZATION;
68+
}
69+
6470
unsigned int get_chunk_count() const override {
6571
return k + m;
6672
}

src/test/erasure-code/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ target_link_libraries(unittest_erasure_code
6262
ceph-common
6363
)
6464

65+
if(WITH_EC_ISA_PLUGIN)
66+
# unittest_erasure_code_plugins
67+
add_executable(unittest_erasure_code_plugins
68+
TestErasureCodePlugins.cc
69+
$<TARGET_OBJECTS:unit-main>
70+
)
71+
add_ceph_unittest(unittest_erasure_code_plugins)
72+
add_dependencies(unittest_erasure_code_plugins
73+
ec_jerasure
74+
ec_isa
75+
ec_lrc
76+
ec_shec
77+
ec_clay)
78+
target_link_libraries(unittest_erasure_code_plugins
79+
global
80+
${CMAKE_DL_LIBS}
81+
ceph-common)
82+
endif(WITH_EC_ISA_PLUGIN)
83+
6584
# unittest_erasure_code_plugin_jerasure
6685
add_executable(unittest_erasure_code_plugin_jerasure
6786
TestErasureCodePluginJerasure.cc

src/test/erasure-code/ErasureCodeExample.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ class ErasureCodeExample final : public ErasureCode {
7676
return _minimum_to_decode(want_to_read, available_chunks, minimum);
7777
}
7878

79+
uint64_t get_supported_optimizations() const override {
80+
return FLAG_EC_PLUGIN_PARTIAL_READ_OPTIMIZATION;
81+
}
82+
7983
unsigned int get_chunk_count() const override {
8084
return DATA_CHUNKS + CODING_CHUNKS;
8185
}

src/test/erasure-code/TestErasureCode.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ErasureCodeTest : public ErasureCode {
3939
return 0;
4040
}
4141

42+
uint64_t get_supported_optimizations() const override { return 0; }
4243
unsigned int get_chunk_count() const override { return k + m; }
4344
unsigned int get_data_chunk_count() const override { return k; }
4445
unsigned int get_chunk_size(unsigned int object_size) const override {

0 commit comments

Comments
 (0)