CernVM-FS  2.9.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 "hash.h"
15 
16 namespace history {
17 
33 class History {
34  public:
47  };
48 
49  struct Branch {
51  Branch(const std::string &b, const std::string &p, unsigned r)
52  : branch(b), parent(p), initial_revision(r) { }
53  std::string branch;
54  std::string parent;
55  unsigned initial_revision;
56 
57  bool operator ==(const Branch &other) const {
58  return (this->branch == other.branch) &&
59  (this->parent == other.parent) &&
60  (this->initial_revision == other.initial_revision);
61  }
62 
63  // Used for sorting in unit tests
64  bool operator <(const Branch &other) const {
65  return (this->branch < other.branch);
66  }
67  };
68 
76  struct Tag {
77  Tag() :
79 
80  Tag(const std::string &n, const shash::Any &h, const uint64_t s,
81  const unsigned r, const time_t t, const UpdateChannel c,
82  const std::string &d, const std::string &b) :
83  name(n), root_hash(h), size(s), revision(r), timestamp(t), channel(c),
84  description(d), branch(b) {}
85 
86  inline const char* GetChannelName() const {
87  switch (channel) {
88  case kChannelTrunk: return "trunk";
89  case kChannelDevel: return "development";
90  case kChannelTest: return "testing";
91  case kChannelProd: return "production";
92  default: assert(false && "unknown channel id");
93  }
94  }
95 
96  bool operator ==(const Tag &other) const {
97  return (this->branch == other.branch) &&
98  (this->revision == other.revision);
99  }
100 
101  bool operator <(const Tag &other) const {
102  if (this->timestamp == other.timestamp)
103  return this->revision < other.revision;
104  return this->timestamp < other.timestamp;
105  }
106 
107  bool operator >(const Tag &other) const {
108  if (this->timestamp == other.timestamp)
109  return this->revision > other.revision;
110  return this->timestamp > other.timestamp;
111  }
112 
113  std::string name;
115  uint64_t size;
116  unsigned revision;
117  time_t timestamp;
119  std::string description;
123  std::string branch;
124  }; // struct Tag
125 
126 
127  public:
128  virtual ~History() { }
129 
130  virtual bool IsWritable() const = 0;
131  virtual unsigned GetNumberOfTags() const = 0;
132 
138  virtual bool BeginTransaction() const = 0;
139 
143  virtual bool CommitTransaction() const = 0;
144 
151  virtual bool SetPreviousRevision(const shash::Any &history_hash) = 0;
152  virtual shash::Any previous_revision() const = 0;
153 
154  virtual bool Insert(const Tag &tag) = 0;
155  virtual bool Remove(const std::string &name) = 0;
156  virtual bool Exists(const std::string &name) const = 0;
157  virtual bool GetByName(const std::string &name, Tag *tag) const = 0;
158  virtual bool GetByDate(const time_t timestamp, Tag *tag) const = 0;
159  virtual bool List(std::vector<Tag> *tags) const = 0;
160  virtual bool Tips(std::vector<Tag> *channel_tips) const = 0;
161 
162  virtual bool GetBranchHead(const std::string &branch_name, Tag *tag)
163  const = 0;
164  virtual bool ExistsBranch(const std::string &branch_name) const = 0;
165  virtual bool InsertBranch(const Branch &branch) = 0;
170  virtual bool PruneBranches() = 0;
171  virtual bool ListBranches(std::vector<Branch> *branches) const = 0;
172 
177  virtual bool ListRecycleBin(std::vector<shash::Any> *hashes) const = 0;
178  virtual bool EmptyRecycleBin() = 0;
179 
190  virtual bool Rollback(const Tag &updated_target_tag) = 0;
191 
202  virtual bool ListTagsAffectedByRollback(const std::string &target_tag_name,
203  std::vector<Tag> *tags) const = 0;
204 
211  virtual bool GetHashes(std::vector<shash::Any> *hashes) const = 0;
212 
213  // database file management controls
214  virtual void TakeDatabaseFileOwnership() = 0;
215  virtual void DropDatabaseFileOwnership() = 0;
216  virtual bool OwnsDatabaseFile() const = 0;
217 
218  virtual bool Vacuum() = 0;
219 
220  const std::string& fqrn() const { return fqrn_; }
221 
222  protected:
223  void set_fqrn(const std::string &fqrn) { fqrn_ = fqrn; }
224 
225  private:
226  std::string fqrn_;
227 };
228 
229 } // namespace history
230 
231 #endif // CVMFS_HISTORY_H_
UpdateChannel channel
Definition: history.h:118
unsigned initial_revision
Definition: history.h:55
bool operator<(const Branch &other) const
Definition: history.h:64
virtual bool PruneBranches()=0
std::string name
Definition: history.h:113
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
Branch(const std::string &b, const std::string &p, unsigned r)
Definition: history.h:51
assert((mem||(size==0))&&"Out Of Memory")
bool operator==(const Tag &other) const
Definition: history.h:96
virtual ~History()
Definition: history.h:128
const std::string & fqrn() const
Definition: history.h:220
virtual bool GetByDate(const time_t timestamp, Tag *tag) const =0
bool operator>(const Tag &other) const
Definition: history.h:107
std::string description
Definition: history.h:119
bool operator==(const Branch &other) const
Definition: history.h:57
virtual bool ListBranches(std::vector< Branch > *branches) const =0
const char * GetChannelName() const
Definition: history.h:86
virtual bool IsWritable() const =0
std::string parent
Definition: history.h:54
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:226
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
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:223
virtual bool Insert(const Tag &tag)=0
Tag(const std::string &n, const shash::Any &h, const uint64_t s, const unsigned r, const time_t t, const UpdateChannel c, const std::string &d, const std::string &b)
Definition: history.h:80
virtual bool GetBranchHead(const std::string &branch_name, Tag *tag) const =0
shash::Any root_hash
Definition: history.h:114
virtual void TakeDatabaseFileOwnership()=0
std::string branch
Definition: history.h:123
virtual bool EmptyRecycleBin()=0
bool operator<(const Tag &other) const
Definition: history.h:101
std::string branch
Definition: history.h:53
virtual bool BeginTransaction() const =0
virtual bool Tips(std::vector< Tag > *channel_tips) const =0