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 "crypto/hash.h" |
6 |
|
|
#include "ingestion/task.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() { return hash_.IsNull(); } |
27 |
|
✗ |
shash::Any *GetHash() { return &hash_; } |
28 |
|
|
|
29 |
|
|
private: |
30 |
|
|
shash::Any hash_; |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
|
class TaskCatalogDownload : public TubeConsumer<CatalogItem>, |
34 |
|
|
public Observable<CatalogDownloadResult> { |
35 |
|
|
public: |
36 |
|
✗ |
TaskCatalogDownload(catalog::SimpleCatalogManager *catalog_mgr, |
37 |
|
|
Tube<CatalogItem> *tube_in, |
38 |
|
|
Tube<CatalogItem> *tube_counter) |
39 |
|
✗ |
: TubeConsumer<CatalogItem>(tube_in) |
40 |
|
✗ |
, tube_counter_(tube_counter) |
41 |
|
✗ |
, catalog_mgr_(catalog_mgr) { } |
42 |
|
|
|
43 |
|
|
protected: |
44 |
|
|
virtual void Process(CatalogItem *input_hash); |
45 |
|
|
|
46 |
|
|
private: |
47 |
|
|
Tube<CatalogItem> *tube_counter_; |
48 |
|
|
catalog::SimpleCatalogManager *catalog_mgr_; |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
class CatalogDownloadPipeline : public Observable<CatalogDownloadResult> { |
52 |
|
|
public: |
53 |
|
|
explicit CatalogDownloadPipeline(catalog::SimpleCatalogManager *catalog_mgr); |
54 |
|
|
~CatalogDownloadPipeline(); |
55 |
|
|
|
56 |
|
|
void Spawn(); |
57 |
|
|
void Process(const shash::Any &catalog_hash); |
58 |
|
|
void WaitFor(); |
59 |
|
|
|
60 |
|
|
void OnFileProcessed(const CatalogDownloadResult &catalog_download_result); |
61 |
|
|
|
62 |
|
|
private: |
63 |
|
|
bool spawned_; |
64 |
|
|
Tube<CatalogItem> tube_input_; |
65 |
|
|
Tube<CatalogItem> tube_counter_; |
66 |
|
|
|
67 |
|
|
TubeConsumerGroup<CatalogItem> tasks_download_; |
68 |
|
|
|
69 |
|
|
catalog::SimpleCatalogManager *catalog_mgr_; |
70 |
|
|
}; |
71 |
|
|
|
72 |
|
|
#endif // CVMFS_CATALOG_DOWNLOADER_H_ |
73 |
|
|
|