| Line |
Branch |
Exec |
Source |
| 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 "ingestion/item.h" |
| 11 |
|
|
#include "ingestion/task.h" |
| 12 |
|
|
#include "util/atomic.h" |
| 13 |
|
|
#include "util/posix.h" |
| 14 |
|
|
#include "util/tube.h" |
| 15 |
|
|
|
| 16 |
|
|
class ItemAllocator; |
| 17 |
|
|
|
| 18 |
|
|
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 |
|
79080 |
TaskRead(Tube<FileItem> *tube_in, |
| 26 |
|
|
TubeGroup<BlockItem> *tubes_out, |
| 27 |
|
|
ItemAllocator *allocator) |
| 28 |
|
79080 |
: TubeConsumer<FileItem>(tube_in) |
| 29 |
|
79080 |
, tubes_out_(tubes_out) |
| 30 |
|
79080 |
, allocator_(allocator) |
| 31 |
|
79080 |
, low_watermark_(0) |
| 32 |
|
79080 |
, high_watermark_(0) { |
| 33 |
|
79080 |
atomic_init64(&n_block_); |
| 34 |
|
79080 |
} |
| 35 |
|
|
|
| 36 |
|
|
void SetWatermarks(uint64_t low, uint64_t high); |
| 37 |
|
|
|
| 38 |
|
60 |
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_ |
| 69 |
|
|
|