xrootd
XrdFileCache.hh
Go to the documentation of this file.
1 #ifndef __XRDFILECACHE_CACHE_HH__
2 #define __XRDFILECACHE_CACHE_HH__
3 //----------------------------------------------------------------------------------
4 // Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University
5 // Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman
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 #include <string>
21 #include <list>
22 
23 #include "XrdSys/XrdSysPthread.hh"
24 #include "XrdOuc/XrdOucCache.hh"
25 #include "XrdCl/XrdClDefaultEnv.hh"
26 
27 namespace XrdCl {
28  class Log;
29 }
30 namespace XrdFileCache {
31 class Prefetch;
32 }
33 
34 namespace XrdFileCache
35 {
36  //----------------------------------------------------------------------------
38  //----------------------------------------------------------------------------
39  class Cache : public XrdOucCache
40  {
41  friend class IOEntireFile;
42  friend class IOFileBlock;
43 
44  public:
45  //---------------------------------------------------------------------
47  //---------------------------------------------------------------------
49 
50  //---------------------------------------------------------------------
52  //---------------------------------------------------------------------
53  virtual XrdOucCacheIO *Attach(XrdOucCacheIO *, int Options=0);
54 
55  //---------------------------------------------------------------------
57  //---------------------------------------------------------------------
58  virtual int isAttached();
59 
60  //---------------------------------------------------------------------
63  //---------------------------------------------------------------------
65  { return NULL; }
66 
67  //---------------------------------------------------------------------
69  //---------------------------------------------------------------------
70  static void AddWriteTask(Prefetch* p, int ramBlockidx, size_t size, bool fromRead);
71 
72  //---------------------------------------------------------------------
74  //---------------------------------------------------------------------
75  static bool HaveFreeWritingSlots();
76 
77  //---------------------------------------------------------------------
80  //---------------------------------------------------------------------
81  static void RemoveWriteQEntriesFor(Prefetch *p);
82 
83  //---------------------------------------------------------------------
85  //---------------------------------------------------------------------
86  static void ProcessWriteTasks();
87 
88  private:
90  void Detach(XrdOucCacheIO *);
91 
93  void getFilePathFromURL(const char* url, std::string& res) const;
94 
96  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
97 
99  unsigned int m_attached;
101 
102  struct WriteTask
103  {
106  size_t size;
107  WriteTask(Prefetch* p, int ri, size_t s):prefetch(p), ramBlockIdx(ri), size(s){}
108  };
109 
110  struct WriteQ
111  {
112  WriteQ() : condVar(0), size(0) {}
114  size_t size;
115  std::list<WriteTask> queue;
116  };
117 
118  static WriteQ s_writeQ;
119 
120  };
121 
122  //----------------------------------------------------------------------------
124  //----------------------------------------------------------------------------
125  class IO : public XrdOucCacheIO
126  {
127  friend class Prefetch;
128 
129  public:
130  IO (XrdOucCacheIO &io, XrdOucCacheStats &stats, Cache &cache) :
131  m_io(io), m_statsGlobal(stats), m_cache(cache) {}
132 
134  virtual XrdOucCacheIO *Base() { return &m_io; }
135 
137  virtual long long FSize() { return m_io.FSize(); }
138 
140  virtual const char *Path() { return m_io.Path(); }
141 
142  virtual int Sync() { return 0; }
143 
144  virtual int Trunc(long long Offset) { errno = ENOTSUP; return -1; }
145 
146  virtual int Write(char *Buffer, long long Offset, int Length)
147  { errno = ENOTSUP; return -1; }
148 
149  virtual void StartPrefetch() {}
150 
151  protected:
152  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
153 
157  };
158 }
159 
160 #endif
IO(XrdOucCacheIO &io, XrdOucCacheStats &stats, Cache &cache)
Definition: XrdFileCache.hh:130
Definition: XrdFileCache.hh:110
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *, int Options=0)
Obtain a new IO object that fronts existing XrdOucCacheIO.
WriteQ()
Definition: XrdFileCache.hh:112
WriteTask(Prefetch *p, int ri, size_t s)
Definition: XrdFileCache.hh:107
virtual int isAttached()
Number of cache-io objects atteched through this cache.
static WriteQ s_writeQ
Definition: XrdFileCache.hh:118
Downloads original file into multiple files, chunked into blocks. Only blocks that are asked for are ...
Definition: XrdFileCacheIOFileBlock.hh:39
virtual int Trunc(long long Offset)
Definition: XrdFileCache.hh:144
void getFilePathFromURL(const char *url, std::string &res) const
Transfor URL to path on local disk.
Definition: XrdFileCache.hh:30
Definition: XrdOucCache.hh:158
XrdSysMutex m_io_mutex
central lock for this class
Definition: XrdFileCache.hh:98
XrdOucCacheStats & m_stats
global cache usage statistics
Definition: XrdFileCache.hh:100
static void ProcessWriteTasks()
Separate task which writes blocks from ram to disk.
void Detach(XrdOucCacheIO *)
Decrease attached count. Called from IO::Detach().
std::list< WriteTask > queue
container
Definition: XrdFileCache.hh:115
Downloads data into a file on local disk and handles IO read requests.
Definition: XrdFileCachePrefetch.hh:42
static Log * GetLog()
Get default log.
Definition: XrdSysPthread.hh:140
size_t size
cache size of a container
Definition: XrdFileCache.hh:114
Base cache-io class that implements XrdOucCacheIO abstract methods.
Definition: XrdFileCache.hh:125
static void RemoveWriteQEntriesFor(Prefetch *p)
Remove blocks from write queue which belong to given prefetch. This method is used at the time of Pre...
virtual void StartPrefetch()
Definition: XrdFileCache.hh:149
Definition: XrdOucCache.hh:313
virtual XrdOucCache * Create(XrdOucCache::Parms &, XrdOucCacheIO::aprParms *)
Unused abstract method. Plugin instantiation role is given to the Factory class.
Definition: XrdFileCache.hh:64
virtual const char * Path()=0
virtual int Sync()
Definition: XrdFileCache.hh:142
Definition: XrdSysPthread.hh:53
virtual int Write(char *Buffer, long long Offset, int Length)
Definition: XrdFileCache.hh:146
Cache(XrdOucCacheStats &)
Constructor.
Definition: XrdClEnv.hh:28
Downloads original file into a single file on local disk. Handles read requests as they come along...
Definition: XrdFileCacheIOEntireFile.hh:39
Definition: XrdOucCache.hh:278
virtual long long FSize()
Original data source URL.
Definition: XrdFileCache.hh:137
unsigned int m_attached
number of attached IO objects
Definition: XrdFileCache.hh:99
Definition: XrdFileCache.hh:102
XrdOucCacheIO & m_io
original data source
Definition: XrdFileCache.hh:154
XrdSysCondVar condVar
write list condVar
Definition: XrdFileCache.hh:113
static bool HaveFreeWritingSlots()
Check write queue size is not over limit.
virtual XrdOucCacheIO * Base()
Original data source.
Definition: XrdFileCache.hh:134
static void AddWriteTask(Prefetch *p, int ramBlockidx, size_t size, bool fromRead)
Add downloaded block in write queue.
Definition: XrdOucCache.hh:93
virtual long long FSize()=0
Prefetch * prefetch
object queued for writing
Definition: XrdFileCache.hh:104
Definition: XrdOucCache.hh:351
XrdCl::Log * clLog() const
Definition: XrdFileCache.hh:152
Attaches/creates and detaches/deletes cache-io objects for disk based cache.
Definition: XrdFileCache.hh:39
XrdOucCacheStats & m_statsGlobal
reference to Cache statistics
Definition: XrdFileCache.hh:155
virtual const char * Path()
Original data source URL.
Definition: XrdFileCache.hh:140
size_t size
write size – block size except in case this is the end file block
Definition: XrdFileCache.hh:106
int ramBlockIdx
in memory cache index
Definition: XrdFileCache.hh:105
Cache & m_cache
reference to Cache needed in detach
Definition: XrdFileCache.hh:156
XrdCl::Log * clLog() const
Short log alias.
Definition: XrdFileCache.hh:96