1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_INGESTION_TASK_READ_H_ |
6 |
|
|
#define CVMFS_INGESTION_TASK_READ_H_ |
7 |
|
|
|
8 |
|
|
#include <stdint.h> |
9 |
|
|
|
10 |
|
|
#include "atomic.h" |
11 |
|
|
#include "ingestion/item.h" |
12 |
|
|
#include "ingestion/task.h" |
13 |
|
|
#include "ingestion/tube.h" |
14 |
|
|
#include "util/posix.h" |
15 |
|
|
|
16 |
|
|
class ItemAllocator; |
17 |
|
|
|
18 |
✗✓ |
1412 |
class TaskRead : public TubeConsumer<FileItem> { |
19 |
|
|
public: |
20 |
|
|
static const unsigned kThrottleInitMs = 50; |
21 |
|
|
static const unsigned kThrottleMaxMs = 500; |
22 |
|
|
static const unsigned kThrottleResetMs = 2000; |
23 |
|
|
static const unsigned kBlockSize = kPageSize * 4; |
24 |
|
|
|
25 |
|
706 |
TaskRead( |
26 |
|
|
Tube<FileItem> *tube_in, |
27 |
|
|
TubeGroup<BlockItem> *tubes_out, |
28 |
|
|
ItemAllocator *allocator) |
29 |
|
|
: TubeConsumer<FileItem>(tube_in) |
30 |
|
|
, tubes_out_(tubes_out) |
31 |
|
|
, allocator_(allocator) |
32 |
|
|
, low_watermark_(0) |
33 |
|
706 |
, high_watermark_(0) |
34 |
|
706 |
{ atomic_init64(&n_block_); } |
35 |
|
|
|
36 |
|
|
void SetWatermarks(uint64_t low, uint64_t high); |
37 |
|
|
|
38 |
|
3 |
uint64_t n_block() { return atomic_read64(&n_block_); } |
39 |
|
|
|
40 |
|
|
protected: |
41 |
|
|
virtual void Process(FileItem *item); |
42 |
|
|
|
43 |
|
|
private: |
44 |
|
|
/** |
45 |
|
|
* Every new file increases the tag sequence counter that is used to annotate |
46 |
|
|
* BlockItems. |
47 |
|
|
*/ |
48 |
|
|
static atomic_int64 tag_seq_; |
49 |
|
|
|
50 |
|
|
TubeGroup<BlockItem> *tubes_out_; |
51 |
|
|
ItemAllocator *allocator_; |
52 |
|
|
/** |
53 |
|
|
* Continue reading once the amount of BlockItem managed bytes is back to |
54 |
|
|
* the given level. |
55 |
|
|
*/ |
56 |
|
|
uint64_t low_watermark_; |
57 |
|
|
/** |
58 |
|
|
* Stop reading new data into the pipeline when the amount BlockItem managed |
59 |
|
|
* byte is higher than the given level. |
60 |
|
|
*/ |
61 |
|
|
uint64_t high_watermark_; |
62 |
|
|
/** |
63 |
|
|
* Number of times reading was blocked on a high watermark. |
64 |
|
|
*/ |
65 |
|
|
atomic_int64 n_block_; |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
#endif // CVMFS_INGESTION_TASK_READ_H_ |