CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MemoryKvStore Class Reference

#include <kvstore.h>

Inheritance diagram for MemoryKvStore:
Collaboration diagram for MemoryKvStore:

Classes

struct  Counters
 

Public Types

enum  MemoryAllocator { kMallocLibc, kMallocHeap }
 
- Public Types inherited from Callbackable< MallocHeap::BlockPtr >
typedef CallbackBase
< MallocHeap::BlockPtr
CallbackTN
 

Public Member Functions

 MemoryKvStore (unsigned int cache_entries, MemoryAllocator alloc, unsigned alloc_size, perf::StatisticsTemplate statistics)
 
 ~MemoryKvStore ()
 
bool Contains (const shash::Any &id)
 
int64_t GetSize (const shash::Any &id)
 
int64_t GetRefcount (const shash::Any &id)
 
bool IncRef (const shash::Any &id)
 
bool Unref (const shash::Any &id)
 
int64_t Read (const shash::Any &id, void *buf, size_t size, size_t offset)
 
int Commit (const MemoryBuffer &buf)
 
bool Delete (const shash::Any &id)
 
bool ShrinkTo (size_t size)
 
size_t GetUsed ()
 

Private Member Functions

bool DoDelete (const shash::Any &id)
 
int DoMalloc (MemoryBuffer *buf)
 
void DoFree (MemoryBuffer *buf)
 
int DoCommit (const MemoryBuffer &buf)
 
void OnBlockMove (const MallocHeap::BlockPtr &ptr)
 
bool CompactMemory ()
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Private Attributes

MemoryAllocator allocator_
 
size_t used_bytes_
 
unsigned int entry_count_
 
unsigned int max_entries_
 
lru::LruCache< shash::Any,
MemoryBuffer
entries_
 
MallocHeapheap_
 
pthread_rwlock_t rwlock_
 
Counters counters_
 

Static Private Attributes

static const double kCompactThreshold = 0.8
 

Additional Inherited Members

- Static Public Member Functions inherited from Callbackable< MallocHeap::BlockPtr >
static CallbackTNMakeClosure (typename BoundClosure< MallocHeap::BlockPtr, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, const ClosureDataT &closure_data)
 
static CallbackTNMakeCallback (typename BoundCallback< MallocHeap::BlockPtr, DelegateT >::CallbackMethod method, DelegateT *delegate)
 
static CallbackTNMakeCallback (typename Callback< MallocHeap::BlockPtr >::CallbackFunction function)
 

Detailed Description

MemoryKvStore provides a simple RAM-backed key/value store suited to use with RamCacheManager. To insert entries, the caller must allocate some memory and can choose to set some metadata such as object type. MemoryKvStore takes ownership of the passed-in memory and maintains reference counts for all its objects. Callers must increment the reference count on an entry before reading to ensure that the entry is not removed mid-operation, and decrement the reference count when done. The store can attempt to reduce its size by removing the least recently used entries without any outstanding references.

Definition at line 66 of file kvstore.h.

Member Enumeration Documentation

Enumerator
kMallocLibc 
kMallocHeap 

Definition at line 68 of file kvstore.h.

Constructor & Destructor Documentation

MemoryKvStore::MemoryKvStore ( unsigned int  cache_entries,
MemoryAllocator  alloc,
unsigned  alloc_size,
perf::StatisticsTemplate  statistics 
)

Definition at line 35 of file kvstore.cc.

Here is the call graph for this function:

MemoryKvStore::~MemoryKvStore ( )

Definition at line 62 of file kvstore.cc.

Member Function Documentation

int MemoryKvStore::Commit ( const MemoryBuffer buf)

Insert a new memory buffer. The KvStore copies the referred memory, so callers may free() their buffers after Commit returns

Parameters
bufThe memory buffer to insert
Returns
-ENFILE if too many file handles are in use
-EIO if memory allocation fails

Definition at line 263 of file kvstore.cc.

Referenced by RamCacheManager::CommitToKvStore().

Here is the call graph for this function:

Here is the caller graph for this function:

bool MemoryKvStore::CompactMemory ( )
private

Definition at line 146 of file kvstore.cc.

Referenced by DoCommit().

Here is the call graph for this function:

Here is the caller graph for this function:

bool MemoryKvStore::Contains ( const shash::Any id)

Check for the existence of an entry

Parameters
idThe hash key
Returns
True iff the entry exists

Definition at line 88 of file kvstore.cc.

Referenced by RamCacheManager::DoOpen().

Here is the call graph for this function:

Here is the caller graph for this function:

bool MemoryKvStore::Delete ( const shash::Any id)

Delete an entry, free()ing its memory. Note that the entry not have any references

Parameters
idThe hash key
Returns
True iff the entry was successfully deleted

Definition at line 321 of file kvstore.cc.

Here is the call graph for this function:

int MemoryKvStore::DoCommit ( const MemoryBuffer buf)
private

Definition at line 269 of file kvstore.cc.

Referenced by Commit().

Here is the call graph for this function:

Here is the caller graph for this function:

