|
bool | cache_enabled () const |
|
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 bool | create_and_lock (const std::string &target, int &fd) |
| Create a file in the cache and lock it for write access.
|
|
void | disable () |
| Disable the cache.
|
|
void | dump (std::ostream &strm) const override |
| dumps information about this object
|
|
void | enable () |
| Enable the cache.
|
|
virtual void | exclusive_to_shared_lock (int fd) |
| Transfer from an exclusive lock to a shared lock.
|
|
std::string | get_cache_directory () const |
|
std::string | get_cache_file_name (const std::string &src, bool mangle=true) override |
| Build the name of file that will holds the uncompressed data from 'src' in the cache.
|
|
std::string | get_cache_file_prefix () const |
|
virtual unsigned long long | get_cache_size () |
| Get the cache size.
|
|
virtual bool | get_exclusive_lock (const std::string &target, int &fd) |
|
virtual bool | get_exclusive_lock_nb (const std::string &target, int &fd) |
|
virtual bool | get_read_lock (const std::string &target, int &fd) |
| Get a read-only lock on the file if it exists.
|
|
void | initialize (const std::string &cache_dir, const std::string &prefix, unsigned long long size) |
| Initialize an instance of FileLockingCache.
|
|
bool | is_unlimited () const |
| Is this cache allowed to store as much as it wants?
|
|
virtual void | purge_file (const std::string &file) |
| Purge a single file from the cache.
|
|
virtual void | unlock_and_close (const std::string &target) |
|
virtual void | update_and_purge (const std::string &new_file) |
| Purge files from the cache.
|
|
virtual unsigned long long | update_cache_info (const std::string &target) |
| Update the cache info file to include 'target'.
|
|
Definition at line 28 of file BESUncompressCache.h.
bool BESFileLockingCache::create_and_lock |
( |
const std::string & | target, |
|
|
int & | fd ) |
|
virtualinherited |
Create a file in the cache and lock it for write access.
If the file does not exist, make it, open it for read-write access and get an exclusive lock on it. The locking operation blocks, although that should never happen.
- Parameters
-
target | The name of the file to make/open/lock |
fd | Value-result param that holds the file descriptor of the opened file |
- Returns
- True if the operation was successful, false otherwise. This method will return false if the file already existed (the file won't be locked and the descriptor reference is undefined - but likely -1).
- Exceptions
-
BESBESInternalError | if any error except EEXIST is returned by open(2) or if fcntl(2) returns an error. |
Definition at line 625 of file BESFileLockingCache.cc.
void BESFileLockingCache::exclusive_to_shared_lock |
( |
int | fd | ) |
|
|
virtualinherited |
Transfer from an exclusive lock to a shared lock.
If the file has an exclusive write lock on it, change that to a shared read lock. This is an atomic operation. If the call to fcntl(2) is protected by locking the cache, a dead lock will result given typical use of this class. This method exists to help with the situation where one process has the cache locked and is blocking on a shared read lock for a file that a second process has locked exclusively (for writing). By changing the exclusive lock to a shared lock, the first process can get its shared lock and then release the cache.
- Parameters
-
fd | The file descriptor that is exclusively locked and which, on exit, will have a shared lock. |
Definition at line 660 of file BESFileLockingCache.cc.
string BESUncompressCache::get_cache_file_name |
( |
const std::string & | src, |
|
|
bool | mangle = true ) |
|
overridevirtual |
Build the name of file that will holds the uncompressed data from 'src' in the cache.
Overrides the generic file name generator in BESFileLocking cache. Because this is the uncompress cache, we know that our job is to simply decompress the file and hand it off to the appropriate response handler for the associated file type. Since the state of file's "compressedness" is determined in ALL cases by suffix on the file name (or resource ID if you wish) we know that in addition to building the generic name we want to remove the compression suffix so that the resulting name/id (unmangled if previously mangled) will correctly match the BES TypeMatch regex system.
- Note
- How names are mangled: 'src' is the full name of the file to be cached.The file name passed has an extension on the end that will be stripped once the file is cached. For example, if the full path to the file name is /usr/lib/data/fnoc1.nc.gz then the resulting file name will be #<prefix>#usr#lib#data#fnoc1.nc.
- Parameters
-
src | The source name to cache |
mangle | if True, assume the name is a file pathname and mangle it. If false, do not mangle the name (assume the caller has sent a suitable string) but do turn the string into a pathname located in the cache directory with the cache prefix. the 'mangle' param is true by default. |
Reimplemented from BESFileLockingCache.
Definition at line 128 of file BESUncompressCache.cc.
void BESFileLockingCache::initialize |
( |
const std::string & | cache_dir, |
|
|
const std::string & | prefix, |
|
|
unsigned long long | size ) |
|
inherited |
Initialize an instance of FileLockingCache.
Initialize and instance of FileLockingCache using the passed values for the cache directory, item prefix and max cache size. This will ignore the value of enable_cache() (but will correctly (re)set it based on the directory, ..., values). This provides a way for clients to re-initialize caches on the fly.
- Parameters
-
cache_dir | The directory into which the cache files will be written. |
prefix | The prefix that will be added to each cache file. |
size | The size of the cache in MBytes |
- Exceptions
-
BESInternalError | If the cache_dir does not exist or is not writable. size is 0, or if cache dir does not exist. |
BESError | If the parameters (directory, ...) are invalid. |
Definition at line 259 of file BESFileLockingCache.cc.
void BESFileLockingCache::purge_file |
( |
const std::string & | file | ) |
|
|
virtualinherited |
Purge a single file from the cache.
Purge a single file from the cache. The file might be old, etc., and need to be removed. Don't use this to shrink the cache when it gets too big, use update_and_purge() instead since that file optimizes accesses to the cache control file for several changes in a row.
- Parameters
-
file | The name of the file to purge. |
Definition at line 1125 of file BESFileLockingCache.cc.
void BESFileLockingCache::unlock_and_close |
( |
const std::string & | target | ) |
|
|
virtualinherited |
Get an exclusive lock on the 'cache info' file. The 'cache info' file is used to control certain cache actions, ensuring that they are atomic. These include making sure that the create_and_lock() and read_and_lock() operations are atomic as well as the purge and related operations.
- Note
- This is intended to be used internally only but might be useful in some settings. Unlock the named file.
This does not do any name mangling; it just closes and unlocks whatever is named (or throws BESBESInternalError if the file cannot be closed). If the file was opened more than once, all descriptors are closed. If you need to close a specific descriptor, use the other version of unlock_and_close().
- Note
- This method assumes that the file was opened/locked using one of read_and_lock() or create_and_lock(). Those methods record the name/file- descriptor pairs so that the files can be properly closed and locks released.
- Parameters
-
file_name | The name of the file to unlock. |
- Exceptions
-
Definition at line 745 of file BESFileLockingCache.cc.