CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gc_aux_impl.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_GARBAGE_COLLECTION_GC_AUX_IMPL_H_
6 #define CVMFS_GARBAGE_COLLECTION_GC_AUX_IMPL_H_
7 
8 #include <cstdio>
9 #include <string>
10 #include <vector>
11 
12 #include "util/logging.h"
13 #include "util/string.h"
14 
15 template<class CatalogTraversalT, class HashFilterT>
17  const ConfigurationTN &config)
18  : config_(config) {
19  assert(config_.uploader != NULL);
20 }
21 
22 
23 template<class CatalogTraversalT, class HashFilterT>
25  uint64_t timestamp, const HashFilterT &preserved_objects) {
26  if (config_.verbose) {
28  "Sweeping auxiliary objects older than %s",
29  StringifyTime(timestamp, true).c_str());
30  }
31  std::vector<SqlReflog::ReferenceType> aux_types;
32  aux_types.push_back(SqlReflog::kRefCertificate);
33  aux_types.push_back(SqlReflog::kRefHistory);
34  aux_types.push_back(SqlReflog::kRefMetainfo);
35  for (unsigned i = 0; i < aux_types.size(); ++i) {
36  std::vector<shash::Any> hashes;
37  bool retval = config_.reflog->ListOlderThan(aux_types[i], timestamp,
38  &hashes);
39  if (!retval) {
40  LogCvmfs(kLogGc, kLogStderr, "failed to enumerate %s objects",
41  PrintAuxType(aux_types[i]).c_str());
42  return 1;
43  }
44  if (config_.verbose) {
45  LogCvmfs(kLogGc, kLogStdout | kLogDebug, "Scanning %lu %s objects",
46  hashes.size(), PrintAuxType(aux_types[i]).c_str());
47  }
48 
49  for (unsigned iter = 0; iter < hashes.size(); ++iter) {
50  if (preserved_objects.Contains(hashes[iter])) {
51  if (config_.verbose) {
52  LogCvmfs(kLogGc, kLogStdout | kLogDebug, " preserving: %s",
53  hashes[iter].ToStringWithSuffix().c_str());
54  }
55  continue;
56  }
57 
58  if (!Sweep(hashes[iter]))
59  return false;
60  }
61  }
62 
63  config_.uploader->WaitForUpload();
64  return config_.uploader->GetNumberOfErrors() == 0;
65 }
66 
67 
68 template<class CatalogTraversalT, class HashFilterT>
71  switch (type) {
73  return "file catalog";
75  return "certificate";
77  return "tag database";
79  return "repository meta information";
80  }
81  // Never here
82  return "UNKNOWN";
83 }
84 
85 
86 template<class CatalogTraversalT, class HashFilterT>
88  const shash::Any &hash) {
89  if (config_.verbose) {
90  LogCvmfs(kLogGc, kLogStdout | kLogDebug, " sweep: %s",
91  hash.ToStringWithSuffix().c_str());
92  }
93 
94  if (!config_.dry_run) {
95  config_.uploader->RemoveAsync(hash);
96  bool retval = config_.reflog->Remove(hash);
97  if (!retval) {
98  LogCvmfs(kLogGc, kLogStderr, "failed to remove %s from reference log",
99  hash.ToStringWithSuffix().c_str());
100  return false;
101  }
102  }
103 
104  if (config_.has_deletion_log()) {
105  const int written = fprintf(config_.deleted_objects_logfile, "%s\n",
106  hash.ToStringWithSuffix().c_str());
107  if (written < 0) {
108  LogCvmfs(kLogGc, kLogStderr, "failed to write to deleted objects log");
109  return false;
110  }
111  }
112 
113  return true;
114 }
115 
116 #endif // CVMFS_GARBAGE_COLLECTION_GC_AUX_IMPL_H_
std::string PrintAuxType(SqlReflog::ReferenceType type)
Definition: gc_aux_impl.h:69
GarbageCollectorAux(const ConfigurationTN &config)
Definition: gc_aux_impl.h:16
std::string ToStringWithSuffix() const
Definition: hash.h:296
assert((mem||(size==0))&&"Out Of Memory")
string StringifyTime(const time_t seconds, const bool utc)
Definition: string.cc:104
bool Sweep(const shash::Any &hash)
Definition: gc_aux_impl.h:87
upload::AbstractUploader * uploader
bool CollectOlderThan(uint64_t timestamp, const HashFilterT &preserved_objects)
Definition: gc_aux_impl.h:24
const ConfigurationTN config_
Definition: gc_aux.h:51
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545