CernVM-FS  2.13.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(const DirectoryEntryBase &entry,
69  const XattrList &xattrs,
70  const std::string &path) {
71  TouchEntry(entry, xattrs, shash::Md5(shash::AsciiPtr(path)));
72  }
73  void RemoveEntry(const std::string &entry_path);
74  void IncLinkcount(const std::string &path_within_group, const int delta);
75  void AddFileChunk(const std::string &entry_path, const FileChunk &chunk);
76  void RemoveFileChunks(const std::string &entry_path);
77 
78  // Creation and removal of catalogs
79  void Partition(WritableCatalog *new_nested_catalog);
80  void MergeIntoParent();
81  void RemoveFromParent();
82 
83  // Nested catalog references
84  void InsertNestedCatalog(const std::string &mountpoint,
85  Catalog *attached_reference,
86  const shash::Any content_hash,
87  const uint64_t size);
88  void InsertBindMountpoint(const std::string &mountpoint,
89  const shash::Any content_hash,
90  const uint64_t size);
91  void UpdateNestedCatalog(const std::string &path,
92  const shash::Any &hash,
93  const uint64_t size,
94  const DeltaCounters &child_counters);
95  void RemoveNestedCatalog(const std::string &mountpoint,
96  Catalog **attached_reference);
97  void RemoveBindMountpoint(const std::string &mountpoint);
98 
99  void UpdateLastModified();
100  void IncrementRevision();
101  void SetRevision(const uint64_t new_revision);
102  void SetBranch(const std::string &branch_name);
103  void SetPreviousRevision(const shash::Any &hash);
104  void SetTTL(const uint64_t new_ttl);
105  bool SetVOMSAuthz(const std::string &voms_authz);
106 
107  protected:
108  static const double kMaximalFreePageRatio; // = 0.2
109  static const double kMaximalRowIdWasteRatio; // = 0.25;
110 
113  }
114 
115  void UpdateEntry(const DirectoryEntry &entry, const shash::Md5 &path_hash);
116  inline void UpdateEntry(const DirectoryEntry &entry,
117  const std::string &path) {
118  UpdateEntry(entry, shash::Md5(shash::AsciiPtr(path)));
119  }
120 
121  inline void AddEntry(const DirectoryEntry &entry,
122  const XattrList &xattrs,
123  const std::string &path) {
124  AddEntry(entry, xattrs, path, GetParentPath(path));
125  }
126 
127  void InitPreparedStatements();
129 
131  Catalog *parent = this->parent();
132  assert(parent->IsWritable());
133  return static_cast<WritableCatalog *>(parent);
134  }
135 
136  int dirty_children() const { return atomic_read32(&dirty_children_); }
137  void set_dirty_children(const int count) {
138  atomic_write32(&dirty_children_, count);
139  }
141  return atomic_xadd32(&dirty_children_, -1) - 1;
142  }
143 
144  private:
154 
155  bool dirty_;
158 
159  // parallel commit state
161 
162  inline void SetDirty() {
163  if (!dirty_)
164  Transaction();
165  dirty_ = true;
166  }
167 
168  // Helpers for nested catalog creation and removal
169  void MakeTransitionPoint(const std::string &mountpoint);
170  void MakeNestedRoot();
171  inline void MoveToNested(const std::string &dir_structure_root,
172  WritableCatalog *new_nested_catalog,
173  std::vector<std::string> *grand_child_mountpoints) {
175  dir_structure_root, new_nested_catalog, grand_child_mountpoints);
176  }
178  const std::string dir_structure_root,
179  WritableCatalog *new_nested_catalog,
180  std::vector<std::string> *grand_child_mountpoints);
181  void MoveCatalogsToNested(const std::vector<std::string> &nested_catalogs,
182  WritableCatalog *new_nested_catalog);
183  void MoveFileChunksToNested(const std::string &full_path,
185  WritableCatalog *new_nested_catalog);
186 
187  void CopyToParent();
188  void CopyCatalogsToParent();
189 
190  void UpdateCounters();
192 }; // class WritableCatalog
193 
194 typedef std::vector<WritableCatalog *> WritableCatalogList;
195 
196 } // namespace catalog
197 
198 #endif // CVMFS_CATALOG_RW_H_
void MoveFileChunksToNested(const std::string &full_path, const shash::Algorithms algorithm, WritableCatalog *new_nested_catalog)
Definition: catalog_rw.cc:461
void AddEntry(const DirectoryEntry &entry, const XattrList &xattrs, const std::string &path)
Definition: catalog_rw.h:121
void RemoveFileChunks(const std::string &entry_path)
Definition: catalog_rw.cc:279
SqlDirentInsert * sql_insert_
Definition: catalog_rw.h:145
void set_dirty_children(const int count)
Definition: catalog_rw.h:137
static const double kMaximalFreePageRatio
Definition: catalog_rw.h:108
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:588
void InsertBindMountpoint(const std::string &mountpoint, const shash::Any content_hash, const uint64_t size)
Definition: catalog_rw.cc:514
bool IsDirty() const
Definition: catalog_rw.h:57
CatalogDatabase::OpenMode DatabaseOpenMode() const
Definition: catalog_rw.h:111
void InsertNestedCatalog(const std::string &mountpoint, Catalog *attached_reference, const shash::Any content_hash, const uint64_t size)
Definition: catalog_rw.cc:485
void RemoveBindMountpoint(const std::string &mountpoint)
Definition: catalog_rw.cc:568
void TouchEntry(const DirectoryEntryBase &entry, const XattrList &xattrs, const shash::Md5 &path_hash)
Definition: catalog_rw.cc:216
assert((mem||(size==0))&&"Out Of Memory")
SqlChunksCount * sql_chunks_count_
Definition: catalog_rw.h:151
void SetPreviousRevision(const shash::Any &hash)
Definition: catalog_rw.cc:336
Catalog * parent() const
Definition: catalog.h:176
SqlChunkInsert * sql_chunk_insert_
Definition: catalog_rw.h:149
void MoveToNestedRecursively(const std::string dir_structure_root, WritableCatalog *new_nested_catalog, std::vector< std::string > *grand_child_mountpoints)
Definition: catalog_rw.cc:391
std::vector< WritableCatalog * > WritableCatalogList
Definition: catalog_rw.h:194
SqlChunksRemove * sql_chunks_remove_
Definition: catalog_rw.h:150
void MakeTransitionPoint(const std::string &mountpoint)
Definition: catalog_rw.cc:364
SqlIncLinkcount * sql_inc_linkcount_
Definition: catalog_rw.h:153
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:171
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:254
bool IsWritable() const
Definition: catalog_rw.h:58
atomic_int32 dirty_children_
Definition: catalog_rw.h:160
SqlDirentUpdate * sql_update_
Definition: catalog_rw.h:148
void SetTTL(const uint64_t new_ttl)
Definition: catalog_rw.cc:323
SqlMaxHardlinkGroup * sql_max_link_id_
Definition: catalog_rw.h:152
PathString mountpoint() const
Definition: catalog.h:175
WritableCatalog(const std::string &path, const shash::Any &catalog_hash, Catalog *parent, const bool is_not_root=false)
Definition: catalog_rw.cc:27
static const double kMaximalRowIdWasteRatio
Definition: catalog_rw.h:109
void RemoveNestedCatalog(const std::string &mountpoint, Catalog **attached_reference)
Definition: catalog_rw.cc:536
bool SetVOMSAuthz(const std::string &voms_authz)
Definition: catalog_rw.cc:328
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:147
SqlDirentUnlink * sql_unlink_
Definition: catalog_rw.h:146
void SetBranch(const std::string &branch_name)
Definition: catalog_rw.cc:318
void Partition(WritableCatalog *new_nested_catalog)
Definition: catalog_rw.cc:344
void SetRevision(const uint64_t new_revision)
Definition: catalog_rw.cc:313
void MoveCatalogsToNested(const std::vector< std::string > &nested_catalogs, WritableCatalog *new_nested_catalog)
Definition: catalog_rw.cc:440
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:14
WritableCatalog * GetWritableParent() const
Definition: catalog_rw.h:130
DeltaCounters delta_counters_
Definition: catalog_rw.h:157
shash::Any hash() const
Definition: catalog.h:182
void RemoveEntry(const std::string &entry_path)
Definition: catalog_rw.cc:180
void UpdateEntry(const DirectoryEntry &entry, const std::string &path)
Definition: catalog_rw.h:116
virtual bool IsWritable() const
Definition: catalog.h:197
static void size_t size
Definition: smalloc.h:54
void IncLinkcount(const std::string &path_within_group, const int delta)
Definition: catalog_rw.cc:202
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:136
void UpdateEntry(const DirectoryEntry &entry, const shash::Md5 &path_hash)
Definition: catalog_rw.cc:244