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 #include "XrdCl/XrdClDefaultEnv.hh"
28 #include "XrdVersion.hh"
29 
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_blockSize(128*1024*1024) {}
57 
59  std::string m_cache_dir;
60  std::string m_username;
61  std::string m_osslib_name;
62 
63  float m_lwm;
64  float m_hwm;
65 
66  long long m_bufferSize;
69  long long m_blockSize;
70  };
71 
72 
73  //----------------------------------------------------------------------------
75  //----------------------------------------------------------------------------
76  class Factory : public XrdOucCache
77  {
78  public:
79  //--------------------------------------------------------------------------
81  //--------------------------------------------------------------------------
82  Factory();
83 
84  //---------------------------------------------------------------------
87  //---------------------------------------------------------------------
88  virtual XrdOucCacheIO *Attach(XrdOucCacheIO *, int Options=0) { return NULL; }
89 
90  //---------------------------------------------------------------------
93  //---------------------------------------------------------------------
94  virtual int isAttached() { return false; }
95 
96  //---------------------------------------------------------------------
98  //---------------------------------------------------------------------
99  virtual XrdOucCache* Create(Parms &, XrdOucCacheIO::aprParms *aprP);
100 
101  XrdOss* GetOss() const { return m_output_fs; }
102 
103  //---------------------------------------------------------------------
105  //---------------------------------------------------------------------
107 
108  //--------------------------------------------------------------------
114  //--------------------------------------------------------------------
115  bool Decide(XrdOucCacheIO*);
116 
117  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  const Configuration& RefConfiguration() const { return m_configuration; }
121 
122 
123  //---------------------------------------------------------------------
131  //---------------------------------------------------------------------
132  bool Config(XrdSysLogger *logger, const char *config_filename, const char *parameters);
133 
134  //---------------------------------------------------------------------
136  //---------------------------------------------------------------------
137  static Factory &GetInstance();
138 
139  //---------------------------------------------------------------------
141  //---------------------------------------------------------------------
142  static bool VCheck(XrdVersionInfo &urVersion) { return true; }
143 
144  //---------------------------------------------------------------------
146  //---------------------------------------------------------------------
147  void CacheDirCleanup();
148 
149  private:
150  bool CheckFileForDiskSpace(const char* path, long long fsize);
151  void UnCheckFileForDiskSpace(const char* path);
152 
153  bool ConfigParameters(const char *);
154  bool ConfigXeq(char *, XrdOucStream &);
155  bool xolib(XrdOucStream &);
156  bool xdlib(XrdOucStream &);
157 
158  XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); }
159 
160  static Factory *m_factory;
161 
165 
166  std::vector<XrdFileCache::Decision*> m_decisionpoints;
167 
168  std::map<std::string, long long> m_filesInQueue;
169 
171  };
172 }
173 
174 #endif
long long m_blockSize
used with m_prefetchFileBlocks, default 128MB
Definition: XrdFileCacheFactory.hh:69
Instantiates Cache and Decision plugins. Parses configuration file.
Definition: XrdFileCacheFactory.hh:76
bool ConfigXeq(char *, XrdOucStream &)
XrdOucCacheStats m_stats
passed to cache, currently not used
Definition: XrdFileCacheFactory.hh:163
Definition: XrdOucCache.hh:158
std::vector< XrdFileCache::Decision * > m_decisionpoints
decision plugins
Definition: XrdFileCacheFactory.hh:166
bool Config(XrdSysLogger *logger, const char *config_filename, const char *parameters)
Parse configuration file.
Definition: XrdOucStream.hh:43
XrdSysError & GetSysError()
Getter for xrootd logger.
Definition: XrdFileCacheFactory.hh:106
static bool VCheck(XrdVersionInfo &urVersion)
Version check.
Definition: XrdFileCacheFactory.hh:142
void UnCheckFileForDiskSpace(const char *path)
std::string m_username
username passed to oss plugin
Definition: XrdFileCacheFactory.hh:60
bool ConfigParameters(const char *)
Definition: XrdSysError.hh:87
int m_NRamBuffersRead
number of read in-memory cache blocks
Definition: XrdFileCacheFactory.hh:67
static Log * GetLog()
Get default log.
XrdCl::Log * clLog() const
Definition: XrdFileCacheFactory.hh:158
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:120
float m_hwm
cache purge high water mark
Definition: XrdFileCacheFactory.hh:64
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:88
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:94
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:164
Configuration m_configuration
configurable parameters
Definition: XrdFileCacheFactory.hh:170
int m_NRamBuffersPrefetch
number of prefetch in-memory cache blocks
Definition: XrdFileCacheFactory.hh:68
bool xolib(XrdOucStream &)
Definition: XrdSysLogger.hh:50
static Factory * m_factory
this object
Definition: XrdFileCacheFactory.hh:160
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:168
static Factory & GetInstance()
Singleton access.
Definition: XrdOss.hh:173
float m_lwm
cache purge low water mark
Definition: XrdFileCacheFactory.hh:63
void CacheDirCleanup()
Thread function running disk cache purge periodically.
std::string m_osslib_name
oss library name (optional)
Definition: XrdFileCacheFactory.hh:61
Definition: XrdOucCache.hh:93
XrdSysError m_log
XrdFileCache namespace logger.
Definition: XrdFileCacheFactory.hh:162
XrdOss * GetOss() const
Definition: XrdFileCacheFactory.hh:101
long long m_bufferSize
prefetch buffer size, default 1MB
Definition: XrdFileCacheFactory.hh:66