CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
catalog_mgr_rw.h
Go to the documentation of this file.
1 
29 #ifndef CVMFS_CATALOG_MGR_RW_H_
30 #define CVMFS_CATALOG_MGR_RW_H_
31 
32 #include <pthread.h>
33 #include <stdint.h>
34 
35 #include <map>
36 #include <set>
37 #include <string>
38 
39 #include "catalog_mgr_ro.h"
40 #include "catalog_rw.h"
41 #include "file_chunk.h"
42 #include "upload_spooler_result.h"
43 #include "util/future.h"
44 #include "xattr.h"
45 
46 class XattrList;
47 namespace upload {
48 class Spooler;
49 }
50 
51 namespace download {
52 class DownloadManager;
53 }
54 
55 namespace manifest {
56 class Manifest;
57 }
58 
59 namespace perf {
60 class Statistics;
61 }
62 
63 namespace catalog {
64 template<class CatalogMgrT>
65 class CatalogBalancer;
66 }
67 
68 namespace catalog {
69 
72  // TODO(jblomer): only needed to get Spooler's hash algorithm. Remove me
73  // after refactoring of the swissknife utility.
74  friend class VirtualCatalog;
75 
76  public:
78  const std::string &stratum0,
79  const std::string &dir_temp,
80  upload::Spooler *spooler,
81  download::DownloadManager *download_manager,
82  bool enforce_limits,
83  const unsigned nested_kcatalog_limit,
84  const unsigned root_kcatalog_limit,
85  const unsigned file_mbyte_limit,
87  bool is_balanceable,
88  unsigned max_weight,
89  unsigned min_weight,
90  const std::string &dir_cache = "");
92  static manifest::Manifest *CreateRepository(const std::string &dir_temp,
93  const bool volatile_content,
94  const std::string &voms_authz,
95  upload::Spooler *spooler);
96 
97  // DirectoryEntry handling
98  void AddFile(const DirectoryEntryBase &entry,
99  const XattrList &xattrs,
100  const std::string &parent_directory) {
101  AddFile(DirectoryEntry(entry), xattrs, parent_directory);
102  }
103  void AddChunkedFile(const DirectoryEntryBase &entry,
104  const XattrList &xattrs,
105  const std::string &parent_directory,
106  const FileChunkList &file_chunks);
107  void RemoveFile(const std::string &file_path);
108 
109  void AddDirectory(const DirectoryEntryBase &entry,
110  const XattrList &xattrs,
111  const std::string &parent_directory);
112  void TouchDirectory(const DirectoryEntryBase &entry,
113  const XattrList &xattrs,
114  const std::string &directory_path);
115  void RemoveDirectory(const std::string &directory_path);
116 
117  void Clone(const std::string from, const std::string to);
118  void CloneTree(const std::string &from_dir, const std::string &to_dir);
119 
120  // Hardlink group handling
121  void AddHardlinkGroup(const DirectoryEntryBaseList &entries,
122  const XattrList &xattrs,
123  const std::string &parent_directory,
124  const FileChunkList &file_chunks);
125  void ShrinkHardlinkGroup(const std::string &remove_path);
126 
127  // Nested catalog handling
128  void CreateNestedCatalog(const std::string &mountpoint);
129  void RemoveNestedCatalog(const std::string &mountpoint,
130  const bool merge = true);
131  void SwapNestedCatalog(const string &mountpoint, const shash::Any &new_hash,
132  const uint64_t new_size);
133  void GraftNestedCatalog(const string &mountpoint, const shash::Any &new_hash,
134  const uint64_t new_size);
135  bool IsTransitionPoint(const std::string &mountpoint);
136  WritableCatalog *GetHostingCatalog(const std::string &path);
137 
138  inline bool IsBalanceable() const { return is_balanceable_; }
142  void PrecalculateListings();
143 
144  void SetTTL(const uint64_t new_ttl);
145  bool SetVOMSAuthz(const std::string &voms_authz);
146  bool Commit(const bool stop_for_tweaks,
147  const uint64_t manual_revision,
149 
150  void Balance() {
151  if (IsBalanceable()) {
152  DoBalance();
153  } else {
155  "Not balancing the catalog "
156  "manager because it is not balanceable");
157  }
158  }
159 
160  protected:
162 
163  Catalog *CreateCatalog(const PathString &mountpoint,
164  const shash::Any &catalog_hash,
165  Catalog *parent_catalog);
166  void ActivateCatalog(Catalog *catalog);
167 
168  void AddFile(const DirectoryEntry &entry,
169  const XattrList &xattrs,
170  const std::string &parent_directory);
171 
172  private:
173  bool FindCatalog(const std::string &path,
174  WritableCatalog **result,
175  DirectoryEntry *dirent = NULL);
176  void DoBalance();
177  void FixWeight(WritableCatalog *catalog);
178 
179  void CloneTreeImpl(const PathString &source_dir,
180  const std::string &dest_parent_dir,
181  const NameString &dest_name);
182 
183  struct CatalogInfo {
184  uint64_t ttl;
185  size_t size;
187  uint64_t revision;
188  };
189 
193  };
194 
195  CatalogInfo SnapshotCatalogs(const bool stop_for_tweaks);
196  void FinalizeCatalog(WritableCatalog *catalog, const bool stop_for_tweaks);
198 
201  result);
202  assert(dirty);
203  }
205  WritableCatalogList *result) const;
206 
207  void CatalogUploadCallback(const upload::SpoolerResult &result,
208  const CatalogUploadContext clg_upload_context);
209 
211 
212  private:
213  inline void SyncLock() { pthread_mutex_lock(sync_lock_); }
214  inline void SyncUnlock() { pthread_mutex_unlock(sync_lock_); }
215 
216  //****************************************************************************
217  // Workaround -- Serialized Catalog Committing
219  const unsigned int
220  number_of_dirty_catalogs = GetModifiedCatalogsRecursively(
221  GetRootCatalog(), result);
222  assert(number_of_dirty_catalogs <= result->size());
223  }
224  int GetModifiedCatalogsRecursively(const Catalog *catalog,
225  WritableCatalogList *result) const;
227  const CatalogUploadContext unused);
228  CatalogInfo SnapshotCatalogsSerialized(const bool stop_for_tweaks);
229  //****************************************************************************
230 
231  // defined in catalog_mgr_rw.cc
232  static const std::string kCatalogFilename;
233 
234  // private lock of WritableCatalogManager
235  pthread_mutex_t *sync_lock_;
236  upload::Spooler *spooler_;
237 
238  pthread_mutex_t *catalog_processing_lock_;
239  std::map<std::string, WritableCatalog *> catalog_processing_map_;
240 
241  // TODO(jblomer): catalog limits should become its own struct
246 
251 
255  const bool is_balanceable_;
256 
263  const unsigned max_weight_;
264 
272  const unsigned min_weight_;
273 
279  const unsigned balance_weight_;
280 }; // class WritableCatalogManager
281 
282 } // namespace catalog
283 
284 #endif // CVMFS_CATALOG_MGR_RW_H_
void AddChunkedFile(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &parent_directory, const FileChunkList &file_chunks)
const manifest::Manifest * manifest() const
Definition: repository.h:125
void CloneTree(const std::string &from_dir, const std::string &to_dir)
void AddHardlinkGroup(const DirectoryEntryBaseList &entries, const XattrList &xattrs, const std::string &parent_directory, const FileChunkList &file_chunks)
void AddDirectory(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &parent_directory)
void RemoveDirectory(const std::string &directory_path)
Definition: future.h:32
WritableCatalog * GetHostingCatalog(const std::string &path)
void FixWeight(WritableCatalog *catalog)
void ScheduleCatalogProcessing(WritableCatalog *catalog)
void SetTTL(const uint64_t new_ttl)
int GetModifiedCatalogsRecursively(const Catalog *catalog, WritableCatalogList *result) const
assert((mem||(size==0))&&"Out Of Memory")
bool FindCatalog(const std::string &path, WritableCatalog **result, DirectoryEntry *dirent=NULL)
bool Commit(const bool stop_for_tweaks, const uint64_t manual_revision, manifest::Manifest *manifest)
pthread_mutex_t * catalog_processing_lock_
std::map< std::string, WritableCatalog * > catalog_processing_map_
std::vector< WritableCatalog * > WritableCatalogList
Definition: catalog_rw.h:194
void CloneTreeImpl(const PathString &source_dir, const std::string &dest_parent_dir, const NameString &dest_name)
bool IsTransitionPoint(const std::string &mountpoint)
void CatalogUploadCallback(const upload::SpoolerResult &result, const CatalogUploadContext clg_upload_context)
void TouchDirectory(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &directory_path)
static manifest::Manifest * CreateRepository(const std::string &dir_temp, const bool volatile_content, const std::string &voms_authz, upload::Spooler *spooler)
void ActivateCatalog(Catalog *catalog)
WritableCatalogManager(const shash::Any &base_hash, const std::string &stratum0, const std::string &dir_temp, upload::Spooler *spooler, download::DownloadManager *download_manager, bool enforce_limits, const unsigned nested_kcatalog_limit, const unsigned root_kcatalog_limit, const unsigned file_mbyte_limit, perf::Statistics *statistics, bool is_balanceable, unsigned max_weight, unsigned min_weight, const std::string &dir_cache="")
void ShrinkHardlinkGroup(const std::string &remove_path)
bool CopyCatalogToLocalCache(const upload::SpoolerResult &result)
bool GetModifiedCatalogLeafsRecursively(Catalog *catalog, WritableCatalogList *result) const
const std::string & dir_temp() const
CatalogInfo SnapshotCatalogsSerialized(const bool stop_for_tweaks)
CatalogInfo SnapshotCatalogs(const bool stop_for_tweaks)
bool SetVOMSAuthz(const std::string &voms_authz)
void Clone(const std::string from, const std::string to)
void RemoveFile(const std::string &file_path)
void CatalogUploadSerializedCallback(const upload::SpoolerResult &result, const CatalogUploadContext unused)
void RemoveNestedCatalog(const std::string &mountpoint, const bool merge=true)
static const std::string kCatalogFilename
std::vector< DirectoryEntryBase > DirectoryEntryBaseList
const int kLogVerboseMsg
void AddFile(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &parent_directory)
void SwapNestedCatalog(const string &mountpoint, const shash::Any &new_hash, const uint64_t new_size)
static void size_t size
Definition: smalloc.h:54
void GetModifiedCatalogLeafs(WritableCatalogList *result) const
Catalog * CreateCatalog(const PathString &mountpoint, const shash::Any &catalog_hash, Catalog *parent_catalog)
void FinalizeCatalog(WritableCatalog *catalog, const bool stop_for_tweaks)
void GraftNestedCatalog(const string &mountpoint, const shash::Any &new_hash, const uint64_t new_size)
void CreateNestedCatalog(const std::string &mountpoint)
void GetModifiedCatalogs(WritableCatalogList *result) const
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545
const shash::Any & base_hash() const