CernVM-FS  2.10.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  uint64_t condemned_bytes_count() const { return condemned_bytes_; }
100  uint64_t oldest_trunk_catalog() const { return oldest_trunk_catalog_; }
101 
102  protected:
103  TraversalParameters GetTraversalParams(const Configuration &configuration);
104 
106  void SweepDataObjects(const TraversalCallbackDataTN &data);
107 
110  bool SweepReflog();
111 
112  void CheckAndSweep(const shash::Any &hash);
113  void Sweep(const shash::Any &hash);
114  bool RemoveCatalogFromReflog(const shash::Any &catalog);
115 
116  void PrintCatalogTreeEntry(const unsigned int tree_level,
117  const CatalogTN *catalog) const;
118  void LogDeletion(const shash::Any &hash) const;
119 
120  private:
122  public swissknife::CatalogTraversalInfoShim<CatalogTN>
123  {
124  public:
126  pthread_mutex_init(&reflog_mutex_, NULL);
127  }
129  pthread_mutex_destroy(&reflog_mutex_);
130  }
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_;
147 
157  unsigned int preserved_catalogs_;
162  unsigned int unreferenced_trees_;
166  unsigned int condemned_trees_;
170  unsigned int condemned_catalogs_;
175 
176  unsigned int condemned_objects_;
178 };
179 
180 #include "garbage_collector_impl.h"
181 
182 #endif // CVMFS_GARBAGE_COLLECTION_GARBAGE_COLLECTOR_H_
uint64_t condemned_bytes_count() const
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)