00001 #ifndef __XRDFILECACHE_FACTORY_HH__ 00002 #define __XRDFILECACHE_FACTORY_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 00021 #include <string> 00022 #include <vector> 00023 #include <map> 00024 00025 #include "XrdSys/XrdSysPthread.hh" 00026 #include "XrdOuc/XrdOucCache.hh" 00027 00028 #include "XrdCl/XrdClDefaultEnv.hh" 00029 #include "XrdVersion.hh" 00030 #include "XrdFileCacheDecision.hh" 00031 00032 class XrdOucStream; 00033 class XrdSysError; 00034 00035 namespace XrdCl 00036 { 00037 class Log; 00038 } 00039 00040 namespace XrdFileCache 00041 { 00042 //---------------------------------------------------------------------------- 00044 //---------------------------------------------------------------------------- 00045 struct Configuration 00046 { 00047 Configuration() : 00048 m_prefetchFileBlocks(false), 00049 m_cache_dir("/var/tmp/xrootd-file-cache"), 00050 m_username("nobody"), 00051 m_lwm(0.95), 00052 m_hwm(0.9), 00053 m_bufferSize(1024*1024), 00054 m_NRamBuffersRead(8), 00055 m_NRamBuffersPrefetch(1), 00056 m_fileFragmentSize(128*1024*1024) {} 00057 00058 bool m_prefetchFileBlocks; 00059 std::string m_cache_dir; 00060 std::string m_username; 00061 00062 float m_lwm; 00063 float m_hwm; 00064 00065 long long m_bufferSize; 00066 int m_NRamBuffersRead; 00067 int m_NRamBuffersPrefetch; 00068 long long m_fileFragmentSize; 00069 }; 00070 00071 00072 //---------------------------------------------------------------------------- 00074 //---------------------------------------------------------------------------- 00075 class Factory : public XrdOucCache 00076 { 00077 public: 00078 //-------------------------------------------------------------------------- 00080 //-------------------------------------------------------------------------- 00081 Factory(); 00082 00083 //--------------------------------------------------------------------- 00086 //--------------------------------------------------------------------- 00087 virtual XrdOucCacheIO *Attach(XrdOucCacheIO *, int Options=0) { return NULL; } 00088 00089 //--------------------------------------------------------------------- 00092 //--------------------------------------------------------------------- 00093 virtual int isAttached() { return false; } 00094 00095 //--------------------------------------------------------------------- 00097 //--------------------------------------------------------------------- 00098 virtual XrdOucCache* Create(Parms &, XrdOucCacheIO::aprParms *aprP); 00099 00100 XrdOss* GetOss() const { return m_output_fs; } 00101 00102 //--------------------------------------------------------------------- 00104 //--------------------------------------------------------------------- 00105 XrdSysError& GetSysError() { return m_log; } 00106 00107 //-------------------------------------------------------------------- 00113 //-------------------------------------------------------------------- 00114 bool Decide(XrdOucCacheIO*); 00115 00116 //------------------------------------------------------------------------ 00118 //------------------------------------------------------------------------ 00119 const Configuration& RefConfiguration() const { return m_configuration; } 00120 00121 00122 //--------------------------------------------------------------------- 00130 //--------------------------------------------------------------------- 00131 bool Config(XrdSysLogger *logger, const char *config_filename, const char *parameters); 00132 00133 //--------------------------------------------------------------------- 00135 //--------------------------------------------------------------------- 00136 static Factory &GetInstance(); 00137 00138 //--------------------------------------------------------------------- 00140 //--------------------------------------------------------------------- 00141 static bool VCheck(XrdVersionInfo &urVersion) { return true; } 00142 00143 //--------------------------------------------------------------------- 00145 //--------------------------------------------------------------------- 00146 void CacheDirCleanup(); 00147 00148 private: 00149 bool CheckFileForDiskSpace(const char* path, long long fsize); 00150 void UnCheckFileForDiskSpace(const char* path); 00151 00152 bool ConfigParameters(std::string, XrdOucStream&); 00153 bool ConfigXeq(char *, XrdOucStream &); 00154 bool xdlib(XrdOucStream &); 00155 00156 XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); } 00157 00158 static Factory *m_factory; 00159 00160 XrdSysError m_log; 00161 XrdOucCacheStats m_stats; 00162 XrdOss *m_output_fs; 00163 00164 std::vector<XrdFileCache::Decision*> m_decisionpoints; 00165 00166 std::map<std::string, long long> m_filesInQueue; 00167 00168 Configuration m_configuration; 00169 }; 00170 } 00171 00172 #endif