#include <Space.h>
Public Types | |
typedef __gnu_cxx::hash_map < LightString, HashTabElement > | SpaceHashTab |
Type of the hash-table. | |
typedef std::vector< SpaceHashTab > | SpaceHashTabs |
Type of the structure that holds every sub-hash-table. | |
typedef std::list< LRUListElement > | SpaceLRUList |
Type of space's LRU List. | |
typedef std::vector< SpaceLRUList > | SpaceLRULists |
Type of vector of space's LRU Lists. | |
typedef std::vector < pthread_rwlock_t * > | Mutexes |
Type of structure holding hash-table mutexes. | |
typedef std::map< int, char > | Indexes |
Type of structure that maps ints to chars (for convieniency). | |
Public Member Functions | |
Space (const std::string &name, unsigned long long softQuota, unsigned long long hardQuota, Cache *memcache, User *user) | |
Constructs the Space. | |
Value | get (const LightString &key, unsigned timeout=0) |
Retrieves the value of the cached chunk assigned to the given key. | |
bool | get (const LightString &key, Value &value, unsigned timeout=0) |
Retrieves the value of the cached chunk assigned to the given key. | |
SpaceResult | set (const LightString &key, const Value &value, unsigned timeout, uint64_t *new_cas_id=NULL) |
Assigns the given value to the given key, sets the expiry time and marks the value with the next available cas_id. | |
SpaceResult | cas (const LightString &key, const Value &value, unsigned timeout, uint64_t cas_id, uint64_t *new_cas_id=NULL) |
Similar to set but this method checks whether current cas_id is equal to the one passed as parameter and sets the new value if and only if they match. | |
SpaceResult | add (const LightString &key, const Value &value, unsigned timeout, uint64_t cas_id=0, uint64_t *new_cas_id=NULL) |
Similar to set, but sets only if there's no such key. | |
SpaceResult | replace (const LightString &key, const Value &value, unsigned timeout, uint64_t cas_id=0, uint64_t *new_cas_id=NULL) |
Similar to set, but sets only if the key already exists in the space. | |
SpaceResult | append (const LightString &key, const Value &value, uint64_t *new_cas_id=NULL) |
Appends the give value to the value assigned that is already assigned to given key. | |
SpaceResult | prepend (const LightString &key, const Value &value, uint64_t *new_cas_id=NULL) |
Prepends the give value to the value assigned that is already assigned to given key. | |
SpaceResult | increment (const LightString &key, uint64_t step, uint64_t *out, unsigned timeout=0, bool force=0, uint64_t initial=0) |
Increments integer value that was previously stored. | |
SpaceResult | decrement (const LightString &key, uint64_t step, uint64_t *out, unsigned timeout=0, bool force=0, uint64_t initial=0) |
Decrements integer value that was previously stored. | |
bool | saveSpace (const char *fileName, unsigned minTimeout=0) |
Dumps the space to a file. | |
void | cleanSpace () |
Cleans the space. | |
void | destroySpace () |
Destroys the space. | |
Stats | getStats () |
Retrieves space stats. | |
void | clearStats () |
Clears all the statistics e.g. | |
void | setStatus (unsigned nUsedQuota, unsigned nGetsCount, unsigned nSetsCount, unsigned nBytesWritten, unsigned nBytesRead, unsigned nMissCount, unsigned nHitCount, unsigned long long nItemsCount) |
Used while loading space from disk to restore saved status and stats. | |
std::string | getStatsStr () |
Generates a textual description of the current space state. | |
Public Attributes | |
Mutexes | mapMutexes |
Dispersed hash-table mutexes. | |
pthread_mutex_t | globalMutex |
Mutex to guard access to space stats and LRUList. | |
std::string | name |
Textual name of the space. | |
Stats | stats |
Space's statistical data. | |
Stats * | fragmentedStats |
Space's statistical data (dispersed into many sub-stats to boost GET requests). | |
SpaceHashTabs | hashTab |
sub-spaces' hash tables | |
SpaceLRULists | LRUList |
sub-spaces' LRU lists | |
Static Public Attributes | |
static unsigned int | NUMERIC_OBJECT_SIZE = UINT_MAX / 2 |
If a numeric value is stored it has size of NUMERIC_OBJECT_SIZE. | |
static unsigned int | INCR_MAX_STORAGE_LEN = 24 |
Maximal digit count in a numeric value. | |
static const int | MUTEXES_COUNT = 32 |
Space is dispersed to MUTEXES_COUNT sub-spaces. | |
Classes | |
class | HashTabElement |
Auxiliary class for keeping elements in the hash table, containing information about the cached value and iterator to LRUList. More... | |
class | LRUListElement |
Auxiliary class for keeping elements in the LRUList, containing the key to hash table and expiry time of the cached value. More... |
It manages the mapping textual keys to the binary values that can be stored and loaded by user.
Definition at line 245 of file Space.h.
Space::Space | ( | const std::string & | name, | |
unsigned long long | softQuota, | |||
unsigned long long | hardQuota, | |||
Cache * | memcache, | |||
User * | user | |||
) |
Value Space::get | ( | const LightString & | key, | |
unsigned | timeout = 0 | |||
) |
Retrieves the value of the cached chunk assigned to the given key.
Optionally modifies the expiry time.
key | key of which value will be retrieved | |
timeout | interval in seconds of the time of life of the value or 0 to leave it unmodified |
bool Space::get | ( | const LightString & | key, | |
Value & | value, | |||
unsigned | timeout = 0 | |||
) |
Retrieves the value of the cached chunk assigned to the given key.
Optionally modifies the expiry time.
if value.memoryPointer is NULL a chunk of memory of exact size as the value in cache will be malloced. if value.memoryPointer is not NULL value.size will be checked whether the value from cache would fit the memory pointed by memoryPointer. If value.size is smaller then size of the one in cache this method does nothind and returns false.
key | key of which value will be retrieved | |
value | value reference to which new data will be copied | |
timeout | interval in seconds of the time of life of the value or 0 to leave it unmodified |
SpaceResult Space::set | ( | const LightString & | key, | |
const Value & | value, | |||
unsigned | timeout, | |||
uint64_t * | new_cas_id = NULL | |||
) |
Assigns the given value to the given key, sets the expiry time and marks the value with the next available cas_id.
NOTE: cas_id member of value parameter is ignored by this method.
key | key at which the value will be stored | |
value | cached value | |
timeout | interval in seconds of the time of life of the value | |
new_cas_id | pointer to where the new cas_id will be stored if not NULL |
SpaceResult Space::cas | ( | const LightString & | key, | |
const Value & | value, | |||
unsigned | timeout, | |||
uint64_t | cas_id, | |||
uint64_t * | new_cas_id = NULL | |||
) |
Similar to set but this method checks whether current cas_id is equal to the one passed as parameter and sets the new value if and only if they match.
cas_id of a value can be obtained by get().
NOTE: cas_id member of value parameter is ignored by this method.
key | key at which the value will be stored | |
value | cached value | |
timeout | interval in seconds of the time of life of the value | |
cas_id | id that has to be equal to the value's current one | |
new_cas_id | pointer to where the new cas_id will be stored if not NULL |
SpaceResult Space::add | ( | const LightString & | key, | |
const Value & | value, | |||
unsigned | timeout, | |||
uint64_t | cas_id = 0 , |
|||
uint64_t * | new_cas_id = NULL | |||
) |
Similar to set, but sets only if there's no such key.
key | key at which the value will be stored | |
value | cached value | |
timeout | interval in seconds of the time of life of the value | |
cas_id | if it's > 0 then overwritten cas_id will be matched and nothing will be done if match fails | |
new_cas_id | pointer to where the new cas_id will be stored if not NULL |
SpaceResult Space::replace | ( | const LightString & | key, | |
const Value & | value, | |||
unsigned | timeout, | |||
uint64_t | cas_id = 0 , |
|||
uint64_t * | new_cas_id = NULL | |||
) |
Similar to set, but sets only if the key already exists in the space.
key | key at which the value will be stored | |
value | cached value | |
timeout | interval in seconds of the time of life of the value | |
cas_id | if it's > 0 then overwritten cas_id will be matched and nothing will be done if match fails | |
new_cas_id | pointer to where the new cas_id will be stored if not NULL |
SpaceResult Space::append | ( | const LightString & | key, | |
const Value & | value, | |||
uint64_t * | new_cas_id = NULL | |||
) |
Appends the give value to the value assigned that is already assigned to given key.
key | key at which the value will appended | |
value | appended value | |
new_cas_id | pointer to where the new cas_id will be stored if not NULL |
SpaceResult Space::prepend | ( | const LightString & | key, | |
const Value & | value, | |||
uint64_t * | new_cas_id = NULL | |||
) |
Prepends the give value to the value assigned that is already assigned to given key.
key | key at which the value will prepended | |
value | prepended value | |
new_cas_id | pointer to where the new cas_id will be stored if not NULL |
SpaceResult Space::increment | ( | const LightString & | key, | |
uint64_t | step, | |||
uint64_t * | out, | |||
unsigned | timeout = 0 , |
|||
bool | force = 0 , |
|||
uint64_t | initial = 0 | |||
) |
Increments integer value that was previously stored.
You have to provide that the value was initialized using setNumeric otherwise the result is undetermined.
key | key at which the value is stored | |
step | the value will be equal to current_value+step | |
out | pointer to where the new value will be stored | |
timeout | interval in seconds of the time of life of the value or 0 to leave it unmodified | |
force | force to store the initial value in case it doesn't exist yet | |
initial | the initial value; ignored if force is false |
SpaceResult Space::decrement | ( | const LightString & | key, | |
uint64_t | step, | |||
uint64_t * | out, | |||
unsigned | timeout = 0 , |
|||
bool | force = 0 , |
|||
uint64_t | initial = 0 | |||
) |
Decrements integer value that was previously stored.
You have to provide that the value was initialized using setNumeric otherwise the result is undetermined.
key | key at which the value is stored | |
step | the value will be equal to current_value-step | |
out | pointer to where the new value will be stored | |
timeout | interval in seconds of the time of life of the value or 0 to leave it unmodified | |
force | force to store the initial value in case it doesn't exist yet | |
initial | the initial value; ignored if force is false |
bool Space::saveSpace | ( | const char * | fileName, | |
unsigned | minTimeout = 0 | |||
) |
Dumps the space to a file.
It dumps only these values which timeout is equal or greater than given timout.
fileName | the name of the file in which the space will be saved | |
minTimeout | the minimal timeout for filtering out values which timeout is less than it |
Stats Space::getStats | ( | ) |
void Space::clearStats | ( | ) |
Clears all the statistics e.g.
sets them to zero. These are: bytesRead bytesWritten getsCount setsCount hitCount missCount
std::string Space::getStatsStr | ( | ) | [inline] |