CernVM-FS  2.11.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 unsigned int kFullHistory;
58  static const unsigned int 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 
80  unsigned int keep_history_depth;
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  unsigned int preserved_catalog_count() const { return preserved_catalogs_; }
97  unsigned int condemned_catalog_count() const { return condemned_catalogs_; }
98  unsigned int condemned_objects_count() const { return condemned_objects_; }
99  unsigned int 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 
161  unsigned int preserved_catalogs_;
166  unsigned int unreferenced_trees_;
170  unsigned int condemned_trees_;
174  unsigned int condemned_catalogs_;
179 
180  unsigned int condemned_objects_;
183 };
184 
185 #include "garbage_collector_impl.h"
186 
187 #endif // CVMFS_GARBAGE_COLLECTION_GARBAGE_COLLECTOR_H_
uint64_t condemned_bytes_count() const
HashFilterT hash_map_delete_requests_
unsigned int duplicate_delete_requests() const
unsigned int duplicate_delete_requests_
uint64_t oldest_trunk_catalog() const
unsigned int condemned_objects_
void LogDeletion(const shash::Any &hash) const
TraversalParameters GetTraversalParams(const Configuration &configuration)
ObjectFetcherTN::HistoryTN HistoryTN
void Sweep(const shash::Any &hash)
unsigned int condemned_trees_
CatalogTraversalT::Parameters TraversalParameters
unsigned int condemned_catalogs_
unsigned int unreferenced_trees_
CatalogTraversalT traversal_
CatalogTraversalT::CallbackDataTN TraversalCallbackDataTN
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
unsigned int preserved_catalogs_
CatalogTraversalT::ObjectFetcherTN ObjectFetcherTN
CatalogTraversalT::CatalogTN CatalogTN
HashFilterT hash_filter_
upload::AbstractUploader * uploader
static const unsigned int kFullHistory
unsigned int condemned_objects_count() const
bool RemoveCatalogFromReflog(const shash::Any &catalog)
Definition: mutex.h:42
void PreserveDataObjects(const TraversalCallbackDataTN &data)
const Configuration configuration_
void SweepDataObjects(const TraversalCallbackDataTN &data)
void CheckAndSweep(const shash::Any &hash)
std::vector< shash::Any > HashVector
unsigned int condemned_catalog_count() const
ReflogBasedInfoShim catalog_info_shim_
static const unsigned int kNoHistory
unsigned int preserved_catalog_count() const
GarbageCollector(const Configuration &configuration)