GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/nfs_maps_sqlite.h Lines: 0 2 0.0 %
Date: 2019-02-03 02:48:13 Branches: 0 0 - %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
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 "atomic.h"
13
#include "duplex_sqlite3.h"
14
#include "hash.h"
15
#include "nfs_maps.h"
16
#include "prng.h"
17
#include "shortstring.h"
18
19
namespace perf {
20
class Counter;
21
class Statistics;
22
}
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(
31
    const std::string &db_dir,
32
    const uint64_t root_inode,
33
    const bool rebuild,
34
    perf::Statistics *statistics_);
35
36
 private:
37
  /**
38
   * Max length of the sql statements
39
   */
40
  static const unsigned  kMaxDBSqlLen = 128;
41
  static const char *kSqlCreateTable;
42
  static const char *kSqlAddRoot;
43
  static const char *kSqlAddInode;
44
  static const char *kSqlGetInode;
45
  static const char *kSqlGetPath;
46
47
  struct BusyHandlerInfo {
48
    BusyHandlerInfo() : accumulated_ms(0) {
49
      prng.InitLocaltime();
50
    }
51
52
    static const unsigned kMaxWaitMs = 60000;
53
    static const unsigned kMaxBackoffMs = 100;
54
    unsigned accumulated_ms;
55
    Prng prng;
56
  };
57
58
  static int BusyHandler(void *data, int attempt);
59
60
  NfsMapsSqlite();
61
  uint64_t FindInode(const PathString &path);
62
  uint64_t IssueInode(const PathString &path);
63
  uint64_t RetryGetInode(const PathString &path, int attempt);
64
65
  sqlite3 *db_;
66
  sqlite3_stmt *stmt_get_path_;
67
  sqlite3_stmt *stmt_get_inode_;
68
  sqlite3_stmt *stmt_add_;
69
  pthread_mutex_t *lock_;
70
71
  BusyHandlerInfo busy_handler_info_;
72
73
  perf::Counter *n_db_seq_;
74
  perf::Counter *n_db_added_;
75
  perf::Counter *n_db_path_found_;
76
  perf::Counter *n_db_inode_found_;
77
};
78
79
#endif  // CVMFS_NFS_MAPS_SQLITE_H_