Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:37

0001 //------------------------------------------------------------------------------
0002 //! @file XrdEcRedundancyProvider.hh
0003 //! @author Paul Hermann Lensing
0004 //! @brief Class for computing parities and recovering data
0005 //------------------------------------------------------------------------------
0006 
0007 /************************************************************************
0008  * KineticIo - a file io interface library to kinetic devices.          *
0009  *                                                                      *
0010  * This Source Code Form is subject to the terms of the Mozilla         *
0011  * Public License, v. 2.0. If a copy of the MPL was not                 *
0012  * distributed with this file, You can obtain one at                    *
0013  * https://mozilla.org/MP:/2.0/.                                        *
0014  *                                                                      *
0015  * This program is distributed in the hope that it will be useful,      *
0016  * but is provided AS-IS, WITHOUT ANY WARRANTY; including without       *
0017  * the implied warranty of MERCHANTABILITY, NON-INFRINGEMENT or         *
0018  * FITNESS FOR A PARTICULAR PURPOSE. See the Mozilla Public             *
0019  * License for more details.                                            *
0020  ************************************************************************/
0021 
0022 #ifndef KINETICIO_REDUNDANCYPROVIDER_HH
0023 #define KINETICIO_REDUNDANCYPROVIDER_HH
0024 
0025 #include "XrdEc/XrdEcObjCfg.hh"
0026 #include "XrdEc/XrdEcUtilities.hh"
0027 
0028 #include <memory>
0029 #include <vector>
0030 #include <string>
0031 #include <unordered_map>
0032 #include <mutex>
0033 
0034 namespace XrdEc
0035 {
0036   //------------------------------------------------------------------------------
0037   //! The redundancy provider class offers automatic parity computing and data
0038   //! recovery. Depending on configuration it will use erasure coding or
0039   //! replication.
0040   //------------------------------------------------------------------------------
0041   class RedundancyProvider {
0042   public:
0043     //--------------------------------------------------------------------------
0044     //! Compute all missing data and parity blocks in the the stripe. Stripe size
0045     //! has to equal nData+nParity. Blocks can be arbitrary size, but size has
0046     //! to be equal within a stripe. Function will throw on incorrect input.
0047     //!
0048     //! @param stripes nData+nParity blocks, missing (empty) blocks will be
0049     //!   computed if possible.
0050     //--------------------------------------------------------------------------
0051     void compute( stripes_t &stripes );
0052 
0053     //--------------------------------------------------------------------------
0054     //! Constructor.
0055     //! Stripe parameters (number of data and parity blocks) are constant per
0056     //! ErasureEncoding object.
0057     //--------------------------------------------------------------------------
0058     RedundancyProvider( const ObjCfg &objcfg );
0059 
0060   private:
0061     //--------------------------------------------------------------------------
0062     //! Data structure to store all information required for a decode process with
0063     //! a known error pattern.
0064     //--------------------------------------------------------------------------
0065     struct CodingTable {
0066       //! the coding table
0067       std::vector<unsigned char> table;
0068       //! array of nData size, containing stripe indices to input blocks
0069       std::vector<unsigned int> blockIndices;
0070       //! Number of errors this coding table is constructed for (maximum==nParity)
0071       int nErrors;
0072     };
0073 
0074     //--------------------------------------------------------------------------
0075     //! Constructs a string of the error pattern / signature. Each missing block
0076     //! in the stripe is counted as an error block, existing blocks are assumed
0077     //! to be correct (crc integrity checks of blocks should be done previously
0078     //! to attempting erasure decoding).
0079     //!
0080     //! @param stripes vector of nData+nParity blocks, missing (empty) blocks
0081     //!        are errors
0082     //! @return a string of stripe size describing the error pattern
0083     //--------------------------------------------------------------------------
0084     std::string getErrorPattern( stripes_t &stripes ) const;
0085 
0086     //--------------------------------------------------------------------------
0087     //! Returns a reference to the coding table for the requested error pattern,
0088     //! if possible from the cache. If that particular table has not been
0089     //! requested before, it will be constructed.
0090     //!
0091     //! @param pattern error pattern / signature
0092     //! @return reference to the coding table for the supplied error pattern
0093     //--------------------------------------------------------------------------
0094     CodingTable& getCodingTable(
0095         const std::string& pattern
0096     );
0097 
0098   private:
0099 
0100     void replication( stripes_t &stripes );
0101 
0102     ObjCfg objcfg;
0103 
0104     //! the encoding matrix, required to compute any decode matrix
0105     std::vector<unsigned char> encode_matrix;
0106     //! a cache of previously used coding tables
0107     std::unordered_map<std::string, CodingTable> cache;
0108     //! concurrency control
0109     std::mutex mutex;
0110   };
0111 
0112 };
0113 
0114 #endif  /* ERASURECODING_HH */