libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
|
Implementation of a caching mechanism for compressed data. This cache uses simple advisory locking found on most modern unix file systems. Compressed files are decompressed and stored in a cache where they can be used over and over until removed from the cache. Several processes can share the cache with each reading from files. At the same time, new files can be added and the cache can be purged, without disrupting the existing read operations. More...
#include <DAPCache3.h>
Public Member Functions | |
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 string &target, int &fd) |
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. | |
virtual void | dump (ostream &strm) const |
dumps information about this object | |
virtual void | dump (std::ostream &strm) const =0 |
dump the contents of this object to the specified ostream | |
virtual void | exclusive_to_shared_lock (int fd) |
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. | |
string | get_cache_file_name (const string &src, bool mangle=true) |
virtual unsigned long long | get_cache_size () |
Get the cache size. Read the size information from the cache info file and return it. This methods locks the cache. | |
virtual bool | get_read_lock (const string &target, int &fd) |
Get a read-only lock on the file if it exists. | |
virtual void | lock_cache_read () |
virtual void | lock_cache_write () |
virtual void | purge_file (const string &file) |
Purge a single file from the cache. | |
virtual void | unlock_and_close (const string &target) |
virtual void | unlock_and_close (int fd) |
virtual void | unlock_cache () |
virtual void | update_and_purge (const string &new_file) |
Purge files from the cache. | |
virtual unsigned long long | update_cache_info (const string &target) |
Update the cache info file to include 'target'. | |
Static Public Member Functions | |
static DAPCache3 * | get_instance () |
static DAPCache3 * | get_instance (const string &cache_dir, const string &prefix, unsigned long long size) |
Implementation of a caching mechanism for compressed data. This cache uses simple advisory locking found on most modern unix file systems. Compressed files are decompressed and stored in a cache where they can be used over and over until removed from the cache. Several processes can share the cache with each reading from files. At the same time, new files can be added and the cache can be purged, without disrupting the existing read operations.
How it works. When a file is added to the cache, the cache is locked - no other processes can add, read or remove files. Once a file has been added, the cache size is examined and, if needed, the cache is purged so that its size is 80% of the maximum size. Then the cache is unlocked. When a process looks to see if a file is already in the cache, the entire cache is locked. If the file is present, a shared read lock is obtained and the cache is unlocked.
Methods: create_and_lock() and get_read_lock() open and lock files; the former creates the file and locks it exclusively iff it does not exist, while the latter obtains a shared lock iff the file already exists. The unlock() methods unlock a file. The lock_cache_info() and unlock_cache_info() are used to control access to the whole cache - with the open + lock and close + unlock operations performed atomically. Other methods that operate on the cache info file must only be called when the lock has been obtained.
Definition at line 82 of file DAPCache3.h.
|
virtual |
look at the cache size; is it too large? Look at the cache size and see if it is too big.
Definition at line 735 of file DAPCache3.cc.
|
virtual |
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.
target | The name of the file to make/open/lock |
fd | Value-result param that holds the file descriptor of the opened file |
BESInternalError | if any error except EEXIST is returned by open(2) or if fcntl(2) returns an error. |
Definition at line 573 of file DAPCache3.cc.
|
virtual |
dumps information about this object
Displays the pointer value of this instance along with information about this cache.
strm | C++ i/o stream to dump the information to |
Definition at line 958 of file DAPCache3.cc.
|
pure virtualinherited |
dump the contents of this object to the specified ostream
This method is implemented by all derived classes to dump their contents, in other words, any state they might have, private variables, etc...
strm | C++ i/o stream to dump the object to |
Implemented in libdap::Array, libdap::AttrTable, libdap::BaseType, libdap::Byte, libdap::Constructor, libdap::D4Attribute, libdap::D4Attributes, libdap::D4Enum, libdap::D4Opaque, libdap::D4Sequence, libdap::D4StreamMarshaller, libdap::D4StreamUnMarshaller, libdap::DAS, libdap::DataDDS, libdap::DDS, libdap::DMR, libdap::Float32, libdap::Float64, libdap::Grid, libdap::Int16, libdap::Int32, libdap::Int64, libdap::Int8, libdap::Marshaller, libdap::Sequence, libdap::Str, libdap::Structure, libdap::UInt16, libdap::UInt32, libdap::UInt64, libdap::UnMarshaller, libdap::Vector, libdap::XDRFileMarshaller, libdap::XDRFileUnMarshaller, libdap::XDRStreamMarshaller, and libdap::XDRStreamUnMarshaller.
|
virtual |
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.
fd | The file descriptor that is exclusively locked and which, on exit, will have a shared lock. |
Definition at line 601 of file DAPCache3.cc.
Build the name of file that will holds the uncompressed data from 'src' in the cache.
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. |
Definition at line 506 of file DAPCache3.cc.
|
virtual |
Get the cache size. Read the size information from the cache info file and return it. This methods locks the cache.
Definition at line 746 of file DAPCache3.cc.
|
static |
Get an instance of the DAPCache3 object. This version is used when there's no question that the cache has been instantiated.
Definition at line 148 of file DAPCache3.cc.
|
static |
Get an instance of the DAPCache3 object. This class is a singleton, so the first call to any of three 'get_instance()' methods makes an instance and subsequent calls return a pointer to that instance.
cache_dir_key | Key to use to get the value of the cache directory |
prefix_key | Key for the item/file prefix. Each file added to the cache uses this as a prefix so cached items can be easily identified when /tmp is used for the cache. |
size_key | How big should the cache be, in megabytes |
Definition at line 135 of file DAPCache3.cc.
|
virtual |
Get a read-only lock on the file if it exists.
Try to get a read-only lock on the file, blocking until we can get it. If the file does not exist, return false.
src | src file that will be cached eventually |
target | a value-result parameter set to the resulting cached file |
Error | if the attempt to get the (shared) lock failed for any reason other than that the file does/did not exist. |
Definition at line 546 of file DAPCache3.cc.
|
virtual |
Get a shared lock on the 'cache info' file.
Definition at line 633 of file DAPCache3.cc.
|
virtual |
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.
Definition at line 622 of file DAPCache3.cc.
|
virtual |
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.
file | The name of the file to purge. |
Definition at line 911 of file DAPCache3.cc.
|
virtual |
|
virtual |
Unlock the file. This does not do any name mangling; it just unlocks whatever is named (or throws BESInternalError if the file cannot be closed).
fd | The descriptor of the file to unlock. |
BESInternalError |
Definition at line 677 of file DAPCache3.cc.
|
virtual |
Unlock the cache info file.
Definition at line 646 of file DAPCache3.cc.
|
virtual |
Purge files from the cache.
Purge files, oldest to newest, if the current size of the cache exceeds the size of the cache specified in the constructor. This method uses an exclusive lock on the cache for the duration of the purge process.
new_file | The name of a file this process just added to the cache. Using fcntl(2) locking there is no way this process can detect its own lock, so the shared read lock on the new file won't keep this process from deleting it (but will keep other processes from deleting it). |
Definition at line 821 of file DAPCache3.cc.
|
virtual |
Update the cache info file to include 'target'.
Add the size of the named file to the total cache size recorded in the cache info file. The cache info file is exclusively locked by this method for its duration. This updates the cache info file and returns the new size.
target | The name of the file |
Definition at line 695 of file DAPCache3.cc.