00001 #ifndef XRDCPXTREMEREAD_HH 00002 #define XRDCPXTREMEREAD_HH 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d c p X t r e m e R e a d . h h */ 00006 /* */ 00007 /* Author: Fabrizio Furano (CERN, 2009) */ 00008 /* */ 00009 /* This file is part of the XRootD software suite. */ 00010 /* */ 00011 /* XRootD is free software: you can redistribute it and/or modify it under */ 00012 /* the terms of the GNU Lesser General Public License as published by the */ 00013 /* Free Software Foundation, either version 3 of the License, or (at your */ 00014 /* option) any later version. */ 00015 /* */ 00016 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00017 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00018 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00019 /* License for more details. */ 00020 /* */ 00021 /* You should have received a copy of the GNU Lesser General Public License */ 00022 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00023 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00024 /* */ 00025 /* The copyright holder's institutional names and contributor's names may not */ 00026 /* be used to endorse or promote products derived from this software without */ 00027 /* specific prior written permission of the institution or contributor. */ 00028 /******************************************************************************/ 00029 00031 // // 00032 // Utility classes handling Extreme readers, i.e. coordinated parallel // 00033 // reads from multiple XrdClient instances // 00034 // // 00036 00037 #include "XrdSys/XrdSysPthread.hh" 00038 #include "XrdClient/XrdClient.hh" 00039 #include "XrdClient/XrdClientVector.hh" 00040 00041 class XrdXtRdBlkInfo { 00042 public: 00043 long long offs; 00044 int len; 00045 time_t lastrequested; 00046 00047 // Nothing more to do, block acquired 00048 bool done; 00049 00050 // The seq of the clientidxs which requested this blk 00051 XrdClientVector<int> requests; 00052 00053 bool AlreadyRequested(int clientIdx) { 00054 for (int i = 0; i < requests.GetSize(); i++) 00055 if (requests[i] == clientIdx) return true; 00056 return false; 00057 } 00058 00059 XrdXtRdBlkInfo() {offs = 0; len = 0; done = false; requests.Clear(); lastrequested = 0; } 00060 }; 00061 00062 class XrdXtRdFile { 00063 private: 00064 int clientidxcnt; // counter to assign client idxs 00065 XrdSysRecMutex mtx; // mutex to protect data structures 00066 00067 int freeblks; // Blocks not yet assigned to readers 00068 int nblks; // Total number of blocks 00069 int doneblks; // Xferred blocks 00070 00071 XrdXtRdBlkInfo *blocks; 00072 00073 public: 00074 00075 // Models a file as a sequence of blocks, which can be attrbuted to 00076 // different readers 00077 XrdXtRdFile(int blksize, long long filesize); 00078 ~XrdXtRdFile(); 00079 00080 bool AllDone() { XrdSysMutexHelper m(mtx); return (doneblks >= nblks); } 00081 00082 // Gives a unique ID which can identify a reader client in the game 00083 int GimmeANewClientIdx(); 00084 00085 int GetNBlks() { return nblks; } 00086 00087 // Finds a block to prefetch and then read 00088 // Atomically associates it to a client idx 00089 // Returns the blk index 00090 int GetBlkToPrefetch(int fromidx, int clientIdx, XrdXtRdBlkInfo *&blkreadonly); 00091 int GetBlkToRead(int fromidx, int clientidx, XrdXtRdBlkInfo *&blkreadonly); 00092 00093 void MarkBlkAsRequested(int blkidx); 00094 int MarkBlkAsRead(int blkidx); 00095 00096 static int GetListOfSources(XrdClient *ref, XrdOucString xtrememgr, 00097 XrdClientVector<XrdClient *> &clients, 00098 int maxSources=12); 00099 00100 00101 }; 00102 #endif