| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 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> |
| 16 |
|
✗ |
GarbageCollectorAux<CatalogTraversalT, HashFilterT>::GarbageCollectorAux( |
| 17 |
|
|
const ConfigurationTN &config) |
| 18 |
|
✗ |
: config_(config) { |
| 19 |
|
✗ |
assert(config_.uploader != NULL); |
| 20 |
|
|
} |
| 21 |
|
|
|
| 22 |
|
|
|
| 23 |
|
|
template<class CatalogTraversalT, class HashFilterT> |
| 24 |
|
✗ |
bool GarbageCollectorAux<CatalogTraversalT, HashFilterT>::CollectOlderThan( |
| 25 |
|
|
uint64_t timestamp, const HashFilterT &preserved_objects) { |
| 26 |
|
✗ |
if (config_.verbose) { |
| 27 |
|
✗ |
LogCvmfs(kLogGc, kLogStdout | kLogDebug, |
| 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> |
| 69 |
|
✗ |
std::string GarbageCollectorAux<CatalogTraversalT, HashFilterT>::PrintAuxType( |
| 70 |
|
|
SqlReflog::ReferenceType type) { |
| 71 |
|
✗ |
switch (type) { |
| 72 |
|
✗ |
case SqlReflog::kRefCatalog: |
| 73 |
|
✗ |
return "file catalog"; |
| 74 |
|
✗ |
case SqlReflog::kRefCertificate: |
| 75 |
|
✗ |
return "certificate"; |
| 76 |
|
✗ |
case SqlReflog::kRefHistory: |
| 77 |
|
✗ |
return "tag database"; |
| 78 |
|
✗ |
case SqlReflog::kRefMetainfo: |
| 79 |
|
✗ |
return "repository meta information"; |
| 80 |
|
|
} |
| 81 |
|
|
// Never here |
| 82 |
|
✗ |
return "UNKNOWN"; |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
|
| 86 |
|
|
template<class CatalogTraversalT, class HashFilterT> |
| 87 |
|
✗ |
bool GarbageCollectorAux<CatalogTraversalT, HashFilterT>::Sweep( |
| 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_ |
| 117 |
|
|
|