CernVM-FS
2.12.0
|
#include <kvstore.h>
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_ |
MallocHeap * | heap_ |
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 CallbackTN * | MakeClosure (typename BoundClosure< MallocHeap::BlockPtr, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, const ClosureDataT &closure_data) |
static CallbackTN * | MakeCallback (typename BoundCallback< MallocHeap::BlockPtr, DelegateT >::CallbackMethod method, DelegateT *delegate) |
static CallbackTN * | MakeCallback (typename Callback< MallocHeap::BlockPtr >::CallbackFunction function) |
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.
MemoryKvStore::MemoryKvStore | ( | unsigned int | cache_entries, |
MemoryAllocator | alloc, | ||
unsigned | alloc_size, | ||
perf::StatisticsTemplate | statistics | ||
) |
MemoryKvStore::~MemoryKvStore | ( | ) |
Definition at line 62 of file kvstore.cc.
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
buf | The memory buffer to insert |
Definition at line 263 of file kvstore.cc.
Referenced by RamCacheManager::CommitToKvStore().
|
private |
Definition at line 146 of file kvstore.cc.
Referenced by DoCommit().
bool MemoryKvStore::Contains | ( | const shash::Any & | id | ) |
Check for the existence of an entry
id | The hash key |
Definition at line 88 of file kvstore.cc.
Referenced by RamCacheManager::DoOpen().
bool MemoryKvStore::Delete | ( | const shash::Any & | id | ) |
Delete an entry, free()ing its memory. Note that the entry not have any references
id | The hash key |
Definition at line 321 of file kvstore.cc.
|
private |
Definition at line 269 of file kvstore.cc.
Referenced by Commit().
|
private |
Definition at line 328 of file kvstore.cc.
Referenced by Delete().
|
private |
Definition at line 128 of file kvstore.cc.
Referenced by DoCommit(), DoDelete(), and ShrinkTo().
|
private |
Definition at line 96 of file kvstore.cc.
Referenced by DoCommit().
int64_t MemoryKvStore::GetRefcount | ( | const shash::Any & | id | ) |
Get the number of references to the entry at id
id | The hash key |
-ENOENT | The entry is absent |
Definition at line 182 of file kvstore.cc.
int64_t MemoryKvStore::GetSize | ( | const shash::Any & | id | ) |
Get the size in bytes of the entry at id
id | The hash key |
-ENOENT | The entry is absent |
Definition at line 166 of file kvstore.cc.
Referenced by RamCacheManager::GetSize().
|
inline |
Get the total space used for data
Definition at line 200 of file kvstore.h.
Referenced by RamCacheManager::CommitToKvStore().
bool MemoryKvStore::IncRef | ( | const shash::Any & | id | ) |
Increase the reference count on the entry at id
id | The hash key |
Definition at line 198 of file kvstore.cc.
Referenced by RamCacheManager::DoOpen(), and RamCacheManager::Dup().
|
private |
Definition at line 68 of file kvstore.cc.
Referenced by MemoryKvStore().
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)
id | The hash key |
buf | The address at which to write the data |
size | The number of bytes to copy |
offset | The offset within the entry to start the copy |
-ENOENT | The entry is absent |
Definition at line 236 of file kvstore.cc.
Referenced by RamCacheManager::Pread().
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.
size | The maximum size to make the KvStore |
Definition at line 352 of file kvstore.cc.
Referenced by RamCacheManager::CommitToKvStore().
bool MemoryKvStore::Unref | ( | const shash::Any & | id | ) |
Decrease the reference count on the entry at id. If the refcount is zero, no effect
id | The hash key |
Definition at line 217 of file kvstore.cc.
Referenced by RamCacheManager::Close().
|
private |
Definition at line 213 of file kvstore.h.
Referenced by CompactMemory(), DoFree(), and DoMalloc().
|
private |
Definition at line 220 of file kvstore.h.
Referenced by Delete(), DoCommit(), DoDelete(), GetRefcount(), GetSize(), IncRef(), Read(), ShrinkTo(), and Unref().
|
private |
Definition at line 217 of file kvstore.h.
Referenced by Contains(), DoCommit(), DoDelete(), GetRefcount(), GetSize(), IncRef(), OnBlockMove(), Read(), ShrinkTo(), and Unref().
|
private |
Definition at line 215 of file kvstore.h.
Referenced by DoCommit(), DoDelete(), and ShrinkTo().
|
private |
Definition at line 218 of file kvstore.h.
Referenced by CompactMemory(), DoFree(), DoMalloc(), MemoryKvStore(), and ~MemoryKvStore().
|
staticprivate |
Definition at line 204 of file kvstore.h.
Referenced by CompactMemory().
|
private |
Definition at line 216 of file kvstore.h.
Referenced by DoCommit().
|
private |
Definition at line 219 of file kvstore.h.
Referenced by Commit(), Delete(), IncRef(), MemoryKvStore(), Read(), ShrinkTo(), Unref(), and ~MemoryKvStore().
|
private |
Definition at line 214 of file kvstore.h.
Referenced by DoCommit(), DoDelete(), and ShrinkTo().