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>
89 :
public Observable<CatalogTraversalData<typename ObjectFetcherT::CatalogTN> >
93 typedef typename ObjectFetcherT::CatalogTN
CatalogTN;
94 typedef typename ObjectFetcherT::HistoryTN
HistoryTN;
211 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)",
257 HashList root_hashes;
258 bool success = tag_db->GetHashes(&root_hashes);
282 tree_level(tree_level),
283 history_depth(history_depth),
328 "%s (swept before?)",
344 job->
catalog->DropDatabaseFileOwnership();
365 "failed to re-open catalog %s", job->
hash.
ToString().c_str());
402 return manifest->catalog_hash();
416 const uint64_t history_depth,
423 assert(timestamp_threshold >= 0);
426 unsigned(timestamp_threshold);
494 template<
class ObjectFetcherT>
526 history_depth(history_depth),
527 timestamp_threshold(timestamp_threshold),
528 traversal_type(traversal_type) {}
548 if (root_catalog_hash.
IsNull()) {
561 Push(root_catalog_hash, &ctx);
567 std::vector<shash::Any>::const_iterator i = catalog_list.begin();
568 const std::vector<shash::Any>::const_iterator iend = catalog_list.end();
570 for (; i != iend; ++i) {
584 Push(root_catalog_hash, &ctx);
702 if (previous_revision.
IsNull()) {
727 typedef typename CatalogTN::NestedCatalogList NestedCatalogList;
728 const NestedCatalogList nested = job.
catalog->ListOwnNestedCatalogs();
729 typename NestedCatalogList::const_iterator i = nested.begin();
730 typename NestedCatalogList::const_iterator iend = nested.end();
731 for (; i != iend; ++i) {
733 const CatalogJob new_job(i->mountpoint.ToString(),
741 return nested.size();
802 if (job->
postponed && !this->no_close_ && !this->ReopenCatalog(job)) {
818 const bool unlink_db =
true;
832 const bool unlink_db =
false;
862 while (!clbs.empty()) {
868 if (!
Yield(&postponed_job)) {
891 template <
class ObjectFetcherT>
893 std::numeric_limits<uint64_t>::max();
895 template <
class ObjectFetcherT>
898 template <
class ObjectFetcherT>
904 #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,...)