Directory: | cvmfs/ |
---|---|
File: | cvmfs/ingestion/task_read.cc |
Date: | 2025-05-11 02:35:43 |
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 | atomic_int64 TaskRead::tag_seq_ = 0; | ||
22 | |||
23 | |||
24 | 250034 | void TaskRead::Process(FileItem *item) { | |
25 |
1/2✓ Branch 1 taken 250028 times.
✗ Branch 2 not taken.
|
250034 | BackoffThrottle throttle(kThrottleInitMs, kThrottleMaxMs, kThrottleResetMs); |
26 |
6/6✓ Branch 0 taken 250026 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 250045 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 250047 times.
|
250028 | if ((high_watermark_ > 0) && (BlockItem::managed_bytes() > high_watermark_)) { |
27 | 1 | atomic_inc64(&n_block_); | |
28 | do { | ||
29 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | throttle.Throttle(); |
30 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | } while (BlockItem::managed_bytes() > low_watermark_); |
31 | } | ||
32 | |||
33 |
2/4✓ Branch 1 taken 249975 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 249975 times.
|
250048 | 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 249950 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 249950 times.
|
249975 | if (item->GetSize(&size) == false) { |
38 | ✗ | PANIC(kLogStderr, "failed to fstat %s (%d)", item->path().c_str(), errno); | |
39 | } | ||
40 | 249950 | item->set_size(size); | |
41 | |||
42 |
2/2✓ Branch 1 taken 249879 times.
✓ Branch 2 taken 65 times.
|
249928 | if (item->may_have_chunks()) { |
43 | 499732 | item->set_may_have_chunks( | |
44 |
1/2✓ Branch 3 taken 249853 times.
✗ Branch 4 not taken.
|
249879 | item->chunk_detector()->MightFindChunks(item->size())); |
45 | } | ||
46 | |||
47 | unsigned char *buffer[kBlockSize]; | ||
48 | 249896 | uint64_t tag = atomic_xadd64(&tag_seq_, 1); | |
49 | 250067 | ssize_t nbytes = -1; | |
50 | 250067 | unsigned cnt = 0; | |
51 | do { | ||
52 |
1/2✓ Branch 1 taken 553073 times.
✗ Branch 2 not taken.
|
552625 | nbytes = item->Read(buffer, kBlockSize); |
53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 553073 times.
|
553073 | if (nbytes < 0) { |
54 | ✗ | PANIC(kLogStderr, "failed to read %s (%d)", item->path().c_str(), errno); | |
55 | } | ||
56 | |||
57 |
2/4✓ Branch 1 taken 553017 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 551373 times.
✗ Branch 5 not taken.
|
553073 | BlockItem *block_item = new BlockItem(tag, allocator_); |
58 |
1/2✓ Branch 1 taken 551180 times.
✗ Branch 2 not taken.
|
551373 | block_item->SetFileItem(item); |
59 |
2/2✓ Branch 0 taken 249679 times.
✓ Branch 1 taken 301501 times.
|
551180 | if (nbytes == 0) { |
60 |
1/2✓ Branch 1 taken 249767 times.
✗ Branch 2 not taken.
|
249679 | item->Close(); |
61 |
1/2✓ Branch 1 taken 249714 times.
✗ Branch 2 not taken.
|
249767 | block_item->MakeStop(); |
62 | } else { | ||
63 |
1/2✓ Branch 1 taken 303873 times.
✗ Branch 2 not taken.
|
301501 | block_item->MakeDataCopy(reinterpret_cast<unsigned char *>(buffer), |
64 | nbytes); | ||
65 | } | ||
66 |
1/2✓ Branch 1 taken 552167 times.
✗ Branch 2 not taken.
|
553587 | tubes_out_->Dispatch(block_item); |
67 | |||
68 | 552167 | cnt++; | |
69 |
2/2✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 550479 times.
|
552167 | if ((cnt % 32) == 0) { |
70 |
2/4✓ Branch 0 taken 1688 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1688 times.
|
3376 | if ((high_watermark_ > 0) && |
71 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1688 times.
|
1688 | (BlockItem::managed_bytes() > high_watermark_)) |
72 | { | ||
73 | ✗ | throttle.Throttle(); | |
74 | } | ||
75 | } | ||
76 |
2/2✓ Branch 0 taken 302558 times.
✓ Branch 1 taken 249609 times.
|
552167 | } while (nbytes > 0); |
77 | 249609 | } | |
78 | |||
79 | |||
80 | 2945 | void TaskRead::SetWatermarks(uint64_t low, uint64_t high) { | |
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2945 times.
|
2945 | assert(high > low); |
82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2945 times.
|
2945 | assert(low > 0); |
83 | 2945 | low_watermark_ = low; | |
84 | 2945 | high_watermark_ = high; | |
85 | 2945 | } | |
86 |