bool MemoryKvStore::DoDelete ( const shash::Any id)
private

Definition at line 328 of file kvstore.cc.

Referenced by Delete().

Here is the call graph for this function:

Here is the caller graph for this function:

void MemoryKvStore::DoFree ( MemoryBuffer buf)
private

Definition at line 128 of file kvstore.cc.

Referenced by DoCommit(), DoDelete(), and ShrinkTo().

Here is the call graph for this function:

Here is the caller graph for this function:

int MemoryKvStore::DoMalloc ( MemoryBuffer buf)
private

Definition at line 96 of file kvstore.cc.

Referenced by DoCommit().

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t MemoryKvStore::GetRefcount ( const shash::Any id)

Get the number of references to the entry at id

Parameters
idThe hash key
Returns
A reference count
Return values
-ENOENTThe entry is absent

Definition at line 182 of file kvstore.cc.

Here is the call graph for this function:

int64_t MemoryKvStore::GetSize ( const shash::Any id)

Get the size in bytes of the entry at id

Parameters
idThe hash key
Returns
The entry's size
Return values
-ENOENTThe entry is absent

Definition at line 166 of file kvstore.cc.

Referenced by RamCacheManager::GetSize().

Here is the call graph for this function:

Here is the caller graph for this function:

size_t MemoryKvStore::GetUsed ( )
inline

Get the total space used for data

Definition at line 200 of file kvstore.h.

Referenced by RamCacheManager::CommitToKvStore().

Here is the caller graph for this function:

bool MemoryKvStore::IncRef ( const shash::Any id)

Increase the reference count on the entry at id

Parameters
idThe hash key
Returns
True if the entry exists and was updated

Definition at line 198 of file kvstore.cc.

Referenced by RamCacheManager::DoOpen(), and RamCacheManager::Dup().

Here is the call graph for this function:

Here is the caller graph for this function:

void MemoryKvStore::OnBlockMove ( const MallocHeap::BlockPtr ptr)
private

Definition at line 68 of file kvstore.cc.

Referenced by MemoryKvStore().

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t MemoryKvStore::Read ( const shash::Any id,
void *  buf,
size_t  size,
size_t  offset 
)

Copy a portion of the entry at id to the given address. See pread(2)

Parameters
idThe hash key
bufThe address at which to write the data
sizeThe number of bytes to copy
offsetThe offset within the entry to start the copy
Returns
The number of bytes copied
Return values
-ENOENTThe entry is absent

Definition at line 236 of file kvstore.cc.

Referenced by RamCacheManager::Pread().

Here is the call graph for this function:

Here is the caller graph for this function:

bool MemoryKvStore::ShrinkTo ( size_t  size)

Delete the oldest entries until the KvStore uses less than the given size. Entries with nonzero refcount will not be deleted.

Parameters
sizeThe maximum size to make the KvStore
Returns
True iff the shrink succeeds

Definition at line 352 of file kvstore.cc.

Referenced by RamCacheManager::CommitToKvStore().

Here is the call graph for this function:

Here is the caller graph for this function:

bool MemoryKvStore::Unref ( const shash::Any id)

Decrease the reference count on the entry at id. If the refcount is zero, no effect

Parameters
idThe hash key
Returns
True if the entry exists and was updated

Definition at line 217 of file kvstore.cc.

Referenced by RamCacheManager::Close().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

MemoryAllocator MemoryKvStore::allocator_
private

Definition at line 213 of file kvstore.h.

Referenced by CompactMemory(), DoFree(), and DoMalloc().

Counters MemoryKvStore::counters_
private

Definition at line 220 of file kvstore.h.

Referenced by Delete(), DoCommit(), DoDelete(), GetRefcount(), GetSize(), IncRef(), Read(), ShrinkTo(), and Unref().

lru::LruCache<shash::Any, MemoryBuffer> MemoryKvStore::entries_
private
unsigned int MemoryKvStore::entry_count_
private

Definition at line 215 of file kvstore.h.

Referenced by DoCommit(), DoDelete(), and ShrinkTo().

MallocHeap* MemoryKvStore::heap_
private

Definition at line 218 of file kvstore.h.

Referenced by CompactMemory(), DoFree(), DoMalloc(), MemoryKvStore(), and ~MemoryKvStore().

const double MemoryKvStore::kCompactThreshold = 0.8
staticprivate

Definition at line 204 of file kvstore.h.

Referenced by CompactMemory().

unsigned int MemoryKvStore::max_entries_
private

Definition at line 216 of file kvstore.h.

Referenced by DoCommit().

pthread_rwlock_t MemoryKvStore::rwlock_
private

Definition at line 219 of file kvstore.h.

Referenced by Commit(), Delete(), IncRef(), MemoryKvStore(), Read(), ShrinkTo(), Unref(), and ~MemoryKvStore().

size_t MemoryKvStore::used_bytes_
private

Definition at line 214 of file kvstore.h.

Referenced by DoCommit(), DoDelete(), and ShrinkTo().


The documentation for this class was generated from the following files: