8 #include "cvmfs_config.h"
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 int64_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) ?
87 "at least one revision needs to be preserved");
94 "neither a timestamp nor history threshold given");
98 const bool follow_redirects =
false;
99 const std::string proxy = ((args.count(
'@') > 0) ?
100 *args.find(
'@')->second :
"");
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 "(errno: %d)", errno);
148 uploader->TearDown();
162 config.
verbose = list_condemned_objects;
170 if (deletion_log_file != NULL) {
171 const int bytes_written = fprintf(deletion_log_file,
172 "# Garbage Collection started at %s\n",
174 if (bytes_written < 0) {
177 deletion_log_path.c_str(), errno);
178 uploader->TearDown();
186 GC collector(config);
188 bool success = collector.
Collect();
194 if (upload_statsdb) {
198 uploader->TearDown();
204 preserved_objects.
Fill(manifest->certificate());
205 preserved_objects.
Fill(manifest->history());
206 preserved_objects.
Fill(manifest->meta_info());
207 GCAux collector_aux(config);
212 "garbage collection of auxiliary files failed");
215 if (upload_statsdb) {
219 uploader->TearDown();
225 if (deletion_log_file != NULL) {
226 const int bytes_written = fprintf(deletion_log_file,
227 "# Garbage Collection finished at %s\n\n",
229 assert(bytes_written >= 0);
230 fclose(deletion_log_file);
235 success = reflog->
Vacuum();
242 uploader->UploadFile(reflog_db,
".cvmfsreflog");
244 uploader->WaitForUpload();
248 unlink(reflog_db.c_str());
250 if (uploader->GetNumberOfErrors() > 0 && !dry_run) {
254 if (upload_statsdb) {
258 uploader->TearDown();
264 if (upload_statsdb) {
268 uploader->TearDown();
static Parameter Optional(const char key, const std::string &desc)
#define LogCvmfs(source, mask,...)
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
static const unsigned int kFullHistory
void DropDatabaseFileOwnership()
static StatisticsDatabase * OpenStandardDB(const std::string repo_name)
bool DirectoryExists(const std::string &path)
static bool GcExtendedStats(const std::string &repo_name)
SmallhashFilter HashFilter
unsigned int keep_history_depth
bool CollectOlderThan(uint64_t timestamp, const HashFilterT &preserved_objects)
uint64_t String2Uint64(const string &value)
std::map< char, SharedPtr< std::string > > ArgumentList
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)