22 #include "BESUncompressCache.h"
28 #include "BESInternalError.h"
31 #include "TheBESKeys.h"
37 bool BESUncompressCache::d_enabled =
true;
39 const string BESUncompressCache::DIR_KEY =
"BES.UncompressCache.dir";
40 const string BESUncompressCache::PREFIX_KEY =
"BES.UncompressCache.prefix";
41 const string BESUncompressCache::SIZE_KEY =
"BES.UncompressCache.size";
43 unsigned long BESUncompressCache::getCacheSizeFromConfig()
47 unsigned long size_in_megabytes = 0;
50 std::istringstream iss(size);
51 iss >> size_in_megabytes;
54 string msg =
"[ERROR] BESUncompressCache::getCacheSize() - The BES Key " + SIZE_KEY
55 +
" is not set! It MUST be set to utilize the decompression cache. ";
56 BESDEBUG(
"cache", msg << endl);
59 return size_in_megabytes;
62 string BESUncompressCache::getCacheDirFromConfig()
69 string msg =
"[ERROR] BESUncompressCache::getSubDirFromConfig() - The BES Key " + DIR_KEY
70 +
" is not set! It MUST be set to utilize the decompression cache. ";
71 BESDEBUG(
"cache", msg << endl);
78 string BESUncompressCache::getCachePrefixFromConfig()
87 string msg =
"[ERROR] BESUncompressCache::getResultPrefix() - The BES Key " + PREFIX_KEY
88 +
" is not set! It MUST be set to utilize the decompression cache. ";
89 BESDEBUG(
"cache", msg << endl);
128 string::size_type last_dot = target.rfind(
'.');
129 if (last_dot != string::npos) {
130 target = target.substr(0, last_dot);
135 BESDEBUG(
"cache",
"BESFileLockingCache::get_cache_file_name - target: '" << target <<
"'" << endl);
140 BESUncompressCache::BESUncompressCache()
142 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - BEGIN" << endl);
145 d_dimCacheDir = getCacheDirFromConfig();
146 d_dimCacheFilePrefix = getCachePrefixFromConfig();
147 d_maxCacheSize = getCacheSizeFromConfig();
150 "BESUncompressCache() - Cache configuration params: " << d_dimCacheDir <<
", " << d_dimCacheFilePrefix <<
", " << d_maxCacheSize << endl);
152 initialize(d_dimCacheDir, d_dimCacheFilePrefix, d_maxCacheSize);
154 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - END" << endl);
157 BESUncompressCache::BESUncompressCache(
const string &data_root_dir,
const string &cache_dir,
const string &prefix,
158 unsigned long long size)
160 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - BEGIN" << endl);
163 d_dataRootDir = data_root_dir;
164 d_dimCacheDir = cache_dir;
165 d_dimCacheFilePrefix = prefix;
166 d_maxCacheSize = size;
168 initialize(d_dimCacheDir, d_dimCacheFilePrefix, d_maxCacheSize);
170 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - END" << endl);
175 unsigned long long max_cache_size)
177 if (d_enabled && d_instance == 0) {
179 d_instance =
new BESUncompressCache(data_root_dir, cache_dir, result_file_prefix, max_cache_size);
184 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
185 "Cache is DISABLED"<< endl);
189 atexit(delete_instance);
191 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
192 "Cache is ENABLED"<< endl);
205 if (d_enabled && d_instance == 0) {
211 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
212 "Cache is DISABLED"<< endl);
216 atexit(delete_instance);
218 BESDEBUG(
"cache",
"BESUncompressCache::"<<__func__ <<
"() - " <<
219 "Cache is ENABLED"<< endl);
226 BESUncompressCache::~BESUncompressCache()
243 bool BESUncompressCache::is_valid(
const string &cache_file_name,
const string &local_id)
249 off_t entry_size = 0;
250 time_t entry_time = 0;
252 if (stat(cache_file_name.c_str(), &buf) == 0) {
253 entry_size = buf.st_size;
254 entry_time = buf.st_mtime;
260 if (entry_size == 0)
return false;
262 time_t dataset_time = entry_time;
263 if (stat(datasetFileName.c_str(), &buf) == 0) {
264 dataset_time = buf.st_mtime;
274 if (dataset_time > entry_time)
return false;