2 * Ceph - scalable distributed file system
4 * Copyright (C) 2014 CERN (Switzerland)
6 * Author: Andreas-Joachim Peters <Andreas.Joachim.Peters@cern.ch>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
16 * @file ErasureCodeIsa.cc
18 * @brief Erasure Code CODEC using the INTEL ISA-L library.
20 * The INTEL ISA-L library supports two pre-defined encoding matrices (cauchy = default, reed_sol_van = default)
21 * The default CODEC implementation using these two matrices is implemented in class ErasureCodeIsaDefault.
22 * ISA-L allows to use custom matrices which might be added later as implementations deriving from the base class ErasoreCodeIsa.
25 #ifndef CEPH_ERASURE_CODE_ISA_L_H
26 #define CEPH_ERASURE_CODE_ISA_L_H
28 // -----------------------------------------------------------------------------
29 #include "erasure-code/ErasureCode.h"
30 #include "ErasureCodeIsaTableCache.h"
31 // -----------------------------------------------------------------------------
33 #define DEFAULT_RULESET_ROOT "default"
34 #define DEFAULT_RULESET_FAILURE_DOMAIN "host"
36 class ErasureCodeIsa
: public ErasureCode
{
40 kVandermonde
= 0, kCauchy
= 1
47 ErasureCodeIsaTableCache
&tcache
;
48 const char *technique
;
49 std::string ruleset_root
;
50 std::string ruleset_failure_domain
;
52 ErasureCodeIsa(const char *_technique
,
53 ErasureCodeIsaTableCache
&_tcache
) :
58 technique(_technique
),
59 ruleset_root(DEFAULT_RULESET_ROOT
),
60 ruleset_failure_domain(DEFAULT_RULESET_FAILURE_DOMAIN
)
65 ~ErasureCodeIsa() override
69 int create_ruleset(const std::string
&name
,
71 std::ostream
*ss
) const override
;
74 get_chunk_count() const override
80 get_data_chunk_count() const override
85 unsigned int get_chunk_size(unsigned int object_size
) const override
;
87 int encode_chunks(const std::set
<int> &want_to_encode
,
88 std::map
<int, bufferlist
> *encoded
) override
;
90 int decode_chunks(const std::set
<int> &want_to_read
,
91 const std::map
<int, bufferlist
> &chunks
,
92 std::map
<int, bufferlist
> *decoded
) override
;
94 int init(ErasureCodeProfile
&profile
, std::ostream
*ss
) override
;
96 virtual void isa_encode(char **data
,
101 virtual int isa_decode(int *erasures
,
106 virtual unsigned get_alignment() const = 0;
108 virtual void prepare() = 0;
111 virtual int parse(ErasureCodeProfile
&profile
,
112 std::ostream
*ss
) = 0;
115 // -----------------------------------------------------------------------------
117 class ErasureCodeIsaDefault
: public ErasureCodeIsa
{
123 static const std::string DEFAULT_K
;
124 static const std::string DEFAULT_M
;
126 unsigned char* encode_coeff
; // encoding coefficient
127 unsigned char* encode_tbls
; // encoding table
129 ErasureCodeIsaDefault(ErasureCodeIsaTableCache
&_tcache
,
130 int matrix
= kVandermonde
) :
132 ErasureCodeIsa("default", _tcache
),
133 encode_coeff(0), encode_tbls(0)
139 ~ErasureCodeIsaDefault() override
144 void isa_encode(char **data
,
146 int blocksize
) override
;
148 virtual bool erasure_contains(int *erasures
, int i
);
150 int isa_decode(int *erasures
,
153 int blocksize
) override
;
155 unsigned get_alignment() const override
;
157 void prepare() override
;
160 int parse(ErasureCodeProfile
&profile
,
161 std::ostream
*ss
) override
;