CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
catalog_rw.h
Go to the documentation of this file.
1 
15 #ifndef CVMFS_CATALOG_RW_H_
16 #define CVMFS_CATALOG_RW_H_
17 
18 #include <stdint.h>
19 
20 #include <string>
21 #include <vector>
22 
23 #include "catalog.h"
24 #include "util/posix.h"
25 
26 class XattrList;
27 
28 namespace swissknife {
29 class CommandMigrate;
30 }
31 
32 namespace catalog {
33 
34 class WritableCatalogManager;
35 
36 class WritableCatalog : public Catalog {
37  friend class WritableCatalogManager;
38  friend class swissknife::CommandMigrate; // needed for catalog migrations
39  friend class VirtualCatalog; // needed for /.cvmfs creation
40 
41  public:
42  WritableCatalog(const std::string &path,
43  const shash::Any &catalog_hash,
44  Catalog *parent,
45  const bool is_not_root = false);
46  virtual ~WritableCatalog();
47 
48  static WritableCatalog *AttachFreely(const std::string &root_path,
49  const std::string &file,
50  const shash::Any &catalog_hash,
51  Catalog *parent = NULL,
52  const bool is_not_root = false);
53 
54  void Transaction();
55  void Commit();
56 
57  inline bool IsDirty() const { return dirty_; }
58  inline bool IsWritable() const { return true; }
59  uint32_t GetMaxLinkId() const;
60 
61  void AddEntry(const DirectoryEntry &entry,
62  const XattrList &xattr,
63  const std::string &entry_path,
64  const std::string &parent_path);
65  void TouchEntry(const DirectoryEntryBase &entry,
66  const XattrList &xattrs,
67  const shash::Md5 &path_hash);
68  inline void TouchEntry(
69  const DirectoryEntryBase &entry,
70  const XattrList &xattrs,
71  const std::string &path)
72  {
73  TouchEntry(entry, xattrs, shash::Md5(shash::AsciiPtr(path)));
74  }
75  void RemoveEntry(const std::string &entry_path);
76  void IncLinkcount(const std::string &path_within_group, const int delta);
77  void AddFileChunk(const std::string &entry_path, const FileChunk &chunk);
78  void RemoveFileChunks(const std::string &entry_path);
79 
80  // Creation and removal of catalogs
81  void Partition(WritableCatalog *new_nested_catalog);
82  void MergeIntoParent();
83  void RemoveFromParent();
84 
85  // Nested catalog references
86  void InsertNestedCatalog(const std::string &mountpoint,
87  Catalog *attached_reference,
88  const shash::Any content_hash,
89  const uint64_t size);
90  void InsertBindMountpoint(const std::string &mountpoint,
91  const shash::Any content_hash,
92  const uint64_t size);
93  void UpdateNestedCatalog(const std::string &path,
94  const shash::Any &hash,
95  const uint64_t size,
96  const DeltaCounters &child_counters);
97  void RemoveNestedCatalog(const std::string &mountpoint,
98  Catalog **attached_reference);
99  void RemoveBindMountpoint(const std::string &mountpoint);
100 
101  void UpdateLastModified();
102  void IncrementRevision();
103  void SetRevision(const uint64_t new_revision);
104  void SetBranch(const std::string &branch_name);
105  void SetPreviousRevision(const shash::Any &hash);
106  void SetTTL(const uint64_t new_ttl);
107  bool SetVOMSAuthz(const std::string &voms_authz);
108 
109  protected:
110  static const double kMaximalFreePageRatio; // = 0.2
111  static const double kMaximalRowIdWasteRatio; // = 0.25;
112 
115  }
116 
117  void UpdateEntry(const DirectoryEntry &entry, const shash::Md5 &path_hash);
118  inline void UpdateEntry(
119  const DirectoryEntry &entry,
120  const std::string &path)
121  {
122  UpdateEntry(entry, shash::Md5(shash::AsciiPtr(path)));
123  }
124 
125  inline void AddEntry(
126  const DirectoryEntry &entry,
127  const XattrList &xattrs,
128  const std::string &path)
129  {
130  AddEntry(entry, xattrs, path, GetParentPath(path));
131  }
132 
133  void InitPreparedStatements();
135 
137  Catalog *parent = this->parent();
138  assert(parent->IsWritable());
139  return static_cast<WritableCatalog *>(parent);
140  }
141 
142  int dirty_children() const { return atomic_read32(&dirty_children_); }
143  void set_dirty_children(const int count) {
144  atomic_write32(&dirty_children_, count);
145  }
147  return atomic_xadd32(&dirty_children_, -1) - 1;
148  }
149 
150  private:
160 
161  bool dirty_;
164 
165  // parallel commit state
167 
168  inline void SetDirty() {
169  if (!dirty_)
170  Transaction();
171  dirty_ = true;
172  }
173 
174  // Helpers for nested catalog creation and removal
175  void MakeTransitionPoint(const std::string &mountpoint);
176  void MakeNestedRoot();
177  inline void MoveToNested(
178  const std::string &dir_structure_root,
179  WritableCatalog *new_nested_catalog,
180  std::vector<std::string> *grand_child_mountpoints)
181  {
182  MoveToNestedRecursively(dir_structure_root,
183  new_nested_catalog,
184  grand_child_mountpoints);
185  }
187  const std::string dir_structure_root,
188  WritableCatalog *new_nested_catalog,
189  std::vector<std::string> *grand_child_mountpoints);
190  void MoveCatalogsToNested(const std::vector<std::string> &nested_catalogs,
191  WritableCatalog *new_nested_catalog);
192  void MoveFileChunksToNested(const std::string &full_path,
194  WritableCatalog *new_nested_catalog);
195 
196  void CopyToParent();
197  void CopyCatalogsToParent();
198 
199  void UpdateCounters();
201 }; // class WritableCatalog
202 
203 typedef std::vector<WritableCatalog *> WritableCatalogList;
204 
205 } // namespace catalog
206 
207 #endif // CVMFS_CATALOG_RW_H_
void MoveFileChunksToNested(const std::string &full_path, const shash::Algorithms algorithm, WritableCatalog *new_nested_catalog)
Definition: catalog_rw.cc:477
void AddEntry(const DirectoryEntry &entry, const XattrList &xattrs, const std::string &path)
Definition: catalog_rw.h:125
void RemoveFileChunks(const std::string &entry_path)
Definition: catalog_rw.cc:291
SqlDirentInsert * sql_insert_
Definition: catalog_rw.h:151
void set_dirty_children(const int count)
Definition: catalog_rw.h:143
static const double kMaximalFreePageRatio
Definition: catalog_rw.h:110
uint32_t GetMaxLinkId() const
Definition: catalog_rw.cc:124
void UpdateNestedCatalog(const std::string &path, const shash::Any &hash, const uint64_t size, const DeltaCounters &child_counters)
Definition: catalog_rw.cc:620
void InsertBindMountpoint(const std::string &mountpoint, const shash::Any content_hash, const uint64_t size)
Definition: catalog_rw.cc:535
bool IsDirty() const
Definition: catalog_rw.h:57
CatalogDatabase::OpenMode DatabaseOpenMode() const
Definition: catalog_rw.h:113
void InsertNestedCatalog(const std::string &mountpoint, Catalog *attached_reference, const shash::Any content_hash, const uint64_t size)
Definition: catalog_rw.cc:502
void RemoveBindMountpoint(const std::string &mountpoint)
Definition: catalog_rw.cc:597
void TouchEntry(const DirectoryEntryBase &entry, const XattrList &xattrs, const shash::Md5 &path_hash)
Definition: catalog_rw.cc:224
assert((mem||(size==0))&&"Out Of Memory")
SqlChunksCount * sql_chunks_count_
Definition: catalog_rw.h:157
void SetPreviousRevision(const shash::Any &hash)
Definition: catalog_rw.cc:352
Catalog * parent() const
Definition: catalog.h:180
SqlChunkInsert * sql_chunk_insert_
Definition: catalog_rw.h:155
void MoveToNestedRecursively(const std::string dir_structure_root, WritableCatalog *new_nested_catalog, std::vector< std::string > *grand_child_mountpoints)
Definition: catalog_rw.cc:407
std::vector< WritableCatalog * > WritableCatalogList
Definition: catalog_rw.h:203
SqlChunksRemove * sql_chunks_remove_
Definition: catalog_rw.h:156
void MakeTransitionPoint(const std::string &mountpoint)
Definition: catalog_rw.cc:380
SqlIncLinkcount * sql_inc_linkcount_
Definition: catalog_rw.h:159
char algorithm
void MoveToNested(const std::string &dir_structure_root, WritableCatalog *new_nested_catalog, std::vector< std::string > *grand_child_mountpoints)
Definition: catalog_rw.h:177
Algorithms
Definition: hash.h:41
static WritableCatalog * AttachFreely(const std::string &root_path, const std::string &file, const shash::Any &catalog_hash, Catalog *parent=NULL, const bool is_not_root=false)
Definition: catalog_rw.cc:49
int32_t atomic_int32
Definition: atomic.h:17
void AddFileChunk(const std::string &entry_path, const FileChunk &chunk)
Definition: catalog_rw.cc:264
bool IsWritable() const
Definition: catalog_rw.h:58
atomic_int32 dirty_children_
Definition: catalog_rw.h:166
SqlDirentUpdate * sql_update_
Definition: catalog_rw.h:154
void SetTTL(const uint64_t new_ttl)
Definition: catalog_rw.cc:339
SqlMaxHardlinkGroup * sql_max_link_id_
Definition: catalog_rw.h:158
PathString mountpoint() const
Definition: catalog.h:179
WritableCatalog(const std::string &path, const shash::Any &catalog_hash, Catalog *parent, const bool is_not_root=false)
Definition: catalog_rw.cc:26
static const double kMaximalRowIdWasteRatio
Definition: catalog_rw.h:111
void RemoveNestedCatalog(const std::string &mountpoint, Catalog **attached_reference)
Definition: catalog_rw.cc:561
bool SetVOMSAuthz(const std::string &voms_authz)
Definition: catalog_rw.cc:344
void AddEntry(const DirectoryEntry &entry, const XattrList &xattr, const std::string &entry_path, const std::string &parent_path)
SqlDirentTouch * sql_touch_
Definition: catalog_rw.h:153
SqlDirentUnlink * sql_unlink_
Definition: catalog_rw.h:152
void SetBranch(const std::string &branch_name)
Definition: catalog_rw.cc:334
void Partition(WritableCatalog *new_nested_catalog)
Definition: catalog_rw.cc:360
void SetRevision(const uint64_t new_revision)
Definition: catalog_rw.cc:329
void MoveCatalogsToNested(const std::vector< std::string > &nested_catalogs, WritableCatalog *new_nested_catalog)
Definition: catalog_rw.cc:456
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:15
WritableCatalog * GetWritableParent() const
Definition: catalog_rw.h:136
DeltaCounters delta_counters_
Definition: catalog_rw.h:163
shash::Any hash() const
Definition: catalog.h:186
void RemoveEntry(const std::string &entry_path)
Definition: catalog_rw.cc:184
void UpdateEntry(const DirectoryEntry &entry, const std::string &path)
Definition: catalog_rw.h:118
virtual bool IsWritable() const
Definition: catalog.h:201
static void size_t size
Definition: smalloc.h:54
void IncLinkcount(const std::string &path_within_group, const int delta)
Definition: catalog_rw.cc:208
void TouchEntry(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &path)
Definition: catalog_rw.h:68
int dirty_children() const
Definition: catalog_rw.h:142
void UpdateEntry(const DirectoryEntry &entry, const shash::Md5 &path_hash)
Definition: catalog_rw.cc:252