22 #include "BESUncompressCache.h" 28 #include "BESInternalError.h" 31 #include "TheBESKeys.h" 34 bool BESUncompressCache::d_enabled =
true;
36 const string BESUncompressCache::DIR_KEY =
"BES.UncompressCache.dir";
37 const string BESUncompressCache::PREFIX_KEY =
"BES.UncompressCache.prefix";
38 const string BESUncompressCache::SIZE_KEY =
"BES.UncompressCache.size";
40 unsigned long BESUncompressCache::getCacheSizeFromConfig()
44 unsigned long size_in_megabytes = 0;
47 std::istringstream iss(size);
48 iss >> size_in_megabytes;
51 string msg =
"[ERROR] BESUncompressCache::getCacheSize() - The BES Key " + SIZE_KEY
52 +
" is not set! It MUST be set to utilize the decompression cache. ";
53 BESDEBUG(
"cache", msg << endl);
56 return size_in_megabytes;
59 string BESUncompressCache::getCacheDirFromConfig()
66 string msg =
"[ERROR] BESUncompressCache::getSubDirFromConfig() - The BES Key " + DIR_KEY
67 +
" is not set! It MUST be set to utilize the decompression cache. ";
68 BESDEBUG(
"cache", msg << endl);
75 string BESUncompressCache::getCachePrefixFromConfig()
84 string msg =
"[ERROR] BESUncompressCache::getResultPrefix() - The BES Key " + PREFIX_KEY
85 +
" is not set! It MUST be set to utilize the decompression cache. ";
86 BESDEBUG(
"cache", msg << endl);
125 string::size_type last_dot = target.rfind(
'.');
126 if (last_dot != string::npos) {
127 target = target.substr(0, last_dot);
132 BESDEBUG(
"cache",
"BESFileLockingCache::get_cache_file_name - target: '" << target <<
"'" << endl);
137 BESUncompressCache::BESUncompressCache()
139 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - BEGIN" << endl);
142 d_dimCacheDir = getCacheDirFromConfig();
143 d_dimCacheFilePrefix = getCachePrefixFromConfig();
144 d_maxCacheSize = getCacheSizeFromConfig();
147 "BESUncompressCache() - Cache configuration params: " << d_dimCacheDir <<
", " << d_dimCacheFilePrefix <<
", " << d_maxCacheSize << endl);
149 initialize(d_dimCacheDir, d_dimCacheFilePrefix, d_maxCacheSize);
151 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - END" << endl);
154 BESUncompressCache::BESUncompressCache(
const string &data_root_dir,
const string &cache_dir,
const string &prefix,
155 unsigned long long size)
157 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - BEGIN" << endl);
160 d_dataRootDir = data_root_dir;
161 d_dimCacheDir = cache_dir;
162 d_dimCacheFilePrefix = prefix;
163 d_maxCacheSize = size;
165 initialize(d_dimCacheDir, d_dimCacheFilePrefix, d_maxCacheSize);
167 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - END" << endl);
172 unsigned long long max_cache_size)
174 if (d_enabled && d_instance == 0) {
176 d_instance =
new BESUncompressCache(data_root_dir, cache_dir, result_file_prefix, max_cache_size);
181 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
182 "Cache is DISABLED"<< endl);
186 atexit(delete_instance);
188 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
189 "Cache is ENABLED"<< endl);
202 if (d_enabled && d_instance == 0) {
208 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
209 "Cache is DISABLED"<< endl);
213 atexit(delete_instance);
215 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
216 "Cache is ENABLED"<< endl);
223 BESUncompressCache::~BESUncompressCache()
238 bool BESUncompressCache::is_valid(
const string &cache_file_name,
const string &local_id)
244 off_t entry_size = 0;
245 time_t entry_time = 0;
247 if (stat(cache_file_name.c_str(), &buf) == 0) {
248 entry_size = buf.st_size;
249 entry_time = buf.st_mtime;
255 if (entry_size == 0)
return false;
257 time_t dataset_time = entry_time;
258 if (stat(datasetFileName.c_str(), &buf) == 0) {
259 dataset_time = buf.st_mtime;
269 if (dataset_time > entry_time)
return false;
exception thrown if inernal error encountered
static string lowercase(const string &s)
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
static string assemblePath(const string &firstPart, const string &secondPart, bool addLeadingSlash=false)
Assemble path fragments making sure that they are separated by a single '/' character.
static bool dir_exists(const string &dir)
static TheBESKeys * TheKeys()
virtual string get_cache_file_name(const string &src, bool mangle=true)
Build the name of file that will holds the uncompressed data from 'src' in the cache.
virtual string get_cache_file_name(const string &src, bool mangle=true)
static BESUncompressCache * get_instance()