GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/nfs_maps_sqlite.h
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 0 2 0.0%
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 "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 }
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 static const char *kSqlCreateTable;
38 static const char *kSqlAddRoot;
39 static const char *kSqlAddInode;
40 static const char *kSqlGetInode;
41 static const char *kSqlGetPath;
42
43 struct BusyHandlerInfo {
44 BusyHandlerInfo() : accumulated_ms(0) {
45 prng.InitLocaltime();
46 }
47
48 static const unsigned kMaxWaitMs = 60000;
49 static const unsigned kMaxBackoffMs = 100;
50 unsigned accumulated_ms;
51 Prng prng;
52 };
53
54 static int BusyHandler(void *data, int attempt);
55
56 NfsMapsSqlite();
57 uint64_t FindInode(const PathString &path);
58 uint64_t IssueInode(const PathString &path);
59 uint64_t RetryGetInode(const PathString &path, int attempt);
60
61 sqlite3 *db_;
62 sqlite3_stmt *stmt_get_path_;
63 sqlite3_stmt *stmt_get_inode_;
64 sqlite3_stmt *stmt_add_;
65 pthread_mutex_t *lock_;
66
67 BusyHandlerInfo busy_handler_info_;
68
69 perf::Counter *n_db_seq_;
70 perf::Counter *n_db_added_;
71 perf::Counter *n_db_path_found_;
72 perf::Counter *n_db_inode_found_;
73 };
74
75 #endif // CVMFS_NFS_MAPS_SQLITE_H_
76