42 #include "PicoSHA2/picosha2.h"
44 #include "BESInternalError.h"
47 #include "TheBESKeys.h"
56 #define AT_EXIT(x) atexit((x))
65 bool CmrCache::d_enabled =
true;
67 const string CmrCache::DIR_KEY =
"CMR.Cache.dir";
68 const string CmrCache::PREFIX_KEY =
"CMR.Cache.prefix";
69 const string CmrCache::SIZE_KEY =
"CMR.Cache.size";
71 unsigned long CmrCache::getCacheSizeFromConfig()
76 unsigned long size_in_megabytes = 0;
79 std::istringstream iss(size);
80 iss >> size_in_megabytes;
83 string msg =
"CmrCache - The BES Key " + SIZE_KEY +
" is not set.";
84 BESDEBUG(MODULE, msg << endl);
87 return size_in_megabytes;
90 string CmrCache::getCacheDirFromConfig()
97 string msg =
"CmrCache - The BES Key " + DIR_KEY +
" is not set.";
98 BESDEBUG(MODULE, msg << endl);
105 string CmrCache::getCachePrefixFromConfig()
114 string msg =
"CmrCache - The BES Key " + PREFIX_KEY +
" is not set.";
115 BESDEBUG(MODULE, msg << endl);
124 BESDEBUG(MODULE,
"CmrCache::CmrCache() - BEGIN" << endl);
126 string cacheDir = getCacheDirFromConfig();
127 string cachePrefix = getCachePrefixFromConfig();
128 unsigned long cacheSizeMbytes = getCacheSizeFromConfig();
131 "CmrCache() - Cache configuration params: " << cacheDir <<
", " << cachePrefix <<
", " << cacheSizeMbytes << endl);
133 initialize(cacheDir, cachePrefix, cacheSizeMbytes);
135 BESDEBUG(MODULE,
"CmrCache::CmrCache() - END" << endl);
138 CmrCache::CmrCache(
const string &cache_dir,
const string &prefix,
unsigned long long size)
140 BESDEBUG(MODULE,
"CmrCache::CmrCache() - BEGIN" << endl);
144 BESDEBUG(MODULE,
"CmrCache::CmrCache() - END" << endl);
148 CmrCache::get_instance(
const string &cache_dir,
const string &cache_file_prefix,
unsigned long long max_cache_size)
150 if (d_enabled && d_instance == 0) {
152 d_instance =
new CmrCache(cache_dir, cache_file_prefix, max_cache_size);
157 BESDEBUG(MODULE,
"CmrCache::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
160 AT_EXIT(delete_instance);
162 BESDEBUG(MODULE,
"CmrCache::"<<__func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
176 if (d_enabled && d_instance == 0) {
183 BESDEBUG(MODULE,
"CmrCache::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
186 AT_EXIT(delete_instance);
188 BESDEBUG(MODULE,
"CmrCache::" << __func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
193 "[ERROR] CmrCache::get_instance(): Failed to obtain cache! msg: " << bie.
get_message() << endl);
211 throw BESInternalError(
"Empty name passed to the Metadata Store.", __FILE__, __LINE__);
212 return picosha2::hash256_hex_string(name[0] ==
'/' ? name :
"/" + name);