xrootd
XrdcpXtremeRead.hh
Go to the documentation of this file.
00001 
00002 //                                                                      //
00003 // XrdXtremeRead                                                        //
00004 //                                                                      //
00005 // Author: Fabrizio Furano (CERN, 2009)                                 //
00006 //                                                                      //
00007 // Utility classes handling Extreme readers, i.e. coordinated parallel  //
00008 //  reads from multiple XrdClient instances                             //
00009 //                                                                      //
00011 
00012 #include "XrdSys/XrdSysPthread.hh"
00013 #include "XrdClient/XrdClient.hh"
00014 #include "XrdClient/XrdClientVector.hh"
00015 
00016 class XrdXtRdBlkInfo {
00017 public:
00018    long long offs;
00019    int len;
00020    time_t lastrequested;
00021 
00022    // Nothing more to do, block acquired
00023    bool done;
00024 
00025    // The seq of the clientidxs which requested this blk
00026    XrdClientVector<int> requests;
00027 
00028    bool AlreadyRequested(int clientIdx) {
00029       for (int i = 0; i < requests.GetSize(); i++)
00030          if (requests[i] == clientIdx) return true;
00031       return false;
00032    }
00033 
00034    XrdXtRdBlkInfo() {offs = 0; len = 0; done = false; requests.Clear(); lastrequested = 0; }
00035 };
00036 
00037 class XrdXtRdFile {
00038 private:
00039    int clientidxcnt;         // counter to assign client idxs
00040    XrdSysRecMutex mtx;       // mutex to protect data structures
00041 
00042    int freeblks;    // Blocks not yet assigned to readers
00043    int nblks;       // Total number of blocks
00044    int doneblks;    // Xferred blocks
00045 
00046    XrdXtRdBlkInfo *blocks;
00047 
00048 public:
00049 
00050    // Models a file as a sequence of blocks, which can be attrbuted to
00051    //  different readers
00052    XrdXtRdFile(int blksize, long long filesize);
00053    ~XrdXtRdFile();
00054 
00055    bool AllDone() { XrdSysMutexHelper m(mtx); return (doneblks >= nblks); }
00056 
00057    // Gives a unique ID which can identify a reader client in the game
00058    int GimmeANewClientIdx();
00059 
00060    int GetNBlks() { return nblks; }
00061 
00062    // Finds a block to prefetch and then read
00063    // Atomically associates it to a client idx
00064    // Returns the blk index
00065    int GetBlkToPrefetch(int fromidx, int clientIdx, XrdXtRdBlkInfo *&blkreadonly);
00066    int GetBlkToRead(int fromidx, int clientidx, XrdXtRdBlkInfo *&blkreadonly);
00067 
00068    void MarkBlkAsRequested(int blkidx);
00069    int MarkBlkAsRead(int blkidx);
00070 
00071    static int GetListOfSources(XrdClient *ref, XrdOucString xtrememgr,
00072                                XrdClientVector<XrdClient *> &clients,
00073                                int maxSources=12);
00074 
00075 
00076 };