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 <list>
36 #include <map>
37 #include <set>
38 #include <string>
39 #include <unordered_set>
40 #include <unordered_map>
41 
42 #include "catalog_mgr_ro.h"
43 #include "catalog_rw.h"
44 #include "file_chunk.h"
45 #include "upload_spooler_result.h"
46 #include "util/future.h"
47 #include "xattr.h"
48 #include "catalog_downloader.h"
49 #include "ingestion/pipeline.h"
50 
51 class XattrList;
52 namespace upload {
53 class Spooler;
54 }
55 
56 namespace download {
57 class DownloadManager;
58 }
59 
60 namespace manifest {
61 class Manifest;
62 }
63 
64 namespace perf {
65 class Statistics;
66 }
67 
68 namespace catalog {
69 template<class CatalogMgrT>
70 class CatalogBalancer;
71 }
72 
73 namespace catalog {
74 
77  // TODO(jblomer): only needed to get Spooler's hash algorithm. Remove me
78  // after refactoring of the swissknife utility.
79  friend class VirtualCatalog;
80 
81  public:
83  const std::string &stratum0,
84  const std::string &dir_temp,
85  upload::Spooler *spooler,
86  download::DownloadManager *download_manager,
87  bool enforce_limits,
88  const unsigned nested_kcatalog_limit,
89  const unsigned root_kcatalog_limit,
90  const unsigned file_mbyte_limit,
92  bool is_balanceable,
93  unsigned max_weight,
94  unsigned min_weight,
95  const std::string &dir_cache = "");
97  static manifest::Manifest *CreateRepository(const std::string &dir_temp,
98  const bool volatile_content,
99  const std::string &voms_authz,
100  upload::Spooler *spooler);
101 
102  // DirectoryEntry handling
103  void AddFile(const DirectoryEntryBase &entry,
104  const XattrList &xattrs,
105  const std::string &parent_directory) {
106  AddFile(DirectoryEntry(entry), xattrs, parent_directory);
107  }
108  void AddChunkedFile(const DirectoryEntryBase &entry,
109  const XattrList &xattrs,
110  const std::string &parent_directory,
111  const FileChunkList &file_chunks);
112  void RemoveFile(const std::string &file_path);
113 
114  void AddDirectory(const DirectoryEntryBase &entry,
115  const XattrList &xattrs,
116  const std::string &parent_directory);
117  void TouchDirectory(const DirectoryEntryBase &entry,
118  const XattrList &xattrs,
119  const std::string &directory_path);
120  void RemoveDirectory(const std::string &directory_path);
121 
122  void Clone(const std::string from, const std::string to);
123  void CloneTree(const std::string &from_dir, const std::string &to_dir);
124 
125  // Hardlink group handling
126  void AddHardlinkGroup(const DirectoryEntryBaseList &entries,
127  const XattrList &xattrs,
128  const std::string &parent_directory,
129  const FileChunkList &file_chunks);
130  void ShrinkHardlinkGroup(const std::string &remove_path);
131 
132  // Nested catalog handling
133  void CreateNestedCatalog(const std::string &mountpoint);
134  void RemoveNestedCatalog(const std::string &mountpoint,
135  const bool merge = true);
136  void SwapNestedCatalog(const string &mountpoint, const shash::Any &new_hash,
137  const uint64_t new_size);
138  void GraftNestedCatalog(const string &mountpoint, const shash::Any &new_hash,
139  const uint64_t new_size);
140  bool IsTransitionPoint(const std::string &mountpoint);
141  WritableCatalog *GetHostingCatalog(const std::string &path);
142 
143  inline bool IsBalanceable() const { return is_balanceable_; }
147  void PrecalculateListings();
148 
149  void SetTTL(const uint64_t new_ttl);
150  bool SetVOMSAuthz(const std::string &voms_authz);
151  bool Commit(const bool stop_for_tweaks,
152  const uint64_t manual_revision,
154 
155  void Balance() {
156  if (IsBalanceable()) {
157  DoBalance();
158  } else {
160  "Not balancing the catalog "
161  "manager because it is not balanceable");
162  }
163  }
164 
165  void LoadCatalogs(const std::string &base_path, const std::unordered_set<std::string> &dirs);
168  void AddCatalogToQueue(const std::string &path);
169  void ScheduleReadyCatalogs();
170  bool LookupDirEntry(const std::string &path,
171  const LookupOptions options,
172  DirectoryEntry *dirent);
173 
174 
175 
176  protected:
178 
179  Catalog *CreateCatalog(const PathString &mountpoint,
180  const shash::Any &catalog_hash,
181  Catalog *parent_catalog);
182  void ActivateCatalog(Catalog *catalog);
183 
184  void AddFile(const DirectoryEntry &entry,
185  const XattrList &xattrs,
186  const std::string &parent_directory);
187 
188  private:
189  bool FindCatalog(const std::string &path,
190  WritableCatalog **result,
191  DirectoryEntry *dirent = NULL);
192  void DoBalance();
193  void FixWeight(WritableCatalog *catalog);
194 
195  void CloneTreeImpl(const PathString &source_dir,
196  const std::string &dest_parent_dir,
197  const NameString &dest_name);
198 
199  struct CatalogInfo {
200  uint64_t ttl;
201  size_t size;
203  uint64_t revision;
204  };
205 
209  };
210 
212  const std::unordered_set<std::string> * dirs;
213  };
214 
216  const CatalogDownloadContext context);
218 
219 
220 
221  CatalogInfo SnapshotCatalogs(const bool stop_for_tweaks);
222  void FinalizeCatalog(WritableCatalog *catalog, const bool stop_for_tweaks);
224 
227  result);
228  assert(dirty);
229  }
231  WritableCatalogList *result) const;
232 
233  void CatalogUploadCallback(const upload::SpoolerResult &result,
234  const CatalogUploadContext clg_upload_context);
235 
237 
238  private:
239  inline void SyncLock() { pthread_mutex_lock(sync_lock_); }
240  inline void SyncUnlock() { pthread_mutex_unlock(sync_lock_); }
241 
242  //****************************************************************************
243  // Workaround -- Serialized Catalog Committing
245  const unsigned int
246  number_of_dirty_catalogs = GetModifiedCatalogsRecursively(
247  GetRootCatalog(), result);
248  assert(number_of_dirty_catalogs <= result->size());
249  }
250  int GetModifiedCatalogsRecursively(const Catalog *catalog,
251  WritableCatalogList *result) const;
253  const CatalogUploadContext unused);
254  CatalogInfo SnapshotCatalogsSerialized(const bool stop_for_tweaks);
256  const CompressHashResult &result);
257  //****************************************************************************
258 
259  // defined in catalog_mgr_rw.cc
260  static const std::string kCatalogFilename;
261 
262  // private lock of WritableCatalogManager
263  pthread_mutex_t *sync_lock_;
264  upload::Spooler *spooler_;
265 
266  pthread_mutex_t *catalog_processing_lock_;
267  std::map<std::string, WritableCatalog *> catalog_processing_map_;
268 
269  // ingestsql
270  std::list<WritableCatalog*> pending_catalogs_;
272  pthread_mutex_t *catalog_download_lock_;
273  std::unordered_map<std::string, Catalog*> catalog_download_map_;
274  pthread_mutex_t *catalog_hash_lock_;
275  std::map<std::string, shash::Any> catalog_hash_map_;
276 
277  // TODO(jblomer): catalog limits should become its own struct
282 
287 
291  const bool is_balanceable_;
292 
299  const unsigned max_weight_;
300 
308  const unsigned min_weight_;
309 
315  const unsigned balance_weight_;
316 }; // class WritableCatalogManager
317 
318 } // namespace catalog
319 
320 #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)
std::unordered_map< std::string, Catalog * > catalog_download_map_
void SingleCatalogUploadCallback(const upload::SpoolerResult &result)
void RemoveDirectory(const std::string &directory_path)
Definition: future.h:32
WritableCatalog * GetHostingCatalog(const std::string &path)
void FixWeight(WritableCatalog *catalog)
unsigned LookupOptions
Definition: catalog_mgr.h:42
void ScheduleCatalogProcessing(WritableCatalog *catalog)
pthread_mutex_t * catalog_download_lock_
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)
pthread_mutex_t * catalog_hash_lock_
void CatalogUploadCallback(const upload::SpoolerResult &result, const CatalogUploadContext clg_upload_context)
void TouchDirectory(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &directory_path)
CatalogDownloadPipeline * catalog_download_pipeline_
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
void AddCatalogToQueue(const std::string &path)
CatalogInfo SnapshotCatalogsSerialized(const bool stop_for_tweaks)
CatalogInfo SnapshotCatalogs(const bool stop_for_tweaks)
std::list< WritableCatalog * > pending_catalogs_
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
void LoadCatalogs(const std::string &base_path, const std::unordered_set< std::string > &dirs)
void CatalogDownloadCallback(const CatalogDownloadResult &result, const CatalogDownloadContext context)
std::map< std::string, shash::Any > catalog_hash_map_
std::vector< DirectoryEntryBase > DirectoryEntryBaseList
const int kLogVerboseMsg
void CatalogHashSerializedCallback(const CompressHashResult &result)
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)
bool LookupDirEntry(const std::string &path, const LookupOptions options, DirectoryEntry *dirent)
void CreateNestedCatalog(const std::string &mountpoint)
void GetModifiedCatalogs(WritableCatalogList *result) const
const std::unordered_set< std::string > * dirs
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545
const shash::Any & base_hash() const