GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/reflog.h Lines: 1 2 50.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_REFLOG_H_
6
#define CVMFS_REFLOG_H_
7
8
#include <string>
9
#include <vector>
10
11
#include "reflog_sql.h"
12
13
namespace manifest {
14
15
16
/**
17
 * This is an object reference log meant to keep track of all "root" objects in
18
 * the backend storage it is situated in. It's main purpose is to keep track of
19
 * historic objects for efficient and robust garbage collection.
20
 *
21
 * "Root objects" in this sense are backend objects containing references to
22
 * other backend objects but that are not necessarily referenced by any other
23
 * object in the backend. For example historic root catalogs, history databases,
24
 * meta-info objects or certificates.
25
 *
26
 * Every time such an object is newly added to a backend storage of CernVM-FS
27
 * its content hash (and object type) will be added to the Reflog. This ensures
28
 * an authorative list of "root objects" in a given backend storage.
29
 *
30
 * Reflogs are associated to a specific backend storage of Stratum0 or Stratum1
31
 * and _not_ to a CernVM-FS repository. Thus, the Reflogs of Stratum0 and its
32
 * replicas can and probably will be different and are _not_ interchangable.
33
 *
34
 * TODO(rmeusel): this shares a lot of database management code with
35
 *                SqliteHistory and (potentially) ...Catalog. This might be an
36
 *                architectural weakness and should be cleaned up.
37
 */
38
73
class Reflog {
39
 public:
40
  static Reflog *Open(const std::string &database_path);
41
  static Reflog *Create(const std::string &database_path,
42
                        const std::string &repo_name);
43
  static void HashDatabase(const std::string &database_path,
44
                           shash::Any *hash_reflog);
45
46
  static bool ReadChecksum(const std::string &path, shash::Any* checksum);
47
  static bool WriteChecksum(const std::string &path, const shash::Any &value);
48
49
  bool AddCertificate(const shash::Any &certificate);
50
  bool AddCatalog(const shash::Any &catalog);
51
  bool AddHistory(const shash::Any &history);
52
  bool AddMetainfo(const shash::Any &metainfo);
53
54
  uint64_t CountEntries();
55
  bool List(SqlReflog::ReferenceType type,
56
            std::vector<shash::Any> *hashes) const;
57
  bool ListOlderThan(SqlReflog::ReferenceType type,
58
                     uint64_t timestamp,
59
                     std::vector<shash::Any> *hashes) const;
60
61
  bool Remove(const shash::Any &hash);
62
63
  bool ContainsCertificate(const shash::Any &certificate) const;
64
  bool ContainsCatalog(const shash::Any &catalog) const;
65
  bool ContainsHistory(const shash::Any &history) const;
66
  bool ContainsMetainfo(const shash::Any &metainfo) const;
67
68
  bool GetCatalogTimestamp(const shash::Any &catalog,
69
                           uint64_t *timestamp) const;
70
71
  void BeginTransaction();
72
  void CommitTransaction();
73
74
  void TakeDatabaseFileOwnership();
75
  void DropDatabaseFileOwnership();
76
  bool OwnsDatabaseFile() const {
77
    return database_.IsValid() && database_->OwnsFile();
78
  }
79
  bool Vacuum() { return database_->Vacuum(); }
80
81
  std::string fqrn() const;
82
  std::string database_file() const;
83
84
 protected:
85
  bool AddReference(const shash::Any               &hash,
86
                    const SqlReflog::ReferenceType  type);
87
  bool ContainsReference(const shash::Any               &hash,
88
                         const SqlReflog::ReferenceType  type) const;
89
  bool GetReferenceTimestamp(const shash::Any               &hash,
90
                             const SqlReflog::ReferenceType  type,
91
                             uint64_t *timestamp) const;
92
93
 private:
94
  bool CreateDatabase(const std::string &database_path,
95
                      const std::string &repo_name);
96
  bool OpenDatabase(const std::string &database_path);
97
98
  void PrepareQueries();
99
100
 private:
101
  UniquePtr<ReflogDatabase>       database_;
102
103
  UniquePtr<SqlInsertReference>   insert_reference_;
104
  UniquePtr<SqlCountReferences>   count_references_;
105
  UniquePtr<SqlListReferences>    list_references_;
106
  UniquePtr<SqlRemoveReference>   remove_reference_;
107
  UniquePtr<SqlContainsReference> contains_reference_;
108
  UniquePtr<SqlGetTimestamp>      get_timestamp_;
109
};
110
111
}  // namespace manifest
112
113
#endif  // CVMFS_REFLOG_H_