xrootd
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  //-----------------------------------------------------------------------
70  {
71  }
72 
73  //-----------------------------------------------------------------------
74  // Destructor
75  //-----------------------------------------------------------------------
76  virtual ~Reader();
77 
78  //-----------------------------------------------------------------------
82  //-----------------------------------------------------------------------
83  void Open( XrdCl::ResponseHandler *handler );
84 
85  //-----------------------------------------------------------------------
92  //-----------------------------------------------------------------------
93  void Read( uint64_t offset,
94  uint32_t length,
95  void *buffer,
96  XrdCl::ResponseHandler *handler );
97 
98  //-----------------------------------------------------------------------
100  //-----------------------------------------------------------------------
101  void Close( XrdCl::ResponseHandler *handler );
102 
103  private:
104 
105  //-----------------------------------------------------------------------
112  //-----------------------------------------------------------------------
113  void Read( size_t blknb, size_t strpnb, buffer_t &buffer, callback_t cb );
114 
115  //-----------------------------------------------------------------------
119  //-----------------------------------------------------------------------
120  XrdCl::Pipeline ReadMetadata( size_t index );
121 
122  //-----------------------------------------------------------------------
126  //-----------------------------------------------------------------------
127  bool ParseMetadata( XrdCl::ChunkInfo &ch );
128 
129  //-----------------------------------------------------------------------
133  //-----------------------------------------------------------------------
134  void AddMissing( const buffer_t &cdbuff );
135 
136  typedef std::unordered_map<std::string, std::shared_ptr<XrdCl::ZipArchive>> dataarchs_t;
137  typedef std::unordered_map<std::string, buffer_t> metadata_t;
138  typedef std::unordered_map<std::string, std::string> urlmap_t;
139  typedef std::unordered_set<std::string> missing_t;
140 
142  dataarchs_t dataarchs; //> map URL to ZipArchive object
143  metadata_t metadata; //> map URL to CD metadata
144  urlmap_t urlmap; //> map blknb/strpnb (data chunk) to URL
145  missing_t missing; //> set of missing stripes
146  std::shared_ptr<block_t> block; //> cache for the block we are reading from
147  };
148 
149 } /* namespace XrdEc */
150 
151 #endif /* SRC_XRDEC_XRDECREADER_HH_ */
std::shared_ptr< block_t > block
Definition: XrdEcReader.hh:146
ObjCfg & objcfg
Definition: XrdEcReader.hh:141
metadata_t metadata
Definition: XrdEcReader.hh:143
urlmap_t urlmap
Definition: XrdEcReader.hh:144
void Open(XrdCl::ResponseHandler *handler)
std::unordered_map< std::string, std::string > urlmap_t
Definition: XrdEcReader.hh:138
std::unordered_map< std::string, buffer_t > metadata_t
Definition: XrdEcReader.hh:137
Describe a data chunk for vector read.
Definition: XrdClXRootDResponses.hh:907
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
Handle an async response.
Definition: XrdClXRootDResponses.hh:1040
std::unordered_set< std::string > missing_t
Definition: XrdEcReader.hh:139
missing_t missing
Definition: XrdEcReader.hh:145
Definition: XrdEcReader.hh:57
void Read(uint64_t offset, uint32_t length, void *buffer, XrdCl::ResponseHandler *handler)
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:142
Definition: XrdEcObjCfg.hh:19
Definition: XrdClOperations.hh:319
void Close(XrdCl::ResponseHandler *handler)
Close the data object.
Reader(ObjCfg &objcfg)
Definition: XrdEcReader.hh:69
virtual ~Reader()
std::unordered_map< std::string, std::shared_ptr< XrdCl::ZipArchive > > dataarchs_t
Definition: XrdEcReader.hh:136
Definition: XrdClZipArchive.hh:45