| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/ingestion/task_read.cc |
| Date: | 2026-11-08 02:41:18 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 36 | 40 | 90.0% |
| Branches: | 37 | 66 | 56.1% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * This file is part of the CernVM File System. | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include "ingestion/task_read.h" | ||
| 6 | |||
| 7 | #include <errno.h> | ||
| 8 | #include <fcntl.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | #include <cstring> | ||
| 12 | |||
| 13 | #include "backoff.h" | ||
| 14 | #include "util/exception.h" | ||
| 15 | #include "util/logging.h" | ||
| 16 | #include "util/platform.h" | ||
| 17 | #include "util/posix.h" | ||
| 18 | #include "util/smalloc.h" | ||
| 19 | |||
| 20 | |||
| 21 | std::atomic<int64_t> TaskRead::tag_seq_(0); | ||
| 22 | |||
| 23 | |||
| 24 | 1500530 | void TaskRead::Process(FileItem *item) { | |
| 25 |
1/2✓ Branch 1 taken 1500788 times.
✗ Branch 2 not taken.
|
1500530 | BackoffThrottle throttle(kThrottleInitMs, kThrottleMaxMs, kThrottleResetMs); |
| 26 |
6/6✓ Branch 0 taken 1500773 times.
✓ Branch 1 taken 15 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 1500190 times.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 1500205 times.
|
1500788 | if ((high_watermark_ > 0) && (BlockItem::managed_bytes() > high_watermark_)) { |
| 27 | 13 | n_block_.fetch_add(1); | |
| 28 | do { | ||
| 29 |
1/2✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
|
26 | throttle.Throttle(); |
| 30 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 13 times.
|
26 | } while (BlockItem::managed_bytes() > low_watermark_); |
| 31 | } | ||
| 32 | |||
| 33 |
2/4✓ Branch 1 taken 1499870 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1499870 times.
|
1500218 | if (item->Open() == false) { |
| 34 | ✗ | PANIC(kLogStderr, "failed to open %s (%d)", item->path().c_str(), errno); | |
| 35 | } | ||
| 36 | uint64_t size; | ||
| 37 |
2/4✓ Branch 1 taken 1500008 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1500008 times.
|
1499870 | if (item->GetSize(&size) == false) { |
| 38 | ✗ | PANIC(kLogStderr, "failed to fstat %s (%d)", item->path().c_str(), errno); | |
| 39 | } | ||
| 40 | 1500008 | item->set_size(size); | |
| 41 | |||
| 42 |
2/2✓ Branch 1 taken 1498891 times.
✓ Branch 2 taken 835 times.
|
1499576 | if (item->may_have_chunks()) { |
| 43 | 2997698 | item->set_may_have_chunks( | |
| 44 |
1/2✓ Branch 3 taken 1498807 times.
✗ Branch 4 not taken.
|
1498891 | item->chunk_detector()->MightFindChunks(item->size())); |
| 45 | } | ||
| 46 | |||
| 47 | unsigned char *buffer[kBlockSize]; | ||
| 48 | 1500218 | const uint64_t tag = tag_seq_.fetch_add(1); | |
| 49 | 1500218 | ssize_t nbytes = -1; | |
| 50 | 1500218 | unsigned cnt = 0; | |
| 51 | do { | ||
| 52 |
1/2✓ Branch 1 taken 3322608 times.
✗ Branch 2 not taken.
|
3323244 | nbytes = item->Read(buffer, kBlockSize); |
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3322608 times.
|
3322608 | if (nbytes < 0) { |
| 54 | ✗ | PANIC(kLogStderr, "failed to read %s (%d)", item->path().c_str(), errno); | |
| 55 | } | ||
| 56 | |||
| 57 |
2/4✓ Branch 1 taken 3323772 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3321750 times.
✗ Branch 5 not taken.
|
3322608 | BlockItem *block_item = new BlockItem(tag, allocator_); |
| 58 |
1/2✓ Branch 1 taken 3321198 times.
✗ Branch 2 not taken.
|
3321750 | block_item->SetFileItem(item); |
| 59 |
2/2✓ Branch 0 taken 1500434 times.
✓ Branch 1 taken 1820764 times.
|
3321198 | if (nbytes == 0) { |
| 60 |
1/2✓ Branch 1 taken 1500596 times.
✗ Branch 2 not taken.
|
1500434 | item->Close(); |
| 61 |
1/2✓ Branch 1 taken 1500512 times.
✗ Branch 2 not taken.
|
1500596 | block_item->MakeStop(); |
| 62 | } else { | ||
| 63 |
1/2✓ Branch 1 taken 1824256 times.
✗ Branch 2 not taken.
|
1820764 | block_item->MakeDataCopy(reinterpret_cast<unsigned char *>(buffer), |
| 64 | nbytes); | ||
| 65 | } | ||
| 66 |
1/2✓ Branch 1 taken 3323514 times.
✗ Branch 2 not taken.
|
3324768 | tubes_out_->Dispatch(block_item); |
| 67 | |||
| 68 | 3323514 | cnt++; | |
| 69 |
2/2✓ Branch 0 taken 10128 times.
✓ Branch 1 taken 3313386 times.
|
3323514 | if ((cnt % 32) == 0) { |
| 70 | 20256 | if ((high_watermark_ > 0) | |
| 71 |
3/6✓ Branch 0 taken 10128 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10128 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10128 times.
|
10128 | && (BlockItem::managed_bytes() > high_watermark_)) { |
| 72 | ✗ | throttle.Throttle(); | |
| 73 | } | ||
| 74 | } | ||
| 75 |
2/2✓ Branch 0 taken 1823026 times.
✓ Branch 1 taken 1500488 times.
|
3323514 | } while (nbytes > 0); |
| 76 | 1500488 | } | |
| 77 | |||
| 78 | |||
| 79 | 34893 | void TaskRead::SetWatermarks(uint64_t low, uint64_t high) { | |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34893 times.
|
34893 | assert(high > low); |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34893 times.
|
34893 | assert(low > 0); |
| 82 | 34893 | low_watermark_ = low; | |
| 83 | 34893 | high_watermark_ = high; | |
| 84 | 34893 | } | |
| 85 | |||
| 86 |