xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdEcReader.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Michal Simon <michal.simon@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef SRC_XRDEC_XRDECREADER_HH_
26 #define SRC_XRDEC_XRDECREADER_HH_
27 
28 #include "XrdEc/XrdEcObjCfg.hh"
29 
30 #include "XrdCl/XrdClZipArchive.hh"
31 #include "XrdCl/XrdClOperations.hh"
32 
33 #include <string>
34 #include <unordered_map>
35 #include <unordered_set>
36 
37 class MicroTest;
38 
39 namespace XrdEc
40 {
41  //---------------------------------------------------------------------------
42  // Forward declaration for the internal cache
43  //---------------------------------------------------------------------------
44  struct block_t;
45  //---------------------------------------------------------------------------
46  // Buffer for a single chunk of data
47  //---------------------------------------------------------------------------
48  typedef std::vector<char> buffer_t;
49  //---------------------------------------------------------------------------
50  // Read callback, to be called with status and number of bytes read
51  //---------------------------------------------------------------------------
52  typedef std::function<void( const XrdCl::XRootDStatus&, uint32_t )> callback_t;
53 
54  //---------------------------------------------------------------------------
55  // Reader object for reading erasure coded and striped data
56  //---------------------------------------------------------------------------
57  class Reader
58  {
59  friend class ::MicroTest;
60  friend struct block_t;
61 
62  public:
63  //-----------------------------------------------------------------------
68  //-----------------------------------------------------------------------
69  Reader( ObjCfg &objcfg ) : objcfg( objcfg ), lstblk( 0 ), filesize( 0 )
70  {
71  }
72 
73  //-----------------------------------------------------------------------
74  // Destructor
75  //-----------------------------------------------------------------------
76  virtual ~Reader();
77 
78  //-----------------------------------------------------------------------
82  //-----------------------------------------------------------------------
83  void Open( XrdCl::ResponseHandler *handler, uint16_t timeout = 0 );
84 
85  //-----------------------------------------------------------------------
92  //-----------------------------------------------------------------------
93  void Read( uint64_t offset,
94  uint32_t length,
95  void *buffer,
96  XrdCl::ResponseHandler *handler,
97  uint16_t timeout );
98 
99  //-----------------------------------------------------------------------
101  //-----------------------------------------------------------------------
102  void Close( XrdCl::ResponseHandler *handler, uint16_t timeout = 0 );
103 
104  //-----------------------------------------------------------------------
106  //-----------------------------------------------------------------------
107  inline uint64_t GetSize()
108  {
109  return filesize;
110  }
111 
112  private:
113 
114  //-----------------------------------------------------------------------
122  //-----------------------------------------------------------------------
123  void Read( size_t blknb, size_t strpnb, buffer_t &buffer, callback_t cb, uint16_t timeout = 0 );
124 
125  //-----------------------------------------------------------------------
129  //-----------------------------------------------------------------------
130  XrdCl::Pipeline ReadMetadata( size_t index );
131 
132  //-----------------------------------------------------------------------
136  //-----------------------------------------------------------------------
137  XrdCl::Pipeline ReadSize( size_t index );
138 
139  //-----------------------------------------------------------------------
143  //-----------------------------------------------------------------------
144  bool ParseMetadata( XrdCl::ChunkInfo &ch );
145 
146  //-----------------------------------------------------------------------
150  //-----------------------------------------------------------------------
151  void AddMissing( const buffer_t &cdbuff );
152 
153  //-----------------------------------------------------------------------
155  //-----------------------------------------------------------------------
156  bool IsMissing( const std::string &fn );
157 
158  typedef std::unordered_map<std::string, std::shared_ptr<XrdCl::ZipArchive>> dataarchs_t;
159  typedef std::unordered_map<std::string, buffer_t> metadata_t;
160  typedef std::unordered_map<std::string, std::string> urlmap_t;
161  typedef std::unordered_set<std::string> missing_t;
162 
164  dataarchs_t dataarchs; //> map URL to ZipArchive object
165  metadata_t metadata; //> map URL to CD metadata
166  urlmap_t urlmap; //> map blknb/strpnb (data chunk) to URL
167  missing_t missing; //> set of missing stripes
168  std::shared_ptr<block_t> block; //> cache for the block we are reading from
169  std::mutex blkmtx; //> mutex guarding the block from parallel access
170  size_t lstblk; //> last block number
171  uint64_t filesize; //> file size (obtained from xattr)
172  };
173 
174 } /* namespace XrdEc */
175 
176 #endif /* SRC_XRDEC_XRDECREADER_HH_ */
std::shared_ptr< block_t > block
Definition: XrdEcReader.hh:168
bool IsMissing(const std::string &fn)
Check if chunk file name is missing.
ObjCfg & objcfg
Definition: XrdEcReader.hh:163
metadata_t metadata
Definition: XrdEcReader.hh:165
urlmap_t urlmap
Definition: XrdEcReader.hh:166
std::mutex blkmtx
Definition: XrdEcReader.hh:169
std::unordered_map< std::string, std::string > urlmap_t
Definition: XrdEcReader.hh:160
uint64_t filesize
Definition: XrdEcReader.hh:171
XrdCl::Pipeline ReadSize(size_t index)
void Read(uint64_t offset, uint32_t length, void *buffer, XrdCl::ResponseHandler *handler, uint16_t timeout)
std::unordered_map< std::string, buffer_t > metadata_t
Definition: XrdEcReader.hh:159
Describe a data chunk for vector read.
Definition: XrdClXRootDResponses.hh:907
void Close(XrdCl::ResponseHandler *handler, uint16_t timeout=0)
Close the data object.
XrdCl::Pipeline ReadMetadata(size_t index)
bool ParseMetadata(XrdCl::ChunkInfo &ch)
friend struct block_t
Definition: XrdEcReader.hh:60
std::vector< char > buffer_t
a buffer type
Definition: XrdEcReader.hh:44
uint64_t GetSize()
Definition: XrdEcReader.hh:107
size_t lstblk
Definition: XrdEcReader.hh:170
Handle an async response.
Definition: XrdClXRootDResponses.hh:1116
std::unordered_set< std::string > missing_t
Definition: XrdEcReader.hh:161
missing_t missing
Definition: XrdEcReader.hh:167
Definition: XrdEcReader.hh:57
void AddMissing(const buffer_t &cdbuff)
std::function< void(const XrdCl::XRootDStatus &, uint32_t)> callback_t
Definition: XrdEcReader.hh:52
dataarchs_t dataarchs
Definition: XrdEcReader.hh:164
Definition: XrdEcObjCfg.hh:33
void Open(XrdCl::ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClOperations.hh:319
Reader(ObjCfg &objcfg)
Definition: XrdEcReader.hh:69
virtual ~Reader()
std::unordered_map< std::string, std::shared_ptr< XrdCl::ZipArchive > > dataarchs_t
Definition: XrdEcReader.hh:158