CernVM-FS  2.12.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  uint64_t condemned_bytes_count() const { return condemned_bytes_; }
102  uint64_t oldest_trunk_catalog() const { return oldest_trunk_catalog_; }
103 
104  protected:
105  TraversalParameters GetTraversalParams(const Configuration &configuration);
106 
108  void SweepDataObjects(const TraversalCallbackDataTN &data);
109 
112  bool SweepReflog();
113 
114  void CheckAndSweep(const shash::Any &hash);
115  void Sweep(const shash::Any &hash);
116  bool RemoveCatalogFromReflog(const shash::Any &catalog);
117 
118  void PrintCatalogTreeEntry(const unsigned int tree_level,
119  const CatalogTN *catalog) const;
120  void LogDeletion(const shash::Any &hash) const;
121 
122  private:
124  public swissknife::CatalogTraversalInfoShim<CatalogTN>
125  {
126  public:
128  pthread_mutex_init(&reflog_mutex_, NULL);
129  }
131  pthread_mutex_destroy(&reflog_mutex_);
132  }
133  virtual uint64_t GetLastModified(const CatalogTN *catalog) {
134  uint64_t timestamp;
136  bool retval = reflog_->GetCatalogTimestamp(catalog->hash(), &timestamp);
137  return retval ? timestamp : catalog->GetLastModified();
138  }
139 
140  private:
142  pthread_mutex_t reflog_mutex_;
143  };
144 
147  CatalogTraversalT traversal_;
148  HashFilterT hash_filter_;
150 
151 
179 
183 };
184 
185 #include "garbage_collector_impl.h"
186 
187 #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)