From 298da45c5c4a2be319c49876c9f1d0addbb54b04 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Tue, 3 Jun 2014 17:45:47 +0200 Subject: [PATCH] erasure-code: ErasureCodeInterface::get_chunk_mapping() Add support for erasure code plugins that do not sequentially map the chunks encoded to the corresponding index. This is mostly transparent to the caller, except when it comes to retrieving the data chunks when reading. For this purpose there needs to be a remapping function so the caller has a way to figure out which chunks actually contain the data and reorder them. Signed-off-by: Loic Dachary --- src/erasure-code/ErasureCode.cc | 4 +++ src/erasure-code/ErasureCode.h | 6 ++++ src/erasure-code/ErasureCodeInterface.h | 36 ++++++++++++++++++++++ src/test/erasure-code/ErasureCodeExample.h | 5 +++ 4 files changed, 51 insertions(+) diff --git a/src/erasure-code/ErasureCode.cc b/src/erasure-code/ErasureCode.cc index 498a06b061779..0d3f62f6354d9 100644 --- a/src/erasure-code/ErasureCode.cc +++ b/src/erasure-code/ErasureCode.cc @@ -149,6 +149,10 @@ int ErasureCode::parse(const map ¶meters, return 0; } +const vector &ErasureCode::get_chunk_mapping() const { + return chunk_mapping; +} + int ErasureCode::to_int(const std::string &name, const map ¶meters, int *value, diff --git a/src/erasure-code/ErasureCode.h b/src/erasure-code/ErasureCode.h index b70e7f87d7f8a..637a009d78c2a 100644 --- a/src/erasure-code/ErasureCode.h +++ b/src/erasure-code/ErasureCode.h @@ -22,12 +22,16 @@ */ +#include + #include "ErasureCodeInterface.h" namespace ceph { class ErasureCode : public ErasureCodeInterface { public: + vector chunk_mapping; + virtual ~ErasureCode() {} virtual int minimum_to_decode(const set &want_to_read, @@ -58,6 +62,8 @@ namespace ceph { virtual int parse(const map ¶meters, ostream *ss); + virtual const vector &get_chunk_mapping() const; + static int to_int(const std::string &name, const map ¶meters, int *value, diff --git a/src/erasure-code/ErasureCodeInterface.h b/src/erasure-code/ErasureCodeInterface.h index 499cfc96ddc6c..f7b2bdc258fcd 100644 --- a/src/erasure-code/ErasureCodeInterface.h +++ b/src/erasure-code/ErasureCodeInterface.h @@ -142,6 +142,7 @@ #include #include +#include #include "include/memory.h" #include "include/buffer.h" @@ -347,6 +348,41 @@ namespace ceph { const map &chunks, map *decoded) = 0; + /** + * Return the ordered list of chunks or an empty vector + * if no remapping is necessary. + * + * By default encoding an object with K=2,M=1 will create three + * chunks, the first two are data and the last one coding. For + * a 10MB object, it would be: + * + * chunk 0 for the first 5MB + * chunk 1 for the last 5MB + * chunk 2 for the 5MB coding chunk + * + * The plugin may, however, decide to remap them in a different + * order, such as: + * + * chunk 0 for the last 5MB + * chunk 1 for the 5MB coding chunk + * chunk 2 for the first 5MB + * + * The vector remaps the chunks so that the first chunks are + * data, in sequential order, and the last chunks contain parity + * in the same order as they were output by the encoding function. + * + * In the example above the mapping would be: + * + * [ 1, 2, 0 ] + * + * The returned vector only contains information for chunks + * that need remapping. If no remapping is necessary, the + * vector is empty. + * + * @return vector list of indices of chunks to be remapped + */ + virtual const vector &get_chunk_mapping() const = 0; + /** * Decode the first **get_data_chunk_count()** **chunks** and * concatenate them them into **decoded**. diff --git a/src/test/erasure-code/ErasureCodeExample.h b/src/test/erasure-code/ErasureCodeExample.h index 2861b648c1ed7..dce35d18e557f 100644 --- a/src/test/erasure-code/ErasureCodeExample.h +++ b/src/test/erasure-code/ErasureCodeExample.h @@ -193,6 +193,11 @@ public: return 0; } + virtual const vector &get_chunk_mapping() const { + static vector mapping; + return mapping; + } + }; #endif -- 2.39.5