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 <loic@dachary.org>
This commit is contained in:
Loic Dachary 2014-06-03 17:45:47 +02:00
parent 8fb472995e
commit 298da45c5c
4 changed files with 51 additions and 0 deletions

View File

@ -149,6 +149,10 @@ int ErasureCode::parse(const map<std::string,std::string> &parameters,
return 0;
}
const vector<int> &ErasureCode::get_chunk_mapping() const {
return chunk_mapping;
}
int ErasureCode::to_int(const std::string &name,
const map<std::string,std::string> &parameters,
int *value,

View File

@ -22,12 +22,16 @@
*/
#include <vector>
#include "ErasureCodeInterface.h"
namespace ceph {
class ErasureCode : public ErasureCodeInterface {
public:
vector<int> chunk_mapping;
virtual ~ErasureCode() {}
virtual int minimum_to_decode(const set<int> &want_to_read,
@ -58,6 +62,8 @@ namespace ceph {
virtual int parse(const map<std::string,std::string> &parameters,
ostream *ss);
virtual const vector<int> &get_chunk_mapping() const;
static int to_int(const std::string &name,
const map<std::string,std::string> &parameters,
int *value,

View File

@ -142,6 +142,7 @@
#include <map>
#include <set>
#include <vector>
#include "include/memory.h"
#include "include/buffer.h"
@ -347,6 +348,41 @@ namespace ceph {
const map<int, bufferlist> &chunks,
map<int, bufferlist> *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<int> 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<int> only contains information for chunks
* that need remapping. If no remapping is necessary, the
* vector<int> is empty.
*
* @return vector<int> list of indices of chunks to be remapped
*/
virtual const vector<int> &get_chunk_mapping() const = 0;
/**
* Decode the first **get_data_chunk_count()** **chunks** and
* concatenate them them into **decoded**.

View File

@ -193,6 +193,11 @@ public:
return 0;
}
virtual const vector<int> &get_chunk_mapping() const {
static vector<int> mapping;
return mapping;
}
};
#endif