CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
history.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_HISTORY_H_
6 #define CVMFS_HISTORY_H_
7 
8 #include <stdint.h>
9 #include <time.h>
10 
11 #include <string>
12 #include <vector>
13 
14 #include "crypto/hash.h"
15 
16 namespace history {
17 
33 class History {
34  public:
35  struct Branch {
37  Branch(const std::string &b, const std::string &p, uint64_t r)
38  : branch(b), parent(p), initial_revision(r) { }
39  std::string branch;
40  std::string parent;
41  uint64_t initial_revision;
42 
43  bool operator ==(const Branch &other) const {
44  return (this->branch == other.branch) &&
45  (this->parent == other.parent) &&
46  (this->initial_revision == other.initial_revision);
47  }
48 
49  // Used for sorting in unit tests
50  bool operator <(const Branch &other) const {
51  return (this->branch < other.branch);
52  }
53  };
54 
62  struct Tag {
63  Tag() : size(0), revision(0), timestamp(0) {}
64 
65  Tag(const std::string &n, const shash::Any &h, const uint64_t s,
66  const uint64_t r, const time_t t, const std::string &d,
67  const std::string &b) :
68  name(n), root_hash(h), size(s), revision(r), timestamp(t),
69  description(d), branch(b) {}
70 
71  bool operator ==(const Tag &other) const {
72  return (this->branch == other.branch) &&
73  (this->revision == other.revision);
74  }
75 
76  bool operator <(const Tag &other) const {
77  if (this->timestamp == other.timestamp)
78  return this->revision < other.revision;
79  return this->timestamp < other.timestamp;
80  }
81 
82  bool operator >(const Tag &other) const {
83  if (this->timestamp == other.timestamp)
84  return this->revision > other.revision;
85  return this->timestamp > other.timestamp;
86  }
87 
88  std::string name;
90  uint64_t size;
91  uint64_t revision;
92  time_t timestamp;
93  std::string description;
97  std::string branch;
98  }; // struct Tag
99 
100 
101  public:
102  virtual ~History() { }
103 
104  virtual bool IsWritable() const = 0;
105  virtual unsigned GetNumberOfTags() const = 0;
106 
112  virtual bool BeginTransaction() const = 0;
113 
117  virtual bool CommitTransaction() const = 0;
118 
125  virtual bool SetPreviousRevision(const shash::Any &history_hash) = 0;
126  virtual shash::Any previous_revision() const = 0;
127 
128  virtual bool Insert(const Tag &tag) = 0;
129  virtual bool Remove(const std::string &name) = 0;
130  virtual bool Exists(const std::string &name) const = 0;
131  virtual bool GetByName(const std::string &name, Tag *tag) const = 0;
132  virtual bool GetByDate(const time_t timestamp, Tag *tag) const = 0;
133  virtual bool List(std::vector<Tag> *tags) const = 0;
134 
135  virtual bool GetBranchHead(const std::string &branch_name, Tag *tag)
136  const = 0;
137  virtual bool ExistsBranch(const std::string &branch_name) const = 0;
138  virtual bool InsertBranch(const Branch &branch) = 0;
143  virtual bool PruneBranches() = 0;
144  virtual bool ListBranches(std::vector<Branch> *branches) const = 0;
145 
150  virtual bool ListRecycleBin(std::vector<shash::Any> *hashes) const = 0;
151  virtual bool EmptyRecycleBin() = 0;
152 
163  virtual bool Rollback(const Tag &updated_target_tag) = 0;
164 
175  virtual bool ListTagsAffectedByRollback(const std::string &target_tag_name,
176  std::vector<Tag> *tags) const = 0;
177 
184  virtual bool GetHashes(std::vector<shash::Any> *hashes) const = 0;
185 
186  // database file management controls
187  virtual void TakeDatabaseFileOwnership() = 0;
188  virtual void DropDatabaseFileOwnership() = 0;
189  virtual bool OwnsDatabaseFile() const = 0;
190 
191  virtual bool Vacuum() = 0;
192 
193  const std::string& fqrn() const { return fqrn_; }
194 
195  protected:
196  void set_fqrn(const std::string &fqrn) { fqrn_ = fqrn; }
197 
198  private:
199  std::string fqrn_;
200 };
201 
202 } // namespace history
203 
204 #endif // CVMFS_HISTORY_H_
bool operator<(const Branch &other) const
Definition: history.h:50
virtual bool PruneBranches()=0
std::string name
Definition: history.h:88
const history::History * history() const
virtual bool Exists(const std::string &name) const =0
virtual shash::Any previous_revision() const =0
virtual bool SetPreviousRevision(const shash::Any &history_hash)=0
virtual bool CommitTransaction() const =0
virtual unsigned GetNumberOfTags() const =0
bool operator==(const Tag &other) const
Definition: history.h:71
virtual ~History()
Definition: history.h:102
Tag(const std::string &n, const shash::Any &h, const uint64_t s, const uint64_t r, const time_t t, const std::string &d, const std::string &b)
Definition: history.h:65
const std::string & fqrn() const
Definition: history.h:193
virtual bool GetByDate(const time_t timestamp, Tag *tag) const =0
bool operator>(const Tag &other) const
Definition: history.h:82
std::string description
Definition: history.h:93
bool operator==(const Branch &other) const
Definition: history.h:43
virtual bool ListBranches(std::vector< Branch > *branches) const =0
virtual bool IsWritable() const =0
std::string parent
Definition: history.h:40
virtual bool List(std::vector< Tag > *tags) const =0
virtual bool InsertBranch(const Branch &branch)=0
virtual void DropDatabaseFileOwnership()=0
virtual bool ListRecycleBin(std::vector< shash::Any > *hashes) const =0
std::string fqrn_
Definition: history.h:199
virtual bool Vacuum()=0
virtual bool GetHashes(std::vector< shash::Any > *hashes) const =0
virtual bool Remove(const std::string &name)=0
virtual bool ListTagsAffectedByRollback(const std::string &target_tag_name, std::vector< Tag > *tags) const =0
Branch(const std::string &b, const std::string &p, uint64_t r)
Definition: history.h:37
virtual bool ExistsBranch(const std::string &branch_name) const =0
virtual bool OwnsDatabaseFile() const =0
virtual bool Rollback(const Tag &updated_target_tag)=0
virtual bool GetByName(const std::string &name, Tag *tag) const =0
void set_fqrn(const std::string &fqrn)
Definition: history.h:196
virtual bool Insert(const Tag &tag)=0
virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const =0
shash::Any root_hash
Definition: history.h:89
virtual void TakeDatabaseFileOwnership()=0
uint64_t initial_revision
Definition: history.h:41
std::string branch
Definition: history.h:97
virtual bool EmptyRecycleBin()=0
bool operator<(const Tag &other) const
Definition: history.h:76
uint64_t revision
Definition: history.h:91
std::string branch
Definition: history.h:39
virtual bool BeginTransaction() const =0