|
||||
File indexing completed on 2025-01-18 10:15:37
0001 //------------------------------------------------------------------------------ 0002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 0003 // Author: Michal Simon <michal.simon@cern.ch> 0004 //------------------------------------------------------------------------------ 0005 // This file is part of the XRootD software suite. 0006 // 0007 // XRootD is free software: you can redistribute it and/or modify 0008 // it under the terms of the GNU Lesser General Public License as published by 0009 // the Free Software Foundation, either version 3 of the License, or 0010 // (at your option) any later version. 0011 // 0012 // XRootD is distributed in the hope that it will be useful, 0013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 // GNU General Public License for more details. 0016 // 0017 // You should have received a copy of the GNU Lesser General Public License 0018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 0019 // 0020 // In applying this licence, CERN does not waive the privileges and immunities 0021 // granted to it by virtue of its status as an Intergovernmental Organization 0022 // or submit itself to any jurisdiction. 0023 //------------------------------------------------------------------------------ 0024 0025 #ifndef SRC_XRDEC_XRDECREADER_HH_ 0026 #define SRC_XRDEC_XRDECREADER_HH_ 0027 0028 #include "XrdEc/XrdEcObjCfg.hh" 0029 0030 #include "XrdCl/XrdClZipArchive.hh" 0031 #include "XrdCl/XrdClOperations.hh" 0032 0033 #include <string> 0034 #include <unordered_map> 0035 #include <unordered_set> 0036 0037 class MicroTest; 0038 class XrdEcTests; 0039 0040 namespace XrdEc 0041 { 0042 //--------------------------------------------------------------------------- 0043 // Forward declaration for the internal cache 0044 //--------------------------------------------------------------------------- 0045 struct block_t; 0046 //--------------------------------------------------------------------------- 0047 // Buffer for a single chunk of data 0048 //--------------------------------------------------------------------------- 0049 typedef std::vector<char> buffer_t; 0050 //--------------------------------------------------------------------------- 0051 // Read callback, to be called with status and number of bytes read 0052 //--------------------------------------------------------------------------- 0053 typedef std::function<void( const XrdCl::XRootDStatus&, uint32_t )> callback_t; 0054 0055 //--------------------------------------------------------------------------- 0056 // Reader object for reading erasure coded and striped data 0057 //--------------------------------------------------------------------------- 0058 class Reader 0059 { 0060 friend class ::MicroTest; 0061 friend class ::XrdEcTests; 0062 friend struct block_t; 0063 0064 public: 0065 //----------------------------------------------------------------------- 0066 //! Constructor 0067 //! 0068 //! @param objcfg : configuration for the data object (e.g. number of 0069 //! data and parity stripes) 0070 //----------------------------------------------------------------------- 0071 Reader( ObjCfg &objcfg ) : objcfg( objcfg ), lstblk( 0 ), filesize( 0 ) 0072 { 0073 } 0074 0075 //----------------------------------------------------------------------- 0076 // Destructor 0077 //----------------------------------------------------------------------- 0078 virtual ~Reader(); 0079 0080 //----------------------------------------------------------------------- 0081 //! Open the erasure coded / striped object 0082 //! 0083 //! @param handler : user callback 0084 //----------------------------------------------------------------------- 0085 void Open( XrdCl::ResponseHandler *handler, uint16_t timeout = 0 ); 0086 0087 //----------------------------------------------------------------------- 0088 //! Read data from the data object 0089 //! 0090 //! @param offset : offset of the data to be read 0091 //! @param length : length of the data to be read 0092 //! @param buffer : buffer for the data to be read 0093 //! @param handler : user callback 0094 //----------------------------------------------------------------------- 0095 void Read( uint64_t offset, 0096 uint32_t length, 0097 void *buffer, 0098 XrdCl::ResponseHandler *handler, 0099 uint16_t timeout ); 0100 0101 /* 0102 * Read multiple locations and lengths of data 0103 * internally remapped to stripes 0104 * 0105 * @param chunks : list of offsets, lengths and separate buffers 0106 * @param buffer : optional full buffer for all data 0107 */ 0108 void VectorRead( const XrdCl::ChunkList &chunks, 0109 void *buffer, 0110 XrdCl::ResponseHandler *handler, 0111 uint16_t timeout); 0112 0113 //----------------------------------------------------------------------- 0114 //! Close the data object 0115 //----------------------------------------------------------------------- 0116 void Close( XrdCl::ResponseHandler *handler, uint16_t timeout = 0 ); 0117 0118 //----------------------------------------------------------------------- 0119 //! @return : get file size 0120 //----------------------------------------------------------------------- 0121 inline uint64_t GetSize() 0122 { 0123 return filesize; 0124 } 0125 0126 private: 0127 0128 //----------------------------------------------------------------------- 0129 //! Read data from given stripes from given block 0130 //! 0131 //! @param blknb : number of the block 0132 //! @param strpnb : number of stripe in the block 0133 //! @param buffer : buffer for the data 0134 //! @param cb : callback 0135 //! @param timeout : operation timeout 0136 //----------------------------------------------------------------------- 0137 void Read( size_t blknb, size_t strpnb, buffer_t &buffer, callback_t cb, uint16_t timeout = 0 ); 0138 0139 //----------------------------------------------------------------------- 0140 //! Read metadata for the object 0141 //! 0142 //! @param index : placement's index 0143 //----------------------------------------------------------------------- 0144 XrdCl::Pipeline ReadMetadata( size_t index ); 0145 0146 //----------------------------------------------------------------------- 0147 //! Read size from xattr 0148 //! 0149 //! @param index : placement's index 0150 //----------------------------------------------------------------------- 0151 XrdCl::Pipeline ReadSize( size_t index ); 0152 0153 //----------------------------------------------------------------------- 0154 //! Parse metadata from chunk info object 0155 //! 0156 //! @param ch : chunk info object returned by a read operation 0157 //----------------------------------------------------------------------- 0158 bool ParseMetadata( XrdCl::ChunkInfo &ch ); 0159 0160 //----------------------------------------------------------------------- 0161 //! Add all the entries from given Central Directory to missing 0162 //! 0163 //! @param cdbuff : buffer containing central directory 0164 //----------------------------------------------------------------------- 0165 void AddMissing( const buffer_t &cdbuff ); 0166 0167 //----------------------------------------------------------------------- 0168 //! Check if chunk file name is missing 0169 //----------------------------------------------------------------------- 0170 bool IsMissing( const std::string &fn ); 0171 0172 inline static callback_t ErrorCorrected(Reader *reader, std::shared_ptr<block_t> &self, size_t blkid, size_t strpid); 0173 0174 void MissingVectorRead(std::shared_ptr<block_t> &block, size_t blkid, size_t strpid, uint16_t timeout = 0); 0175 0176 typedef std::unordered_map<std::string, std::shared_ptr<XrdCl::ZipArchive>> dataarchs_t; 0177 typedef std::unordered_map<std::string, buffer_t> metadata_t; 0178 typedef std::unordered_map<std::string, std::string> urlmap_t; 0179 typedef std::unordered_set<std::string> missing_t; 0180 0181 ObjCfg &objcfg; 0182 dataarchs_t dataarchs; //> map URL to ZipArchive object 0183 metadata_t metadata; //> map URL to CD metadata 0184 urlmap_t urlmap; //> map blknb/strpnb (data chunk) to URL 0185 missing_t missing; //> set of missing stripes 0186 std::shared_ptr<block_t> block; //> cache for the block we are reading from 0187 std::mutex blkmtx; //> mutex guarding the block from parallel access 0188 size_t lstblk; //> last block number 0189 uint64_t filesize; //> file size (obtained from xattr) 0190 std::map<std::string, size_t> archiveIndices; 0191 0192 std::mutex missingChunksMutex; 0193 std::vector<std::tuple<size_t, size_t>> missingChunksVectorRead; 0194 std::condition_variable waitMissing; 0195 }; 0196 0197 } /* namespace XrdEc */ 0198 0199 #endif /* SRC_XRDEC_XRDECREADER_HH_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |