xrootd
XrdFileCacheFactory.hh
Go to the documentation of this file.
1 #ifndef __XRDFILECACHE_FACTORY_HH__
2 #define __XRDFILECACHE_FACTORY_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 
21 #include <string>
22 #include <vector>
23 #include <map>
24 
25 #include "XrdSys/XrdSysPthread.hh"
26 #include "XrdOuc/XrdOucCache.hh"
27 
28 #include "XrdCl/XrdClDefaultEnv.hh"
29 #include "XrdVersion.hh"
30 #include "XrdFileCacheDecision.hh"
31 
32 class XrdOucStream;
33 class XrdSysError;
34 
35 namespace XrdCl
36 {
37  class Log;
38 }
39 
40 namespace XrdFileCache
41 {
42  //----------------------------------------------------------------------------
44  //----------------------------------------------------------------------------
46  {
48  m_prefetchFileBlocks(false),
49  m_cache_dir("/var/tmp/xrootd-file-cache"),
50  m_username("nobody"),
51  m_lwm(0.95),
52  m_hwm(0.9),
53  m_bufferSize(1024*1024),
56  m_fileFragmentSize(128*1024*1024) {}
57 
59  std::string m_cache_dir;
60  std::string m_username;
61 
62  float m_lwm;
63  float m_hwm;
64 
65  long long m_bufferSize;
68  long long m_fileFragmentSize;
69  };
70 
71 
72  //----------------------------------------------------------------------------
74  //----------------------------------------------------------------------------
75  class Factory : public XrdOucCache
76  {
77  public:
78  //--------------------------------------------------------------------------
80  //--------------------------------------------------------------------------
81  Factory();
82 
83  //---------------------------------------------------------------------
86  //---------------------------------------------------------------------
87  virtual XrdOucCacheIO *Attach(XrdOucCacheIO *, int Options=0) { return NULL; }
88 
89  //---------------------------------------------------------------------
92  //---------------------------------------------------------------------
93  virtual int isAttached() { return false; }
94 
95  //---------------------------------------------------------------------
97  //---------------------------------------------------------------------
98  virtual XrdOucCache* Create(Parms &, XrdOucCacheIO::aprParms *aprP);
99 
100  XrdOss* GetOss() const { return m_output_fs; }
101 
102  //---------------------------------------------------------------------
104  //---------------------------------------------------------------------
106 
107  //--------------------------------------------------------------------
113  //--------------------------------------------------------------------
114  bool Decide(XrdOucCacheIO*);
115 
116  //------------------------------------------------------------------------
118  //------------------------------------------------------------------------
119  const Configuration& RefConfiguration() const { return m_configuration; }
120 
121 
122  //---------------------------------------------------------------------
130  //---------------------------------------------------------------------
131  bool Config(XrdSysLogger *logger, const char *config_filename, const char *parameters);
132 
133  //---------------------------------------------------------------------
135  //---------------------------------------------------------------------
136  static Factory &GetInstance();
137 
138  //---------------------------------------------------------------------
140  //---------------------------------------------------------------------
141  static bool VCheck(XrdVersionInfo &urVersion) { return true; }
142 
143  //---------------------------------------------------------------------
145  //---------------------------------------------------------------------
146  void CacheDirCleanup();
147 
148  private:
149  bool CheckFileForDiskSpace(const char* path, long long fsize);
150  void UnCheckFileForDiskSpace(const char* path);
151 
152  bool ConfigParameters(std::string, XrdOucStream&);
153  bool ConfigXeq(char *, XrdOucStream &);
154  bool xdlib(XrdOucStream &);
155 
156  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
157 
158  static Factory *m_factory;
159 
163 
164  std::vector<XrdFileCache::Decision*> m_decisionpoints;
165 
166  std::map<std::string, long long> m_filesInQueue;
167 
169  };
170 }
171 
172 #endif