CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nfs_maps_leveldb.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_NFS_MAPS_LEVELDB_H_
6 #define CVMFS_NFS_MAPS_LEVELDB_H_
7 
8 #include "nfs_maps.h"
9 
10 #include <pthread.h>
11 
12 #include <string>
13 
14 #include "atomic.h"
15 #include "hash.h"
16 #include "leveldb/env.h"
17 
18 
19 namespace leveldb {
20 class DB;
21 class Cache;
22 class FilterPolicy;
23 }
24 namespace perf {
25 class Counter;
26 class Statistics;
27 }
28 
29 
30 class NfsMapsLeveldb : public NfsMaps {
31  public:
32  virtual ~NfsMapsLeveldb();
33  virtual uint64_t GetInode(const PathString &path);
34  virtual bool GetPath(const uint64_t inode, PathString *path);
35  virtual void SetInodeResidue(unsigned residue_class, unsigned remainder);
36  virtual void Spawn() { spawned_ = true; }
37  virtual std::string GetStatistics();
38 
39  static NfsMapsLeveldb *Create(
40  const std::string &leveldb_dir,
41  const uint64_t root_inode,
42  const bool rebuild,
43  perf::Statistics *statistics);
44 
45  private:
46  class ForkAwareEnv;
47  struct FuncArg {
48  void (*function)(void*);
49  void *arg;
50  class ForkAwareEnv *env;
51  };
52 
58  class ForkAwareEnv : public leveldb::EnvWrapper {
59  public:
60  explicit ForkAwareEnv(NfsMapsLeveldb *maps);
61  void StartThread(void (*f)(void*), void* a);
62  void Schedule(void (*function)(void*), void* arg);
63  void WaitForBGThreads();
64  void SleepForMicroseconds(int micros);
65 
66  private:
67  static void *MainFakeThread(void *data);
68 
71  };
72 
74  void PutInode2Path(const uint64_t inode, const PathString &path);
75  void PutPath2Inode(const shash::Md5 &path, const uint64_t inode);
76  uint64_t FindInode(const shash::Md5 &path);
77 
78  leveldb::DB *db_inode2path_;
79  leveldb::DB *db_path2inode_;
80  leveldb::Cache *cache_inode2path_;
81  leveldb::Cache *cache_path2inode_;
82  const leveldb::FilterPolicy *filter_inode2path_;
83  const leveldb::FilterPolicy *filter_path2inode_;
85  uint64_t root_inode_;
86  uint64_t seq_;
87  pthread_mutex_t *lock_;
88  bool spawned_;
89 
91  unsigned inode_remainder_;
92 
94 };
95 
96 #endif // CVMFS_NFS_MAPS_LEVELDB_H_
virtual bool GetPath(const uint64_t inode, PathString *path)
pthread_mutex_t * lock_
virtual void SetInodeResidue(unsigned residue_class, unsigned remainder)
const leveldb::FilterPolicy * filter_inode2path_
uint64_t root_inode_
virtual void Spawn()
static NfsMapsLeveldb * Create(const std::string &leveldb_dir, const uint64_t root_inode, const bool rebuild, perf::Statistics *statistics)
uint64_t FindInode(const shash::Md5 &path)
virtual uint64_t GetInode(const PathString &path)
perf::Counter * n_db_added_
leveldb::DB * db_path2inode_
unsigned inode_residue_class_
void PutInode2Path(const uint64_t inode, const PathString &path)
ForkAwareEnv(NfsMapsLeveldb *maps)
int32_t atomic_int32
Definition: atomic.h:17
static void * MainFakeThread(void *data)
virtual std::string GetStatistics()
leveldb::DB * db_inode2path_
leveldb::Cache * cache_path2inode_
unsigned inode_remainder_
void Schedule(void(*function)(void *), void *arg)
void PutPath2Inode(const shash::Md5 &path, const uint64_t inode)
virtual ~NfsMapsLeveldb()
void StartThread(void(*f)(void *), void *a)
void SleepForMicroseconds(int micros)
const leveldb::FilterPolicy * filter_path2inode_
ForkAwareEnv * fork_aware_env_
leveldb::Cache * cache_inode2path_
class ForkAwareEnv * env