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)
69 const time_t timestamp = (args.count(
'z') > 0)
70 ? static_cast<time_t>(
73 std::string repo_keys = (args.count(
'k') > 0) ? *args.find(
'k')->second :
"";
76 const bool dry_run = (args.count(
'd') > 0);
77 const bool list_condemned_objects = (args.count(
'l') > 0);
78 const std::string temp_directory = (args.count(
't') > 0)
79 ? *args.find(
't')->second
81 const std::string deletion_log_path = (args.count(
'L') > 0)
82 ? *args.find(
'L')->second
84 const bool upload_statsdb = (args.count(
'I') > 0);
85 const unsigned int num_threads = (args.count(
'N') > 0)
92 "neither a timestamp nor history threshold given");
96 const bool follow_redirects =
false;
97 const std::string proxy = ((args.count(
'@') > 0) ? *args.find(
'@')->second
116 "failed to load repository manifest "
122 if (!manifest->garbage_collectable()) {
124 "repository does not allow garbage collection");
129 reflog =
FetchReflog(&object_fetcher, repo_name, reflog_hash);
142 FILE *deletion_log_file = NULL;
143 if (!deletion_log_path.empty()) {
144 deletion_log_file = fopen(deletion_log_path.c_str(),
"a+");
145 if (NULL == deletion_log_file) {
147 "failed to open deletion log file "
150 uploader->TearDown();
164 config.
verbose = list_condemned_objects;
172 if (deletion_log_file != NULL) {
173 const int bytes_written = fprintf(deletion_log_file,
174 "# Garbage Collection started at %s\n",
176 if (bytes_written < 0) {
178 "failed to write to deletion log '%s' "
180 deletion_log_path.c_str(), errno);
181 uploader->TearDown();
189 GC collector(config);
191 bool success = collector.
Collect();
197 if (upload_statsdb) {
201 uploader->TearDown();
207 preserved_objects.
Fill(manifest->certificate());
208 preserved_objects.
Fill(manifest->history());
209 preserved_objects.
Fill(manifest->meta_info());
210 GCAux collector_aux(config);
215 "garbage collection of auxiliary files failed");
218 if (upload_statsdb) {
222 uploader->TearDown();
228 if (deletion_log_file != NULL) {
229 const int bytes_written = fprintf(deletion_log_file,
230 "# Garbage Collection finished at %s\n\n",
232 assert(bytes_written >= 0);
233 fclose(deletion_log_file);
238 success = reflog->
Vacuum();
245 uploader->UploadFile(reflog_db,
".cvmfsreflog");
247 uploader->WaitForUpload();
251 unlink(reflog_db.c_str());
253 if (uploader->GetNumberOfErrors() > 0 && !dry_run) {
257 if (upload_statsdb) {
261 uploader->TearDown();
267 if (upload_statsdb) {
271 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,...)