GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/catalog_mgr_client.h Lines: 5 8 62.5 %
Date: 2019-02-03 02:48:13 Branches: 1 2 50.0 %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
5
#ifndef CVMFS_CATALOG_MGR_CLIENT_H_
6
#define CVMFS_CATALOG_MGR_CLIENT_H_
7
8
#include "catalog_mgr.h"
9
10
#include <inttypes.h>
11
12
#include <map>
13
#include <string>
14
15
#include "backoff.h"
16
#include "hash.h"
17
#include "manifest_fetch.h"
18
#include "shortstring.h"
19
20
class CacheManager;
21
namespace cvmfs {
22
class Fetcher;
23
}
24
class MountPoint;
25
namespace perf {
26
class Counter;
27
class Statistics;
28
}
29
namespace signature {
30
class SignatureManager;
31
}
32
33
namespace catalog {
34
35
/**
36
 * A catalog manager that uses a Fetcher to get file catalgs in the form of
37
 * (virtual) file descriptors from a cache manager.  Sqlite has a path based
38
 * interface.  This catalog manager returns @<FILE DESCRIPTOR> as a path and
39
 * thus requires a sqlite vfs that supports this syntax, such as the cvmfs
40
 * default vfs for clients.
41
 *
42
 * This class uses the Fetcher in order to get access to the download manager
43
 * and the cache manager, too.  It requires a download manager and a signature
44
 * manager as it calls manifest::Fetch in order to get the manifest of new and
45
 * updated root catalogs.  It requires the cache manager to get access to the
46
 * Unpin() method of the corresponding quota manager; loaded catalogs need to
47
 * be unpinned when the class is destructed.
48
 */
49
class ClientCatalogManager : public AbstractCatalogManager<Catalog> {
50
  // Maintains certificate hit/miss counters
51
  friend class CachedManifestEnsemble;
52
53
 public:
54
  explicit ClientCatalogManager(MountPoint *mountpoint);
55
  virtual ~ClientCatalogManager();
56
57
  bool InitFixed(const shash::Any &root_hash, bool alternative_path);
58
59
  shash::Any GetRootHash();
60
61
  bool IsRevisionBlacklisted();
62
63
  bool offline_mode() const { return offline_mode_; }
64
  uint64_t all_inodes() const { return all_inodes_; }
65
  uint64_t loaded_inodes() const { return loaded_inodes_; }
66
17
  std::string repo_name() const { return repo_name_; }
67
68
 protected:
69
  LoadError LoadCatalog(const PathString  &mountpoint,
70
                        const shash::Any  &hash,
71
                        std::string       *catalog_path,
72
                        shash::Any        *catalog_hash);
73
  void UnloadCatalog(const catalog::Catalog *catalog);
74
  catalog::Catalog* CreateCatalog(const PathString &mountpoint,
75
                                  const shash::Any  &catalog_hash,
76
                                  catalog::Catalog *parent_catalog);
77
  void ActivateCatalog(catalog::Catalog *catalog);
78
79
 private:
80
  LoadError LoadCatalogCas(const shash::Any &hash,
81
                           const std::string &name,
82
                           const std::string &alt_catalog_path,
83
                           std::string *catalog_path);
84
85
  /**
86
   * Required for unpinning
87
   */
88
  std::map<PathString, shash::Any> loaded_catalogs_;
89
  std::map<PathString, shash::Any> mounted_catalogs_;
90
91
  std::string repo_name_;
92
  cvmfs::Fetcher *fetcher_;
93
  signature::SignatureManager *signature_mgr_;
94
  std::string workspace_;
95
  bool offline_mode_;  /**< cached copy used because there is no network */
96
  uint64_t all_inodes_;
97
  uint64_t loaded_inodes_;
98
  bool fixed_alt_root_catalog_;  /**< fixed root hash but alternative url */
99
  BackoffThrottle backoff_throttle_;
100
  perf::Counter *n_certificate_hits_;
101
  perf::Counter *n_certificate_misses_;
102
};
103
104
105
/**
106
 * Tries to fetch the certificate from cache
107
 */
108
24
class CachedManifestEnsemble : public manifest::ManifestEnsemble {
109
 public:
110
24
  CachedManifestEnsemble(
111
    CacheManager *cache_mgr,
112
    ClientCatalogManager *catalog_mgr)
113
    : cache_mgr_(cache_mgr)
114
24
    , catalog_mgr_(catalog_mgr)
115
24
  { }
116
  void FetchCertificate(const shash::Any &hash);
117
118
 private:
119
  CacheManager *cache_mgr_;
120
  ClientCatalogManager *catalog_mgr_;
121
};
122
123
}  // namespace catalog
124
125
#endif  // CVMFS_CATALOG_MGR_CLIENT_H_