Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
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 "crypto/hash.h" |
15 |
|
|
#include "leveldb/env.h" |
16 |
|
|
#include "util/atomic.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 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* Leveldb's background threads must not be started before cvmfs has forked. |
55 |
|
|
* Before forking, we run the processes in specially created threads. |
56 |
|
|
* We make sure, these threads are terminated before forking. |
57 |
|
|
*/ |
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 |
|
|
|
69 |
|
|
NfsMapsLeveldb *maps_; |
70 |
|
|
atomic_int32 num_bg_threads_; |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
NfsMapsLeveldb(); |
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_; |
84 |
|
|
ForkAwareEnv *fork_aware_env_; |
85 |
|
|
uint64_t root_inode_; |
86 |
|
|
uint64_t seq_; |
87 |
|
|
pthread_mutex_t *lock_; |
88 |
|
|
bool spawned_; |
89 |
|
|
|
90 |
|
|
unsigned inode_residue_class_; |
91 |
|
|
unsigned inode_remainder_; |
92 |
|
|
|
93 |
|
|
perf::Counter *n_db_added_; |
94 |
|
|
}; |
95 |
|
|
|
96 |
|
|
#endif // CVMFS_NFS_MAPS_LEVELDB_H_ |
97 |
|
|
|