CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nfs_maps_sqlite.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_NFS_MAPS_SQLITE_H_
6 #define CVMFS_NFS_MAPS_SQLITE_H_
7 
8 #include <pthread.h>
9 
10 #include <string>
11 
12 #include "crypto/hash.h"
13 #include "duplex_sqlite3.h"
14 #include "nfs_maps.h"
15 #include "shortstring.h"
16 #include "util/atomic.h"
17 #include "util/prng.h"
18 
19 namespace perf {
20 class Counter;
21 class Statistics;
22 } // namespace perf
23 
24 class NfsMapsSqlite : public NfsMaps {
25  public:
26  virtual ~NfsMapsSqlite();
27  virtual uint64_t GetInode(const PathString &path);
28  virtual bool GetPath(const uint64_t inode, PathString *path);
29 
30  static NfsMapsSqlite *Create(const std::string &db_dir,
31  const uint64_t root_inode,
32  const bool rebuild,
34 
35  private:
36  static const char *kSqlCreateTable;
37  static const char *kSqlAddRoot;
38  static const char *kSqlAddInode;
39  static const char *kSqlGetInode;
40  static const char *kSqlGetPath;
41 
42  struct BusyHandlerInfo {
44 
45  static const unsigned kMaxWaitMs = 60000;
46  static const unsigned kMaxBackoffMs = 100;
47  unsigned accumulated_ms;
49  };
50 
51  static int BusyHandler(void *data, int attempt);
52 
53  NfsMapsSqlite();
54  uint64_t FindInode(const PathString &path);
55  uint64_t IssueInode(const PathString &path);
56  uint64_t RetryGetInode(const PathString &path, int attempt);
57 
58  sqlite3 *db_;
59  sqlite3_stmt *stmt_get_path_;
60  sqlite3_stmt *stmt_get_inode_;
61  sqlite3_stmt *stmt_add_;
62  pthread_mutex_t *lock_;
63 
65 
70 };
71 
72 #endif // CVMFS_NFS_MAPS_SQLITE_H_
virtual ~NfsMapsSqlite()
Definition: prng.h:27
perf::Counter * n_db_added_
sqlite3_stmt * stmt_add_
static const char * kSqlGetPath
static NfsMapsSqlite * Create(const std::string &db_dir, const uint64_t root_inode, const bool rebuild, perf::Statistics *statistics_)
perf::Counter * n_db_seq_
uint64_t FindInode(const PathString &path)
void InitLocaltime()
Definition: prng.h:34
perf::Statistics * statistics_
Definition: repository.h:138
static const char * kSqlAddRoot
BusyHandlerInfo busy_handler_info_
static const char * kSqlGetInode
pthread_mutex_t * lock_
static const unsigned kMaxWaitMs
virtual uint64_t GetInode(const PathString &path)
static int BusyHandler(void *data, int attempt)
static const char * kSqlCreateTable
static const unsigned kMaxBackoffMs
virtual bool GetPath(const uint64_t inode, PathString *path)
perf::Counter * n_db_inode_found_
sqlite3_stmt * stmt_get_inode_
uint64_t RetryGetInode(const PathString &path, int attempt)
uint64_t IssueInode(const PathString &path)
perf::Counter * n_db_path_found_
sqlite3_stmt * stmt_get_path_
static const char * kSqlAddInode