bes
Updated for version 3.20.6
|
29 #ifndef BESFileLockingCache_h_
30 #define BESFileLockingCache_h_ 1
40 #define USE_GET_SHARED_LOCK 1
46 unsigned long long size;
50 typedef std::list<cache_entry> CacheFiles;
88 friend class FileLockingCacheTest;
91 static const char DAP_CACHE_CHAR =
'#';
96 std::string d_cache_dir;
103 unsigned long long d_max_cache_size_in_bytes;
106 unsigned long long d_target_size;
109 std::string d_cache_info;
113 typedef std::multimap<std::string, int> FilesAndLockDescriptors;
114 FilesAndLockDescriptors d_locks;
116 bool m_check_ctor_params();
117 bool m_initialize_cache_info();
119 unsigned long long m_collect_cache_dir_info(CacheFiles &contents);
121 void m_record_descriptor(
const std::string &file,
int fd);
122 int m_remove_descriptor(
const std::string &file);
123 #if USE_GET_SHARED_LOCK
124 int m_find_descriptor(
const std::string &file);
132 BESFileLockingCache(): d_cache_enabled(
true), d_cache_dir(
""), d_prefix(
""), d_max_cache_size_in_bytes(0),
133 d_target_size(0), d_cache_info(
""), d_cache_info_fd(-1) { }
135 BESFileLockingCache(
const std::string &cache_dir,
const std::string &prefix,
unsigned long long size);
139 if (d_cache_info_fd != -1) {
140 close(d_cache_info_fd);
141 d_cache_info_fd = -1;
145 void initialize(
const std::string &cache_dir,
const std::string &prefix,
unsigned long long size);
150 virtual bool get_read_lock(
const std::string &target,
int &fd);
159 virtual bool cache_too_big(
unsigned long long current_size)
const;
162 virtual bool get_exclusive_lock_nb(
const std::string &target,
int &fd);
163 virtual bool get_exclusive_lock(
const std::string &target,
int &fd);
166 virtual void purge_file(
const std::string &file);
178 return d_max_cache_size_in_bytes == 0;
195 static bool dir_exists(
const std::string &dir);
200 return d_cache_enabled;
206 d_cache_enabled =
false;
212 d_cache_enabled =
true;
215 virtual void dump(std::ostream &strm)
const;
218 #endif // BESFileLockingCache_h_
virtual bool get_read_lock(const std::string &target, int &fd)
Get a read-only lock on the file if it exists.
virtual unsigned long long get_cache_size()
Get the cache size.
bool cache_enabled() const
virtual bool create_and_lock(const std::string &target, int &fd)
Create a file in the cache and lock it for write access.
virtual void lock_cache_write()
bool is_unlimited() const
Is this cache allowed to store as much as it wants?
static bool dir_exists(const std::string &dir)
const std::string get_cache_file_prefix()
virtual void purge_file(const std::string &file)
Purge a single file from the cache.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void unlock_and_close(const std::string &target)
void enable()
Enable the cache.
top level BES object to house generic methods
virtual void lock_cache_read()
void initialize(const std::string &cache_dir, const std::string &prefix, unsigned long long size)
Initialize an instance of FileLockingCache.
void disable()
Disable the cache.
Implementation of a caching mechanism for compressed data.
virtual unsigned long long update_cache_info(const std::string &target)
Update the cache info file to include 'target'.
virtual std::string get_cache_file_name(const std::string &src, bool mangle=true)
virtual void update_and_purge(const std::string &new_file)
Purge files from the cache.
virtual void unlock_cache()
const std::string get_cache_directory()
virtual bool cache_too_big(unsigned long long current_size) const
look at the cache size; is it too large? Look at the cache size and see if it is too big.
virtual void exclusive_to_shared_lock(int fd)
Transfer from an exclusive lock to a shared lock.