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
Instantiates Cache and Decision plugins. Parses configuration file.
Definition: XrdFileCacheFactory.hh:75
bool ConfigXeq(char *, XrdOucStream &)
XrdOucCacheStats m_stats
passed to cache, currently not used
Definition: XrdFileCacheFactory.hh:161
Definition: XrdOucCache.hh:158
std::vector< XrdFileCache::Decision * > m_decisionpoints
decision plugins
Definition: XrdFileCacheFactory.hh:164
bool Config(XrdSysLogger *logger, const char *config_filename, const char *parameters)
Parse configuration file.
Definition: XrdOucStream.hh:43
bool ConfigParameters(std::string, XrdOucStream &)
XrdSysError & GetSysError()
Getter for xrootd logger.
Definition: XrdFileCacheFactory.hh:105
static bool VCheck(XrdVersionInfo &urVersion)
Version check.
Definition: XrdFileCacheFactory.hh:141
void UnCheckFileForDiskSpace(const char *path)
std::string m_username
username passed to oss plugin
Definition: XrdFileCacheFactory.hh:60
Definition: XrdSysError.hh:87
int m_NRamBuffersRead
number of read in-memory cache blocks
Definition: XrdFileCacheFactory.hh:66
static Log * GetLog()
Get default log.
XrdCl::Log * clLog() const
Definition: XrdFileCacheFactory.hh:156
Definition: XrdOucCache.hh:313
Factory()
Constructor.
bool CheckFileForDiskSpace(const char *path, long long fsize)
std::string m_cache_dir
path of disk cache
Definition: XrdFileCacheFactory.hh:59
bool Decide(XrdOucCacheIO *)
Makes decision if the original XrdOucCacheIO should be cached.
const Configuration & RefConfiguration() const
Reference XrdFileCache configuration.
Definition: XrdFileCacheFactory.hh:119
float m_hwm
cache purge high water mark
Definition: XrdFileCacheFactory.hh:63
bool xdlib(XrdOucStream &)
virtual XrdOucCacheIO * Attach(XrdOucCacheIO *, int Options=0)
Unused abstract method. This method is implemented in the the Cache class.
Definition: XrdFileCacheFactory.hh:87
virtual XrdOucCache * Create(Parms &, XrdOucCacheIO::aprParms *aprP)
Creates XrdFileCache::Cache object.
virtual int isAttached()
Unused abstract method. This information is available in the Cache class.
Definition: XrdFileCacheFactory.hh:93
Contains parameters configurable from the xrootd config file.
Definition: XrdFileCacheFactory.hh:45
Definition: XrdOucCache.hh:278
XrdOss * m_output_fs
disk cache file system
Definition: XrdFileCacheFactory.hh:162
Configuration m_configuration
configurable parameters
Definition: XrdFileCacheFactory.hh:168
int m_NRamBuffersPrefetch
number of prefetch in-memory cache blocks
Definition: XrdFileCacheFactory.hh:67
Definition: XrdSysLogger.hh:50
static Factory * m_factory
this object
Definition: XrdFileCacheFactory.hh:158
Configuration()
Definition: XrdFileCacheFactory.hh:47
bool m_prefetchFileBlocks
flag for enabling block-level operation
Definition: XrdFileCacheFactory.hh:58
std::map< std::string, long long > m_filesInQueue
Definition: XrdFileCacheFactory.hh:166
static Factory & GetInstance()
Singleton access.
Definition: XrdOss.hh:173
float m_lwm
cache purge low water mark
Definition: XrdFileCacheFactory.hh:62
void CacheDirCleanup()
Thread function running disk cache purge periodically.
Definition: XrdOucCache.hh:93
XrdSysError m_log
XrdFileCache namespace logger.
Definition: XrdFileCacheFactory.hh:160
long long m_fileFragmentSize
used with m_prefetchFileBlocks, default 128MB
Definition: XrdFileCacheFactory.hh:68
XrdOss * GetOss() const
Definition: XrdFileCacheFactory.hh:100
long long m_bufferSize
prefetch buffer size, default 1MB
Definition: XrdFileCacheFactory.hh:65