Line |
Branch |
Exec |
Source |
1 |
|
|
#ifndef CVMFS_CATALOG_DOWNLOADER_H_ |
2 |
|
|
#define CVMFS_CATALOG_DOWNLOADER_H_ |
3 |
|
|
|
4 |
|
|
#include "catalog_mgr_ro.h" |
5 |
|
|
#include "ingestion/task.h" |
6 |
|
|
#include "crypto/hash.h" |
7 |
|
|
#include "util/concurrency.h" |
8 |
|
|
|
9 |
|
|
extern int kCatalogDownloadMultiplier; |
10 |
|
|
|
11 |
|
|
struct CatalogDownloadResult { |
12 |
|
|
CatalogDownloadResult() { } |
13 |
|
✗ |
explicit CatalogDownloadResult(const std::string &p, const std::string &h) |
14 |
|
✗ |
: db_path(p), hash(h) { } |
15 |
|
|
std::string db_path; |
16 |
|
|
std::string hash; |
17 |
|
|
}; |
18 |
|
|
|
19 |
|
|
class CatalogItem : SingleCopy { |
20 |
|
|
public: |
21 |
|
|
explicit CatalogItem(const shash::Any &hash); |
22 |
|
✗ |
static CatalogItem *CreateQuitBeacon() { |
23 |
|
✗ |
shash::Any const empty; |
24 |
|
✗ |
return new CatalogItem(empty); |
25 |
|
|
} |
26 |
|
✗ |
bool IsQuitBeacon() { |
27 |
|
✗ |
return hash_.IsNull(); |
28 |
|
|
} |
29 |
|
✗ |
shash::Any *GetHash() { |
30 |
|
✗ |
return &hash_; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
private: |
34 |
|
|
shash::Any hash_; |
35 |
|
|
}; |
36 |
|
|
|
37 |
|
|
class TaskCatalogDownload |
38 |
|
|
: public TubeConsumer<CatalogItem> |
39 |
|
|
, public Observable<CatalogDownloadResult> { |
40 |
|
|
public: |
41 |
|
✗ |
TaskCatalogDownload(catalog::SimpleCatalogManager *catalog_mgr, Tube<CatalogItem> *tube_in, Tube<CatalogItem> *tube_counter) |
42 |
|
✗ |
: TubeConsumer<CatalogItem>(tube_in), tube_counter_(tube_counter), catalog_mgr_(catalog_mgr) { } |
43 |
|
|
|
44 |
|
|
protected: |
45 |
|
|
virtual void Process(CatalogItem *input_hash); |
46 |
|
|
|
47 |
|
|
private: |
48 |
|
|
Tube<CatalogItem> *tube_counter_; |
49 |
|
|
catalog::SimpleCatalogManager *catalog_mgr_; |
50 |
|
|
}; |
51 |
|
|
|
52 |
|
|
class CatalogDownloadPipeline : public Observable<CatalogDownloadResult> { |
53 |
|
|
public: |
54 |
|
|
explicit CatalogDownloadPipeline(catalog::SimpleCatalogManager *catalog_mgr); |
55 |
|
|
~CatalogDownloadPipeline(); |
56 |
|
|
|
57 |
|
|
void Spawn(); |
58 |
|
|
void Process(const shash::Any &catalog_hash); |
59 |
|
|
void WaitFor(); |
60 |
|
|
|
61 |
|
|
void OnFileProcessed(const CatalogDownloadResult &catalog_download_result); |
62 |
|
|
|
63 |
|
|
private: |
64 |
|
|
bool spawned_; |
65 |
|
|
Tube<CatalogItem> tube_input_; |
66 |
|
|
Tube<CatalogItem> tube_counter_; |
67 |
|
|
|
68 |
|
|
TubeConsumerGroup<CatalogItem> tasks_download_; |
69 |
|
|
|
70 |
|
|
catalog::SimpleCatalogManager *catalog_mgr_; |
71 |
|
|
}; |
72 |
|
|
|
73 |
|
|
#endif // CVMFS_CATALOG_DOWNLOADER_H_ |
74 |
|
|
|