22 #include "BESUncompressCache.h" 28 #include "BESInternalError.h" 31 #include "TheBESKeys.h" 34 const string BESUncompressCache::DIR_KEY =
"BES.UncompressCache.dir";
35 const string BESUncompressCache::PREFIX_KEY =
"BES.UncompressCache.prefix";
36 const string BESUncompressCache::SIZE_KEY =
"BES.UncompressCache.size";
38 unsigned long BESUncompressCache::getCacheSizeFromConfig()
42 unsigned long size_in_megabytes = 0;
45 std::istringstream iss(size);
46 iss >> size_in_megabytes;
49 string msg =
"[ERROR] BESUncompressCache::getCacheSize() - The BES Key " + SIZE_KEY
50 +
" is not set! It MUST be set to utilize the decompression cache. ";
51 BESDEBUG(
"cache", msg << endl);
54 return size_in_megabytes;
57 string BESUncompressCache::getCacheDirFromConfig()
64 string msg =
"[ERROR] BESUncompressCache::getSubDirFromConfig() - The BES Key " + DIR_KEY
65 +
" is not set! It MUST be set to utilize the decompression cache. ";
66 BESDEBUG(
"cache", msg << endl);
73 string BESUncompressCache::getCachePrefixFromConfig()
82 string msg =
"[ERROR] BESUncompressCache::getResultPrefix() - The BES Key " + PREFIX_KEY
83 +
" is not set! It MUST be set to utilize the decompression cache. ";
84 BESDEBUG(
"cache", msg << endl);
123 string::size_type last_dot = target.rfind(
'.');
124 if (last_dot != string::npos) {
125 target = target.substr(0, last_dot);
130 BESDEBUG(
"cache",
"BESFileLockingCache::get_cache_file_name - target: '" << target <<
"'" << endl);
135 BESUncompressCache::BESUncompressCache()
137 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - BEGIN" << endl);
139 d_dimCacheDir = getCacheDirFromConfig();
140 d_dimCacheFilePrefix = getCachePrefixFromConfig();
141 d_maxCacheSize = getCacheSizeFromConfig();
144 "BESUncompressCache() - Cache configuration params: " << d_dimCacheDir <<
", " << d_dimCacheFilePrefix <<
", " << d_maxCacheSize << endl);
146 initialize(d_dimCacheDir, d_dimCacheFilePrefix, d_maxCacheSize);
148 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - END" << endl);
151 BESUncompressCache::BESUncompressCache(
const string &data_root_dir,
const string &cache_dir,
const string &prefix,
152 unsigned long long size)
155 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - BEGIN" << endl);
157 d_dataRootDir = data_root_dir;
158 d_dimCacheDir = cache_dir;
159 d_dimCacheFilePrefix = prefix;
160 d_maxCacheSize = size;
162 initialize(d_dimCacheDir, d_dimCacheFilePrefix, d_maxCacheSize);
164 BESDEBUG(
"cache",
"BESUncompressCache::BESUncompressCache() - END" << endl);
169 unsigned long long max_cache_size)
171 if (d_instance == 0) {
174 d_instance =
new BESUncompressCache(data_root_dir, cache_dir, result_file_prefix, max_cache_size);
176 atexit(delete_instance);
181 "[ERROR] BESUncompressCache::get_instance(): Failed to obtain cache! msg: " << bie.
get_message() << endl);
194 if (d_instance == 0) {
198 atexit(delete_instance);
203 "[ERROR] BESUncompressCache::get_instance(): Failed to obtain cache! msg: " << bie.
get_message() << endl);
210 BESUncompressCache::~BESUncompressCache()
225 bool BESUncompressCache::is_valid(
const string &cache_file_name,
const string &local_id)
231 off_t entry_size = 0;
232 time_t entry_time = 0;
234 if (stat(cache_file_name.c_str(), &buf) == 0) {
235 entry_size = buf.st_size;
236 entry_time = buf.st_mtime;
242 if (entry_size == 0)
return false;
244 time_t dataset_time = entry_time;
245 if (stat(datasetFileName.c_str(), &buf) == 0) {
246 dataset_time = buf.st_mtime;
256 if (dataset_time > entry_time)
return false;
exception thrown if inernal error encountered
static string lowercase(const string &s)
virtual std::string get_message()
get the error message for this exception
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)
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()
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
static BESKeys * TheKeys()