Directory: | cvmfs/ |
---|---|
File: | cvmfs/ingestion/task_read.cc |
Date: | 2025-08-31 02:39:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 36 | 40 | 90.0% |
Branches: | 36 | 66 | 54.5% |
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 | atomic_int64 TaskRead::tag_seq_ = 0; | ||
22 | |||
23 | |||
24 | 4500500 | void TaskRead::Process(FileItem *item) { | |
25 |
1/2✓ Branch 1 taken 4500968 times.
✗ Branch 2 not taken.
|
4500500 | BackoffThrottle throttle(kThrottleInitMs, kThrottleMaxMs, kThrottleResetMs); |
26 |
6/6✓ Branch 0 taken 4500938 times.
✓ Branch 1 taken 30 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4500358 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4500388 times.
|
4500968 | if ((high_watermark_ > 0) && (BlockItem::managed_bytes() > high_watermark_)) { |
27 | 4 | atomic_inc64(&n_block_); | |
28 | do { | ||
29 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | throttle.Throttle(); |
30 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | } while (BlockItem::managed_bytes() > low_watermark_); |
31 | } | ||
32 | |||
33 |
2/4✓ Branch 1 taken 4499834 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4499834 times.
|
4500392 | 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 4499420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4499420 times.
|
4499834 | if (item->GetSize(&size) == false) { |
38 | ✗ | PANIC(kLogStderr, "failed to fstat %s (%d)", item->path().c_str(), errno); | |
39 | } | ||
40 | 4499420 | item->set_size(size); | |
41 | |||
42 |
2/2✓ Branch 1 taken 4497850 times.
✓ Branch 2 taken 1966 times.
|
4499294 | if (item->may_have_chunks()) { |
43 | 8996096 | item->set_may_have_chunks( | |
44 |
1/2✓ Branch 3 taken 4498246 times.
✗ Branch 4 not taken.
|
4497850 | item->chunk_detector()->MightFindChunks(item->size())); |
45 | } | ||
46 | |||
47 | unsigned char *buffer[kBlockSize]; | ||
48 | 4500032 | const uint64_t tag = atomic_xadd64(&tag_seq_, 1); | |
49 | 4501526 | ssize_t nbytes = -1; | |
50 | 4501526 | unsigned cnt = 0; | |
51 | do { | ||
52 |
1/2✓ Branch 1 taken 9956313 times.
✗ Branch 2 not taken.
|
9953019 | nbytes = item->Read(buffer, kBlockSize); |
53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9956313 times.
|
9956313 | if (nbytes < 0) { |
54 | ✗ | PANIC(kLogStderr, "failed to read %s (%d)", item->path().c_str(), errno); | |
55 | } | ||
56 | |||
57 |
2/4✓ Branch 1 taken 9958923 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9936657 times.
✗ Branch 5 not taken.
|
9956313 | BlockItem *block_item = new BlockItem(tag, allocator_); |
58 |
1/2✓ Branch 1 taken 9935325 times.
✗ Branch 2 not taken.
|
9936657 | block_item->SetFileItem(item); |
59 |
2/2✓ Branch 0 taken 4496396 times.
✓ Branch 1 taken 5438929 times.
|
9935325 | if (nbytes == 0) { |
60 |
1/2✓ Branch 1 taken 4496144 times.
✗ Branch 2 not taken.
|
4496396 | item->Close(); |
61 |
1/2✓ Branch 1 taken 4495784 times.
✗ Branch 2 not taken.
|
4496144 | block_item->MakeStop(); |
62 | } else { | ||
63 |
1/2✓ Branch 1 taken 5471095 times.
✗ Branch 2 not taken.
|
5438929 | block_item->MakeDataCopy(reinterpret_cast<unsigned char *>(buffer), |
64 | nbytes); | ||
65 | } | ||
66 |
1/2✓ Branch 1 taken 9946197 times.
✗ Branch 2 not taken.
|
9966879 | tubes_out_->Dispatch(block_item); |
67 | |||
68 | 9946197 | cnt++; | |
69 |
2/2✓ Branch 0 taken 30366 times.
✓ Branch 1 taken 9915831 times.
|
9946197 | if ((cnt % 32) == 0) { |
70 | 60750 | if ((high_watermark_ > 0) | |
71 |
3/6✓ Branch 0 taken 30366 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 30384 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 30384 times.
|
30366 | && (BlockItem::managed_bytes() > high_watermark_)) { |
72 | ✗ | throttle.Throttle(); | |
73 | } | ||
74 | } | ||
75 |
2/2✓ Branch 0 taken 5451493 times.
✓ Branch 1 taken 4494722 times.
|
9946215 | } while (nbytes > 0); |
76 | 4494722 | } | |
77 | |||
78 | |||
79 | 61764 | void TaskRead::SetWatermarks(uint64_t low, uint64_t high) { | |
80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 61764 times.
|
61764 | assert(high > low); |
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 61764 times.
|
61764 | assert(low > 0); |
82 | 61764 | low_watermark_ = low; | |
83 | 61764 | high_watermark_ = high; | |
84 | 61764 | } | |
85 |