11 #include <gtest/gtest_prod.h>
33 #ifndef CVMFS_GLUE_BUFFER_H_
34 #define CVMFS_GLUE_BUFFER_H_
40 return (uint32_t) *(
reinterpret_cast<const uint32_t *
>(key.
digest) + 1);
45 return MurmurHash2(&inode,
sizeof(inode), 0x07387a4f);
64 return sizeof(uint16_t) + length;
66 char *
data()
const {
return reinterpret_cast<char *
>(
length_ + 1); }
71 result.
length_ =
reinterpret_cast<uint16_t *
>(addr);
74 memcpy(result.
length_ + 1, str, length);
100 void Init(
const uint64_t minimum_size) {
105 uint64_t pow2_size = 128 * 1024;
106 while (pow2_size < minimum_size)
112 for (
unsigned i = 0; i <
bins_.
size(); ++i) {
121 if (remaining_bin_size < str_size) {
122 size_ += remaining_bin_size;
130 bin_used_ += str_size;
139 if (
size_ == 0)
return 1.0;
140 return static_cast<double>(
used_) / static_cast<double>(
size_);
149 for (
unsigned i = 0; i <
bins_.
size(); ++i) {
158 void *bin = smmap(size);
200 bool found =
map_.Lookup(md5path, &info);
203 map_.Insert(md5path, info);
210 map_.Insert(md5path, new_entry);
222 map_.Insert(md5path, new_entry);
227 bool retval =
map_.Lookup(md5path, &info);
243 bool found =
map_.Lookup(md5path, &info);
254 for (
unsigned i = 0; i <
map_.capacity(); ++i) {
255 if (
map_.keys()[i] != empty_path) {
256 (
map_.values() + i)->name =
258 map_.values()[i].name.data());
266 map_.Insert(md5path, info);
282 while (cursor->
idx <
map_.capacity()) {
283 if (
map_.keys()[cursor->
idx] == empty_key) {
287 *parent =
map_.values()[cursor->
idx].parent;
288 *name =
map_.values()[cursor->
idx].name;
330 if (found)
return inode;
337 if (found)
return inode;
418 bool Get(
const uint64_t inode,
const uint32_t by) {
419 uint32_t refcounter = 0;
420 const bool found =
map_.
Lookup(inode, &refcounter);
421 const bool new_inode = !found;
427 bool Put(
const uint64_t inode,
const uint32_t by) {
432 if (refcounter == by) {
503 bool VfsPut(
const uint64_t inode,
const uint32_t by) {
610 &(cursor->
csr_paths), &parent_md5, &name_ref);
635 int retval = pthread_mutex_lock(
lock_);
639 int retval = pthread_mutex_unlock(
lock_);
661 Entry(uint64_t e, uint64_t p,
const char *n)
700 void Add(
const uint64_t inode_parent,
const char *name, uint64_t timeout_s) {
702 if (timeout_s == 0)
return;
706 entries_.PushBack(
Entry(now + timeout_s, inode_parent, name));
733 int retval = pthread_mutex_lock(
lock_);
737 int retval = pthread_mutex_unlock(
lock_);
828 void Evict(uint64_t inode);
863 void Close(uint64_t inode);
892 #endif // CVMFS_GLUE_BUFFER_H_
BigVector< void * > bins_
VfsPutRaii GetVfsPutRaii()
Entry(int32_t n, const shash::Any &h)
OpenDirectives(bool k, bool d)
InodeReferences inode_references_
InodeReferences::Cursor csr_inos
atomic_int64 num_hits_inode
static uint32_t hasher_md5(const shash::Md5 &key)
Cursor(const PathStore::Cursor &p, const InodeReferences::Cursor &i)
Item At(const size_t index) const
void SpawnCleaner(unsigned interval_s)
atomic_int64 num_misses_path
static const unsigned kVersion
Statistics GetStatistics()
void EndEnumerate(Cursor *cursor)
bool NextEntry(Cursor *cursor, uint64_t *inode_parent, NameString *name)
PageCacheTracker & operator=(const PageCacheTracker &other)
void Assign(const char *chars, const unsigned length)
PathStore::Cursor csr_paths
BigQueue< Entry > entries_
bool Put(const uint64_t inode, const uint32_t by)
static uint16_t size(const uint16_t length)
FRIEND_TEST(T_GlueBuffer, NentryTracker)
assert((mem||(size==0))&&"Out Of Memory")
SmallHashDynamic< uint64_t, uint32_t > map_
std::string GetParentPath(const std::string &path)
StringHeap * string_heap_
void EndEnumerate(Cursor *cursor)
Statistics GetStatistics()
bool VfsPut(const uint64_t inode, const uint32_t by)
uint64_t LookupInodeByMd5Path(const shash::Md5 &md5path)
unsigned char digest[digest_size_]
uint64_t LookupInodeByPath(const PathString &path)
OpenDirectives Open(uint64_t inode, const shash::Any &hash)
void Insert(const shash::Md5 &md5path, const PathString &path)
shash::Md5 Insert(const PathString &path, const uint64_t inode)
static uint32_t hasher_inode(const uint64_t &inode)
void CopyFrom(const NentryTracker &other)
bool Next(Cursor *cursor, shash::Md5 *parent, StringRef *name)
uint64_t GetSizeAlloc() const
bool LookupMd5Path(const uint64_t inode, shash::Md5 *md5path)
void CopyFrom(const InodeTracker &other)
uint64_t FindInode(const PathString &path)
SmallHashDynamic< uint64_t, shash::Md5 > map_
InodeTracker & operator=(const InodeTracker &other)
uint32_t capacity() const
Statistics GetStatistics()
void VfsGetBy(const uint64_t inode, const uint32_t by, const PathString &path)
bool NextEntry(Cursor *cursor, uint64_t *inode_parent, NameString *name)
StringHeap(const uint64_t minimum_size)
bool NextInode(Cursor *cursor, uint64_t *inode)
static StringRef Place(const uint16_t length, const char *str, void *addr)
pthread_t thread_cleaner_
bool Lookup(const shash::Md5 &md5path, PathString *path)
void Insert(const Key &key, const Value &value)
bool Next(Cursor *cursor, uint64_t *inode)
static const unsigned kVersion
void Append(const char *chars, const unsigned length)
string StringifyInt(const int64_t value)
int cleaning_interval_ms_
static const unsigned kVersion
SmallHashDynamic< shash::Md5, PathInfo > map_
void Erase(const uint64_t inode)
atomic_int64 num_references
Entry(uint64_t e, uint64_t p, const char *n)
SmallHashDynamic< shash::Md5, uint64_t > map_
bool Contains(const Key &key) const
PathStore & operator=(const PathStore &other)
void Add(const uint64_t inode_parent, const char *name, uint64_t timeout_s)
bool FindPath(const uint64_t inode, PathString *path)
void PushBack(const Item &item)
void Evict(uint64_t inode)
void Close(uint64_t inode)
OpenDirectives OpenDirect()
EvictRaii(PageCacheTracker *t)
void RemoveString(const StringRef str_ref)
void Erase(const shash::Md5 &md5path)
void CopyFrom(const PathStore &other)
PageCacheTracker * tracker_
bool Erase(const Key &key)
bool LookupPath(const shash::Md5 &md5path, PathString *path)
void CopyFrom(const PageCacheTracker &other)
void Erase(const shash::Md5 &md5path)
void Insert(const uint64_t inode, const shash::Md5 &md5path)
void VfsGet(const uint64_t inode, const PathString &path)
unsigned GetLength() const
atomic_int64 num_hits_path
bool Lookup(const Key &key, Value *value) const
void Init(uint32_t expected_size, Key empty, uint32_t(*hasher)(const Key &key))
NentryTracker & operator=(const NentryTracker &other)
static const unsigned int kBitDirectIo
const char * GetChars() const
void Init(const uint64_t minimum_size)
void AddBin(const uint64_t size)
bool Get(const uint64_t inode, const uint32_t by)
StringRef AddString(const uint16_t length, const char *str)
static void * MainCleaner(void *data)
SmallHashDynamic< uint64_t, Entry > map_
uint32_t MurmurHash2(const void *key, int len, uint32_t seed)
void DoPrune(uint64_t now)
VfsPutRaii(InodeTracker *t)