CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
garbage_collector.h
Go to the documentation of this file.
1 
32 #ifndef CVMFS_GARBAGE_COLLECTION_GARBAGE_COLLECTOR_H_
33 #define CVMFS_GARBAGE_COLLECTION_GARBAGE_COLLECTOR_H_
34 
35 #include <inttypes.h>
36 
37 #include <vector>
38 
41 #include "statistics.h"
42 #include "upload_facility.h"
43 
44 template<class CatalogTraversalT, class HashFilterT>
46  protected:
47  typedef typename CatalogTraversalT::ObjectFetcherTN ObjectFetcherTN;
48  typedef typename ObjectFetcherTN::HistoryTN HistoryTN;
49  typedef typename ObjectFetcherTN::ReflogTN ReflogTN;
50  typedef typename CatalogTraversalT::CatalogTN CatalogTN;
51  typedef typename CatalogTraversalT::CallbackDataTN TraversalCallbackDataTN;
52  typedef typename CatalogTraversalT::Parameters TraversalParameters;
53  typedef std::vector<shash::Any> HashVector;
54 
55  public:
56  struct Configuration {
57  static const uint64_t kFullHistory;
58  static const uint64_t kNoHistory;
59  static const time_t kNoTimestamp;
61 
63  : uploader(NULL)
64  , object_fetcher(NULL)
65  , reflog(NULL)
68  , dry_run(false)
69  , verbose(false)
71  , statistics(NULL)
72  , extended_stats(false)
73  , num_threads(8) { }
74 
75  bool has_deletion_log() const { return deleted_objects_logfile != NULL; }
76 
82  bool dry_run;
83  bool verbose;
87  unsigned int num_threads;
88  };
89 
90  public:
91  explicit GarbageCollector(const Configuration &configuration);
92 
93  void UseReflogTimestamps();
94  bool Collect();
95 
96  uint64_t preserved_catalog_count() const { return preserved_catalogs_; }
97  uint64_t condemned_catalog_count() const { return condemned_catalogs_; }
98  uint64_t condemned_objects_count() const { return condemned_objects_; }
99  uint64_t duplicate_delete_requests() const {
101  }
102  uint64_t condemned_bytes_count() const { return condemned_bytes_; }
103  uint64_t oldest_trunk_catalog() const { return oldest_trunk_catalog_; }
104 
105  protected:
106  TraversalParameters GetTraversalParams(const Configuration &configuration);
107 
109  void SweepDataObjects(const TraversalCallbackDataTN &data);
110 
113  bool SweepReflog();
114 
115  void CheckAndSweep(const shash::Any &hash);
116  void Sweep(const shash::Any &hash);
117  bool RemoveCatalogFromReflog(const shash::Any &catalog);
118 
119  void PrintCatalogTreeEntry(const unsigned int tree_level,
120  const CatalogTN *catalog) const;
121  void LogDeletion(const shash::Any &hash) const;
122 
123  private:
125  : public swissknife::CatalogTraversalInfoShim<CatalogTN> {
126  public:
128  pthread_mutex_init(&reflog_mutex_, NULL);
129  }
130  virtual ~ReflogBasedInfoShim() { pthread_mutex_destroy(&reflog_mutex_); }
131  virtual uint64_t GetLastModified(const CatalogTN *catalog) {
132  uint64_t timestamp;
134  bool retval = reflog_->GetCatalogTimestamp(catalog->hash(), &timestamp);
135  return retval ? timestamp : catalog->GetLastModified();
136  }
137 
138  private:
140  pthread_mutex_t reflog_mutex_;
141  };
142 
145  CatalogTraversalT traversal_;
146  HashFilterT hash_filter_;
148 
149 
177 
181 };
182 
183 #include "garbage_collector_impl.h"
184 
185 #endif // CVMFS_GARBAGE_COLLECTION_GARBAGE_COLLECTOR_H_
uint64_t condemned_bytes_count() const
uint64_t unreferenced_trees_
uint64_t condemned_catalogs_
HashFilterT hash_map_delete_requests_
uint64_t duplicate_delete_requests_
uint64_t condemned_catalog_count() const
uint64_t oldest_trunk_catalog() const
void LogDeletion(const shash::Any &hash) const
TraversalParameters GetTraversalParams(const Configuration &configuration)
ObjectFetcherTN::HistoryTN HistoryTN
void Sweep(const shash::Any &hash)
CatalogTraversalT::Parameters TraversalParameters
CatalogTraversalT traversal_
uint64_t preserved_catalog_count() const
CatalogTraversalT::CallbackDataTN TraversalCallbackDataTN
static const uint64_t kNoHistory
void PrintCatalogTreeEntry(const unsigned int tree_level, const CatalogTN *catalog) const
virtual uint64_t GetLastModified(const CatalogTN *catalog)
static const shash::Any kLatestHistoryDatabase
uint64_t oldest_trunk_catalog_
ObjectFetcherTN::ReflogTN ReflogTN
uint64_t condemned_objects_count() const
CatalogTraversalT::ObjectFetcherTN ObjectFetcherTN
CatalogTraversalT::CatalogTN CatalogTN
uint64_t duplicate_delete_requests() const
HashFilterT hash_filter_
upload::AbstractUploader * uploader
uint64_t preserved_catalogs_
bool RemoveCatalogFromReflog(const shash::Any &catalog)
Definition: mutex.h:42
static const uint64_t kFullHistory
void PreserveDataObjects(const TraversalCallbackDataTN &data)
const Configuration configuration_
void SweepDataObjects(const TraversalCallbackDataTN &data)
void CheckAndSweep(const shash::Any &hash)
std::vector< shash::Any > HashVector
ReflogBasedInfoShim catalog_info_shim_
GarbageCollector(const Configuration &configuration)