XrdFileCache.hh

Go to the documentation of this file.
00001 #ifndef __XRDFILECACHE_CACHE_HH__
00002 #define __XRDFILECACHE_CACHE_HH__
00003 //----------------------------------------------------------------------------------
00004 // Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
00005 // Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
00006 //----------------------------------------------------------------------------------
00007 // XRootD is free software: you can redistribute it and/or modify
00008 // it under the terms of the GNU Lesser General Public License as published by
00009 // the Free Software Foundation, either version 3 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // XRootD is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public License
00018 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00019 //----------------------------------------------------------------------------------
00020 #include <string>
00021 #include <list>
00022 
00023 #include "XrdSys/XrdSysPthread.hh"
00024 #include "XrdOuc/XrdOucCache.hh"
00025 #include "XrdCl/XrdClDefaultEnv.hh"
00026 
00027 namespace XrdCl {
00028    class Log;
00029 }
00030 namespace XrdFileCache {
00031 class Prefetch;
00032 }
00033 
00034 namespace XrdFileCache
00035 {
00036    //----------------------------------------------------------------------------
00038    //----------------------------------------------------------------------------
00039    class Cache : public XrdOucCache
00040    {
00041       friend class IOEntireFile;
00042       friend class IOFileBlock;
00043 
00044       public:
00045          //---------------------------------------------------------------------
00047          //---------------------------------------------------------------------
00048          Cache(XrdOucCacheStats&);
00049 
00050          //---------------------------------------------------------------------
00052          //---------------------------------------------------------------------
00053          virtual XrdOucCacheIO *Attach(XrdOucCacheIO *, int Options=0);
00054 
00055          //---------------------------------------------------------------------
00057          //---------------------------------------------------------------------
00058          virtual int isAttached();
00059 
00060          //---------------------------------------------------------------------
00063          //---------------------------------------------------------------------
00064          virtual XrdOucCache* Create(XrdOucCache::Parms&, XrdOucCacheIO::aprParms*)
00065          { return NULL; }
00066 
00067          //---------------------------------------------------------------------
00069          //---------------------------------------------------------------------
00070          static void AddWriteTask(Prefetch* p, int ramBlockidx, size_t size, bool fromRead);
00071 
00072          //---------------------------------------------------------------------
00074          //---------------------------------------------------------------------
00075          static bool HaveFreeWritingSlots();
00076 
00077          //---------------------------------------------------------------------
00080          //---------------------------------------------------------------------
00081          static void RemoveWriteQEntriesFor(Prefetch *p);
00082 
00083          //---------------------------------------------------------------------
00085          //---------------------------------------------------------------------
00086          static void ProcessWriteTasks();
00087 
00088       private:
00090          void Detach(XrdOucCacheIO *);
00091 
00093          bool getFilePathFromURL(const char* url, std::string& res) const;
00094 
00096          XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
00097 
00098          XrdSysMutex        m_io_mutex; 
00099          unsigned int       m_attached; 
00100          XrdOucCacheStats  &m_stats;    
00101 
00102          struct WriteTask
00103          {
00104             Prefetch* prefetch;    
00105             int       ramBlockIdx; 
00106             size_t    size;        
00107             WriteTask(Prefetch* p, int ri, size_t s):prefetch(p), ramBlockIdx(ri), size(s){}
00108          };
00109 
00110          struct WriteQ
00111          {
00112             WriteQ() : condVar(0), size(0) {}
00113             XrdSysCondVar         condVar;  
00114             size_t                size;     
00115             std::list<WriteTask>  queue;    
00116          };
00117 
00118          static WriteQ s_writeQ;
00119 
00120    };
00121 
00122    //----------------------------------------------------------------------------
00124    //----------------------------------------------------------------------------
00125    class IO : public XrdOucCacheIO
00126    {
00127       friend class Prefetch;
00128 
00129       public:
00130          IO (XrdOucCacheIO &io, XrdOucCacheStats &stats, Cache &cache) :
00131          m_io(io), m_statsGlobal(stats), m_cache(cache) {}
00132 
00134          virtual XrdOucCacheIO *Base() { return &m_io; }
00135 
00137          virtual long long FSize() { return m_io.FSize(); }
00138 
00140          virtual const char *Path() { return m_io.Path(); }
00141 
00142          virtual int Sync() { return 0; }
00143 
00144          virtual int Trunc(long long Offset) { errno = ENOTSUP; return -1; }
00145 
00146          virtual int Write(char *Buffer, long long Offset, int Length)
00147          { errno = ENOTSUP; return -1; }
00148 
00149          virtual void StartPrefetch() {}
00150 
00151       protected:
00152          XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
00153 
00154          XrdOucCacheIO    &m_io;          
00155          XrdOucCacheStats &m_statsGlobal; 
00156          Cache            &m_cache;       
00157    };
00158 }
00159 
00160 #endif

Generated on 12 Dec 2014 for xrootd by  doxygen 1.4.7