CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lru_md.h
Go to the documentation of this file.
1 
7 #ifndef CVMFS_LRU_MD_H_
8 #define CVMFS_LRU_MD_H_
9 
10 #ifndef __STDC_FORMAT_MACROS
11 #define __STDC_FORMAT_MACROS
12 #endif
13 
14 #include <stdint.h>
15 
16 #include "crypto/hash.h"
17 #include "directory_entry.h"
18 #include "duplex_fuse.h"
19 #include "lru.h"
20 #include "shortstring.h"
21 #include "util/atomic.h"
22 #include "util/logging.h"
23 #include "util/murmur.hxx"
24 
25 
26 namespace lru {
27 
28 // Hash functions
29 static inline uint32_t hasher_md5(const shash::Md5 &key) {
30  // Don't start with the first bytes, because == is using them as well
31  return (uint32_t) *(reinterpret_cast<const uint32_t *>(key.digest) + 1);
32 }
33 
34 static inline uint32_t hasher_inode(const fuse_ino_t &inode) {
35  return MurmurHash2(&inode, sizeof(inode), 0x07387a4f);
36 }
37 // uint32_t hasher_md5(const shash::Md5 &key);
38 // uint32_t hasher_inode(const fuse_ino_t &inode);
39 
40 
41 class InodeCache : public LruCache<fuse_ino_t, catalog::DirectoryEntry>
42 {
43  public:
44  explicit InodeCache(unsigned int cache_size, perf::Statistics *statistics) :
45  LruCache<fuse_ino_t, catalog::DirectoryEntry>(
46  cache_size, fuse_ino_t(-1), hasher_inode,
47  perf::StatisticsTemplate("inode_cache", statistics))
48  {
49  }
50 
51  bool Insert(const fuse_ino_t &inode, const catalog::DirectoryEntry &dirent) {
52  LogCvmfs(kLogLru, kLogDebug, "insert inode --> dirent: %lu -> '%s'",
53  inode, dirent.name().c_str());
54  const bool result =
56  return result;
57  }
58 
59  bool Lookup(const fuse_ino_t &inode, catalog::DirectoryEntry *dirent,
60  bool update_lru = true)
61  {
62  const bool result =
64  LogCvmfs(kLogLru, kLogDebug, "lookup inode --> dirent: %lu (%s)",
65  inode, result ? "hit" : "miss");
66  return result;
67  }
68 
69  void Drop() {
70  LogCvmfs(kLogLru, kLogDebug, "dropping inode cache");
72  }
73 }; // InodeCache
74 
75 
76 class PathCache : public LruCache<fuse_ino_t, PathString> {
77  public:
78  explicit PathCache(unsigned int cache_size, perf::Statistics *statistics) :
79  LruCache<fuse_ino_t, PathString>(cache_size, fuse_ino_t(-1), hasher_inode,
80  perf::StatisticsTemplate("path_cache", statistics))
81  {
82  }
83 
84  bool Insert(const fuse_ino_t &inode, const PathString &path) {
85  LogCvmfs(kLogLru, kLogDebug, "insert inode --> path %lu -> '%s'",
86  inode, path.c_str());
87  const bool result =
89  return result;
90  }
91 
92  bool Lookup(const fuse_ino_t &inode, PathString *path,
93  bool update_lru = true)
94  {
95  const bool found =
97  LogCvmfs(kLogLru, kLogDebug, "lookup inode --> path: %lu (%s)",
98  inode, found ? "hit" : "miss");
99  return found;
100  }
101 
102  void Drop() {
103  LogCvmfs(kLogLru, kLogDebug, "dropping path cache");
105  }
106 }; // PathCache
107 
108 
110  public LruCache<shash::Md5, catalog::DirectoryEntry>
111 {
112  public:
113  explicit Md5PathCache(unsigned int cache_size, perf::Statistics *statistics) :
114  LruCache<shash::Md5, catalog::DirectoryEntry>(
115  cache_size, shash::Md5(shash::AsciiPtr("!")), hasher_md5,
116  perf::StatisticsTemplate("md5_path_cache", statistics))
117  {
119  }
120 
121  bool Insert(const shash::Md5 &hash, const catalog::DirectoryEntry &dirent) {
122  LogCvmfs(kLogLru, kLogDebug, "insert md5 --> dirent: %s -> '%s'",
123  hash.ToString().c_str(), dirent.name().c_str());
124  const bool result =
126  return result;
127  }
128 
129  bool InsertNegative(const shash::Md5 &hash) {
130  const bool result = Insert(hash, dirent_negative_);
131  if (result)
133  return result;
134  }
135 
136  bool Lookup(const shash::Md5 &hash, catalog::DirectoryEntry *dirent,
137  bool update_lru = true)
138  {
139  const bool result =
141  LogCvmfs(kLogLru, kLogDebug, "lookup md5 --> dirent: %s (%s)",
142  hash.ToString().c_str(), result ? "hit" : "miss");
143  return result;
144  }
145 
146  bool Forget(const shash::Md5 &hash) {
147  LogCvmfs(kLogLru, kLogDebug, "forget md5: %s",
148  hash.ToString().c_str());
150  }
151 
152  void Drop() {
153  LogCvmfs(kLogLru, kLogDebug, "dropping md5path cache");
155  }
156 
157  private:
159 }; // Md5PathCache
160 
161 } // namespace lru
162 
163 #endif // CVMFS_LRU_MD_H_
bool InsertNegative(const shash::Md5 &hash)
Definition: lru_md.h:129
bool Forget(const shash::Md5 &hash)
Definition: lru_md.h:146
bool Insert(const fuse_ino_t &inode, const catalog::DirectoryEntry &dirent)
Definition: lru_md.h:51
std::string ToString(const bool with_suffix=false) const
Definition: hash.h:249
virtual bool Insert(const Key &key, const Value &value)
Definition: lru.h:556
bool Lookup(const shash::Md5 &hash, catalog::DirectoryEntry *dirent, bool update_lru=true)
Definition: lru_md.h:136
bool Lookup(const fuse_ino_t &inode, catalog::DirectoryEntry *dirent, bool update_lru=true)
Definition: lru_md.h:59
static uint32_t hasher_md5(const shash::Md5 &key)
Definition: lru_md.h:29
unsigned char digest[digest_size_]
Definition: hash.h:124
bool Lookup(const fuse_ino_t &inode, PathString *path, bool update_lru=true)
Definition: lru_md.h:92
NameString name() const
perf::Counter * n_insert_negative
Definition: lru.h:68
catalog::DirectoryEntry dirent_negative_
Definition: lru_md.h:158
void Drop()
Definition: lru_md.h:69
void Inc(class Counter *counter)
Definition: statistics.h:50
void Drop()
Definition: lru_md.h:102
static uint32_t hasher_inode(const fuse_ino_t &inode)
Definition: lru_md.h:34
Md5PathCache(unsigned int cache_size, perf::Statistics *statistics)
Definition: lru_md.h:113
virtual bool Lookup(const Key &key, Value *value, bool update_lru=true)
Definition: lru.h:640
virtual bool Forget(const Key &key)
Definition: lru.h:669
PathCache(unsigned int cache_size, perf::Statistics *statistics)
Definition: lru_md.h:78
virtual void Drop()
Definition: lru.h:697
bool Insert(const fuse_ino_t &inode, const PathString &path)
Definition: lru_md.h:84
InodeCache(unsigned int cache_size, perf::Statistics *statistics)
Definition: lru_md.h:44
const char * c_str() const
Definition: shortstring.h:145
bool Insert(const shash::Md5 &hash, const catalog::DirectoryEntry &dirent)
Definition: lru_md.h:121
uint32_t MurmurHash2(const void *key, int len, uint32_t seed)
Definition: murmur.hxx:23
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528