5 #ifndef CVMFS_CATALOG_TRAVERSAL_H_
6 #define CVMFS_CATALOG_TRAVERSAL_H_
26 class WritableCatalog;
29 namespace swissknife {
42 template<
class CatalogT>
50 , catalog_hash(catalog_hash)
51 , tree_level(tree_level)
52 , file_size(file_size)
53 , history_depth(history_depth) { }
70 template<
class CatalogT>
77 return catalog->GetLastModified();
87 template<
class ObjectFetcherT>
90 CatalogTraversalData<typename ObjectFetcherT::CatalogTN> > {
93 typedef typename ObjectFetcherT::CatalogTN
CatalogTN;
94 typedef typename ObjectFetcherT::HistoryTN
HistoryTN;
212 virtual bool TraverseList(
const std::vector<shash::Any> &catalog_list,
236 typedef std::vector<shash::Any> HashList;
247 "didn't find a history database to traverse");
252 "failed to download history database (%d - %s)", retval,
257 HashList root_hashes;
258 bool success = tag_db->GetHashes(&root_hashes);
282 , tree_level(tree_level)
283 , history_depth(history_depth)
328 "ignoring missing catalog "
329 "%s (swept before?)",
337 "failed to load catalog %s "
346 job->
catalog->DropDatabaseFileOwnership();
367 "failed to re-open catalog %s", job->
hash.
ToString().c_str());
398 "failed to load manifest "
405 return manifest->catalog_hash();
418 const uint64_t history_depth,
424 assert(timestamp_threshold >= 0);
426 < unsigned(timestamp_threshold);
494 template<
class ObjectFetcherT>
524 : history_depth(history_depth)
525 , timestamp_threshold(timestamp_threshold)
526 , traversal_type(traversal_type) { }
545 if (root_catalog_hash.
IsNull()) {
557 Push(root_catalog_hash, &ctx);
563 std::vector<shash::Any>::const_iterator i = catalog_list.begin();
564 const std::vector<shash::Any>::const_iterator iend = catalog_list.end();
566 for (; i != iend; ++i) {
577 Push(root_catalog_hash, &ctx);
694 if (previous_revision.
IsNull()) {
717 typedef typename CatalogTN::NestedCatalogList NestedCatalogList;
718 const NestedCatalogList nested = job.
catalog->ListOwnNestedCatalogs();
719 typename NestedCatalogList::const_iterator i = nested.begin();
720 typename NestedCatalogList::const_iterator iend = nested.end();
721 for (; i != iend; ++i) {
723 const CatalogJob new_job(i->mountpoint.ToString(),
731 return nested.size();
792 if (job->
postponed && !this->no_close_ && !this->ReopenCatalog(job)) {
808 const bool unlink_db =
true;
822 const bool unlink_db =
false;
852 while (!clbs.empty()) {
858 if (!
Yield(&postponed_job)) {
881 template<
class ObjectFetcherT>
883 kFullHistory = std::numeric_limits<uint64_t>::max();
885 template<
class ObjectFetcherT>
888 template<
class ObjectFetcherT>
894 #endif // CVMFS_CATALOG_TRAVERSAL_H_
CatalogJob(const std::string &path, const shash::Any &hash, const unsigned tree_level, const uint64_t history_depth, CatalogTN *parent=NULL)
const time_t timestamp_threshold
const char * Code2Ascii(const ObjectFetcherFailures::Failures error)
std::set< shash::Any > HashSet
const uint64_t history_depth
bool Yield(CatalogJob *job)
const manifest::Manifest * manifest() const
struct cvmcache_context * ctx
bool HandlePostponedYields(const CatalogJob &job, TraversalContext *ctx)
bool YieldToListeners(CatalogJob *job, TraversalContext *ctx)
virtual uint64_t GetLastModified(const CatalogT *catalog)
bool IsBelowPruningThresholds(const CatalogJob &job, const uint64_t history_depth, const time_t timestamp_threshold)
ObjectFetcherT ObjectFetcherTN
LogFacilities error_sink_
ObjectFetcherT * object_fetcher_
uint64_t referenced_catalogs
const TraversalType traversal_type
std::string ToString(const bool with_suffix=false) const
const history::History * history() const
std::string ToStringWithSuffix() const
CallbackDataTN GetCallbackData() const
void NotifyListeners(const CatalogTraversalData< ObjectFetcherT::CatalogTN > ¶meter)
void PushReferencedCatalogs(CatalogJob *job, TraversalContext *ctx)
void PostponeYield(CatalogJob *job, TraversalContext *ctx)
ObjectFetcherT * object_fetcher
const bool no_repeat_history_
assert((mem||(size==0))&&"Out Of Memory")
const uint64_t history_depth
CatalogTraversalBase(const Parameters ¶ms)
bool DoTraverse(TraversalContext *ctx)
static const uint64_t kNoHistory
bool IsRootCatalog() const
bool PrepareCatalog(CatalogJob *job)
CatalogTraversalData< CatalogTN > CallbackDataTN
Base::CatalogJob CatalogJob
const bool ignore_load_failure_
CatalogTraversalData(const CatalogT *catalog, const shash::Any &catalog_hash, const unsigned tree_level, const size_t file_size, const uint64_t history_depth)
CatalogJob Pop(TraversalContext *ctx)
std::set< shash::Any > HashSet
ObjectFetcherT ObjectFetcherTN
CatalogTraversalInfoShim< CatalogTN > * catalog_info_shim_
bool TraverseList(const std::vector< shash::Any > &catalog_list, const TraversalType type=Base::kBreadthFirst)
CatalogTraversalInfoShim< CatalogTN > catalog_info_default_shim_
virtual bool TraverseNamedSnapshots(const TraversalType type=kBreadthFirst)
CatalogJobStack callback_stack
virtual bool TraverseRevision(const shash::Any &root_catalog_hash, const TraversalType type=kBreadthFirst)=0
bool ShouldBeSkipped(const CatalogJob &job)
ObjectFetcherT::HistoryTN HistoryTN
const shash::Any catalog_hash
TraversalContext(const uint64_t history_depth, const time_t timestamp_threshold, const TraversalType traversal_type)
Base::Parameters Parameters
CatalogJobStack catalog_stack
CatalogTraversalBase< ObjectFetcherT > Base
Base::TraversalType TraversalType
ObjectFetcherT::CatalogTN CatalogTN
ObjectFetcherT::CatalogTN CatalogTN
uint64_t timestamp_threshold
std::stack< CatalogJob > CatalogJobStack
virtual ~CatalogTraversalInfoShim()
bool Traverse(const TraversalType type=Base::kBreadthFirst)
HashSet visited_catalogs_
const uint64_t default_history_depth_
void MarkAsVisited(const CatalogJob &job)
CatalogTraversalData< CatalogTN > CallbackDataTN
const uint64_t history_depth
virtual bool TraverseList(const std::vector< shash::Any > &catalog_list, const TraversalType type=kBreadthFirst)=0
bool TraverseRevision(const shash::Any &root_catalog_hash, const TraversalType type=Base::kBreadthFirst)
static const time_t kNoTimestampThreshold
static const uint64_t kFullHistory
void Push(const shash::Any &root_catalog_hash, TraversalContext *ctx)
void SetCatalogInfoShim(CatalogTraversalInfoShim< CatalogTN > *shim)
bool Traverse(const shash::Any &root_catalog_hash, const TraversalType type=Base::kBreadthFirst)
int64_t GetFileSize(const std::string &path)
shash::Any GetRepositoryRootCatalogHash()
unsigned int PushPreviousRevision(const CatalogJob &job, TraversalContext *ctx)
virtual bool Traverse(const TraversalType type=kBreadthFirst)=0
const unsigned tree_level
void Push(const CatalogJob &job, TraversalContext *ctx)
bool CloseCatalog(const bool unlink_db, CatalogJob *job)
CatalogTraversal(const Parameters ¶ms)
ObjectFetcherT::HistoryTN HistoryTN
std::string catalog_file_path
bool ReopenCatalog(CatalogJob *job)
unsigned int PushNestedCatalogs(const CatalogJob &job, TraversalContext *ctx)
const unsigned int tree_level
const time_t default_timestamp_threshold_
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)