xrootd
XrdcpXtremeRead.hh
Go to the documentation of this file.
1 #ifndef XRDCPXTREMEREAD_HH
2 #define XRDCPXTREMEREAD_HH
3 /******************************************************************************/
4 /* */
5 /* X r d c p X t r e m e R e a d . h h */
6 /* */
7 /* Author: Fabrizio Furano (CERN, 2009) */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
31 // //
32 // Utility classes handling Extreme readers, i.e. coordinated parallel //
33 // reads from multiple XrdClient instances //
34 // //
36 
37 #include "XrdSys/XrdSysPthread.hh"
38 #include "XrdClient/XrdClient.hh"
40 
42 public:
43  long long offs;
44  int len;
45  time_t lastrequested;
46 
47  // Nothing more to do, block acquired
48  bool done;
49 
50  // The seq of the clientidxs which requested this blk
52 
53  bool AlreadyRequested(int clientIdx) {
54  for (int i = 0; i < requests.GetSize(); i++)
55  if (requests[i] == clientIdx) return true;
56  return false;
57  }
58 
59  XrdXtRdBlkInfo() {offs = 0; len = 0; done = false; requests.Clear(); lastrequested = 0; }
60 };
61 
62 class XrdXtRdFile {
63 private:
64  int clientidxcnt; // counter to assign client idxs
65  XrdSysRecMutex mtx; // mutex to protect data structures
66 
67  int freeblks; // Blocks not yet assigned to readers
68  int nblks; // Total number of blocks
69  int doneblks; // Xferred blocks
70 
72 
73 public:
74 
75  // Models a file as a sequence of blocks, which can be attrbuted to
76  // different readers
77  XrdXtRdFile(int blksize, long long filesize);
78  ~XrdXtRdFile();
79 
80  bool AllDone() { XrdSysMutexHelper m(mtx); return (doneblks >= nblks); }
81 
82  // Gives a unique ID which can identify a reader client in the game
83  int GimmeANewClientIdx();
84 
85  int GetNBlks() { return nblks; }
86 
87  // Finds a block to prefetch and then read
88  // Atomically associates it to a client idx
89  // Returns the blk index
90  int GetBlkToPrefetch(int fromidx, int clientIdx, XrdXtRdBlkInfo *&blkreadonly);
91  int GetBlkToRead(int fromidx, int clientidx, XrdXtRdBlkInfo *&blkreadonly);
92 
93  void MarkBlkAsRequested(int blkidx);
94  int MarkBlkAsRead(int blkidx);
95 
96  static int GetListOfSources(XrdClient *ref, XrdOucString xtrememgr,
98  int maxSources=12);
99 
100 
101 };
102 #endif
XrdXtRdFile::blocks
XrdXtRdBlkInfo * blocks
Definition: XrdcpXtremeRead.hh:71
XrdClient
Definition: XrdClient.hh:121
XrdXtRdBlkInfo::lastrequested
time_t lastrequested
Definition: XrdcpXtremeRead.hh:45
XrdXtRdBlkInfo::offs
long long offs
Definition: XrdcpXtremeRead.hh:43
XrdSysPthread.hh
XrdXtRdFile::freeblks
int freeblks
Definition: XrdcpXtremeRead.hh:67
XrdXtRdFile::GetBlkToRead
int GetBlkToRead(int fromidx, int clientidx, XrdXtRdBlkInfo *&blkreadonly)
XrdClientVector::GetSize
int GetSize() const
Definition: XrdClientVector.hh:142
XrdXtRdFile::clientidxcnt
int clientidxcnt
Definition: XrdcpXtremeRead.hh:64
XrdXtRdFile::doneblks
int doneblks
Definition: XrdcpXtremeRead.hh:69
XrdXtRdFile::MarkBlkAsRead
int MarkBlkAsRead(int blkidx)
XrdXtRdFile::mtx
XrdSysRecMutex mtx
Definition: XrdcpXtremeRead.hh:65
XrdXtRdBlkInfo
Definition: XrdcpXtremeRead.hh:41
XrdXtRdBlkInfo::AlreadyRequested
bool AlreadyRequested(int clientIdx)
Definition: XrdcpXtremeRead.hh:53
XrdXtRdBlkInfo::XrdXtRdBlkInfo
XrdXtRdBlkInfo()
Definition: XrdcpXtremeRead.hh:59
XrdClientVector::Clear
void Clear()
Definition: XrdClientVector.hh:144
XrdXtRdFile::AllDone
bool AllDone()
Definition: XrdcpXtremeRead.hh:80
XrdXtRdBlkInfo::len
int len
Definition: XrdcpXtremeRead.hh:44
XrdXtRdFile::~XrdXtRdFile
~XrdXtRdFile()
XrdClientVector< int >
XrdXtRdFile
Definition: XrdcpXtremeRead.hh:62
XrdXtRdBlkInfo::requests
XrdClientVector< int > requests
Definition: XrdcpXtremeRead.hh:51
XrdSysRecMutex
Definition: XrdSysPthread.hh:239
XrdXtRdFile::GetNBlks
int GetNBlks()
Definition: XrdcpXtremeRead.hh:85
XrdXtRdFile::XrdXtRdFile
XrdXtRdFile(int blksize, long long filesize)
XrdClient.hh
XrdXtRdFile::GetListOfSources
static int GetListOfSources(XrdClient *ref, XrdOucString xtrememgr, XrdClientVector< XrdClient * > &clients, int maxSources=12)
XrdXtRdFile::GimmeANewClientIdx
int GimmeANewClientIdx()
XrdXtRdFile::nblks
int nblks
Definition: XrdcpXtremeRead.hh:68
XrdXtRdFile::MarkBlkAsRequested
void MarkBlkAsRequested(int blkidx)
XrdClientVector.hh
XrdSysMutexHelper
Definition: XrdSysPthread.hh:260
XrdXtRdBlkInfo::done
bool done
Definition: XrdcpXtremeRead.hh:48
XrdOucString
Definition: XrdOucString.hh:254
XrdXtRdFile::GetBlkToPrefetch
int GetBlkToPrefetch(int fromidx, int clientIdx, XrdXtRdBlkInfo *&blkreadonly)