23 namespace swissknife {
56 const std::string &repo_url = *args.find(
'r')->second;
57 const std::string &
spooler = *args.find(
'u')->second;
58 const std::string &repo_name = *args.find(
'n')->second;
59 const std::string &reflog_chksum_path = *args.find(
'R')->second;
66 const uint64_t revisions = (args.count(
'h') > 0) ?
68 const time_t timestamp = (args.count(
'z') > 0)
69 ? static_cast<time_t>(
String2Int64(*args.find(
'z')->second))
71 std::string repo_keys = (args.count(
'k') > 0) ?
72 *args.find(
'k')->second :
"";
75 const bool dry_run = (args.count(
'd') > 0);
76 const bool list_condemned_objects = (args.count(
'l') > 0);
77 const std::string temp_directory = (args.count(
't') > 0) ?
78 *args.find(
't')->second :
"/tmp";
79 const std::string deletion_log_path = (args.count(
'L') > 0) ?
80 *args.find(
'L')->second :
"";
81 const bool upload_statsdb = (args.count(
'I') > 0);
82 const unsigned int num_threads = (args.count(
'N') > 0) ?
88 "neither a timestamp nor history threshold given");
92 const bool follow_redirects =
false;
93 const std::string proxy = ((args.count(
'@') > 0) ?
94 *args.find(
'@')->second :
"");
116 if (!manifest->garbage_collectable()) {
118 "repository does not allow garbage collection");
123 reflog =
FetchReflog(&object_fetcher, repo_name, reflog_hash);
136 FILE *deletion_log_file = NULL;
137 if (!deletion_log_path.empty()) {
138 deletion_log_file = fopen(deletion_log_path.c_str(),
"a+");
139 if (NULL == deletion_log_file) {
141 "(errno: %d)", errno);
142 uploader->TearDown();
156 config.
verbose = list_condemned_objects;
164 if (deletion_log_file != NULL) {
165 const int bytes_written = fprintf(deletion_log_file,
166 "# Garbage Collection started at %s\n",
168 if (bytes_written < 0) {
171 deletion_log_path.c_str(), errno);
172 uploader->TearDown();
180 GC collector(config);
182 bool success = collector.
Collect();
188 if (upload_statsdb) {
192 uploader->TearDown();
198 preserved_objects.
Fill(manifest->certificate());
199 preserved_objects.
Fill(manifest->history());
200 preserved_objects.
Fill(manifest->meta_info());
201 GCAux collector_aux(config);
206 "garbage collection of auxiliary files failed");
209 if (upload_statsdb) {
213 uploader->TearDown();
219 if (deletion_log_file != NULL) {
220 const int bytes_written = fprintf(deletion_log_file,
221 "# Garbage Collection finished at %s\n\n",
223 assert(bytes_written >= 0);
224 fclose(deletion_log_file);
229 success = reflog->
Vacuum();
236 uploader->UploadFile(reflog_db,
".cvmfsreflog");
238 uploader->WaitForUpload();
242 unlink(reflog_db.c_str());
244 if (uploader->GetNumberOfErrors() > 0 && !dry_run) {
248 if (upload_statsdb) {
252 uploader->TearDown();
258 if (upload_statsdb) {
262 uploader->TearDown();
static Parameter Optional(const char key, const std::string &desc)
const char * Code2Ascii(const ObjectFetcherFailures::Failures error)
std::string database_file() const
const manifest::Manifest * manifest() const
static Parameter Switch(const char key, const std::string &desc)
std::string GetGMTimestamp(const std::string &format)
bool UploadStatistics(upload::Spooler *spooler, std::string local_path="")
static bool ReadChecksum(const std::string &path, shash::Any *checksum)
bool StoreGCStatistics(const perf::Statistics *statistics, const std::string &start_time, const bool success)
std::vector< Parameter > ParameterList
string JoinStrings(const vector< string > &strings, const string &joint)
FILE * deleted_objects_logfile
void UseReflogTimestamps()
uint64_t oldest_trunk_catalog() const
CatalogTraversalParallel< ObjectFetcher > ReadonlyCatalogTraversal
GarbageCollectorAux< ReadonlyCatalogTraversal, HashFilter > GCAux
ObjectFetcherTN * object_fetcher
assert((mem||(size==0))&&"Out Of Memory")
perf::Statistics * statistics
upload::Spooler * spooler
GarbageCollector< ReadonlyCatalogTraversal, HashFilter > GC
string StringifyTime(const time_t seconds, const bool utc)
virtual ParameterList GetParams() const
void Fill(const shash::Any &hash)
static AbstractUploader * Construct(const SpoolerDefinition ¶m)
int64_t String2Int64(const string &value)
static Parameter Mandatory(const char key, const std::string &desc)
int Main(const ArgumentList &args)
static void HashDatabase(const std::string &database_path, shash::Any *hash_reflog)
manifest::Reflog * reflog
upload::AbstractUploader * uploader
static const time_t kNoTimestamp
void DropDatabaseFileOwnership()
static StatisticsDatabase * OpenStandardDB(const std::string repo_name)
bool DirectoryExists(const std::string &path)
static bool GcExtendedStats(const std::string &repo_name)
uint64_t keep_history_depth
SmallhashFilter HashFilter
bool CollectOlderThan(uint64_t timestamp, const HashFilterT &preserved_objects)
uint64_t String2Uint64(const string &value)
std::map< char, SharedPtr< std::string > > ArgumentList
static const uint64_t kFullHistory
HttpObjectFetcher ObjectFetcher
Failures FetchManifest(manifest::Manifest **manifest)
time_t keep_history_timestamp
static bool WriteChecksum(const std::string &path, const shash::Any &value)
GC::Configuration GcConfig
std::vector< std::string > FindFilesBySuffix(const std::string &dir, const std::string &suffix)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)