GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/ingestion/task_chunk.cc
Date: 2026-10-25 02:40:14
Exec Total Coverage
Lines: 89 91 97.8%
Branches: 90 149 60.4%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "ingestion/task_chunk.h"
6
7 #include <unistd.h>
8
9 #include <cassert>
10
11 #include "util/exception.h"
12
13 /**
14 * The tags from the read stage in the pipeline and the tags given in the
15 * chunking stage can safely overlap. Nevertheless, debugging might be easier
16 * if they don't. So let's start with a high number.
17 */
18 std::atomic<int64_t> TaskChunk::tag_seq_(2 << 28);
19
20 /**
21 * Consumes the stream of input blocks and produces new output blocks according
22 * to cut marks. The output blocks correspond to chunks.
23 */
24 18730897 void TaskChunk::Process(BlockItem *input_block) {
25 18730897 FileItem *file_item = input_block->file_item();
26 18727795 const int64_t input_tag = input_block->tag();
27
2/4
✓ Branch 0 taken 18735583 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18735781 times.
✗ Branch 3 not taken.
18734857 assert((file_item != NULL) && (input_tag >= 0));
28
29 18735781 ChunkInfo chunk_info;
30 // Do we see blocks of the file for the first time?
31
3/4
✓ Branch 1 taken 18744295 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8247155 times.
✓ Branch 4 taken 10497140 times.
18733207 if (!tag_map_.Lookup(input_tag, &chunk_info)) {
32 // We may have only regular chunks, only a bulk chunk, or both. We may
33 // end up in a situation where we produced only a single non-bulk chunk.
34 // This needs to be fixed up later in the pipeline by the write task.
35
2/2
✓ Branch 1 taken 555 times.
✓ Branch 2 taken 8246897 times.
8247155 if (file_item->may_have_chunks()) {
36
2/4
✓ Branch 1 taken 555 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 555 times.
✗ Branch 5 not taken.
555 chunk_info.next_chunk = new ChunkItem(file_item, 0);
37 555 chunk_info.output_tag_chunk = tag_seq_.fetch_add(1);
38
2/2
✓ Branch 1 taken 378 times.
✓ Branch 2 taken 177 times.
555 if (file_item->has_legacy_bulk_chunk()) {
39
2/4
✓ Branch 1 taken 378 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 378 times.
✗ Branch 5 not taken.
378 chunk_info.bulk_chunk = new ChunkItem(file_item, 0);
40 }
41 } else {
42
2/4
✓ Branch 1 taken 8248844 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8245082 times.
✗ Branch 5 not taken.
8246897 chunk_info.bulk_chunk = new ChunkItem(file_item, 0);
43 }
44
45
1/2
✓ Branch 0 taken 8245658 times.
✗ Branch 1 not taken.
8245637 if (chunk_info.bulk_chunk != NULL) {
46
1/2
✓ Branch 1 taken 8240807 times.
✗ Branch 2 not taken.
8245658 chunk_info.bulk_chunk->MakeBulkChunk();
47 8240807 chunk_info.bulk_chunk->set_size(file_item->size());
48 8249156 chunk_info.output_tag_bulk = tag_seq_.fetch_add(1);
49 }
50
1/2
✓ Branch 1 taken 8238872 times.
✗ Branch 2 not taken.
8249135 tag_map_.Insert(input_tag, chunk_info);
51 }
52
3/4
✓ Branch 0 taken 489393 times.
✓ Branch 1 taken 18246619 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 489393 times.
18736012 assert((chunk_info.bulk_chunk != NULL) || (chunk_info.next_chunk != NULL));
53
54 18736012 BlockItem *output_block_bulk = NULL;
55
2/2
✓ Branch 0 taken 18249325 times.
✓ Branch 1 taken 486687 times.
18736012 if (chunk_info.bulk_chunk != NULL) {
56
2/4
✓ Branch 1 taken 18251437 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18231505 times.
✗ Branch 5 not taken.
18249325 output_block_bulk = new BlockItem(chunk_info.output_tag_bulk, allocator_);
57
1/2
✓ Branch 1 taken 18234772 times.
✗ Branch 2 not taken.
18231505 output_block_bulk->SetFileItem(file_item);
58
1/2
✓ Branch 1 taken 18233287 times.
✗ Branch 2 not taken.
18234772 output_block_bulk->SetChunkItem(chunk_info.bulk_chunk);
59 }
60
61 18719974 ChunkDetector *chunk_detector = file_item->chunk_detector();
62
2/3
✓ Branch 1 taken 8242700 times.
✓ Branch 2 taken 10483544 times.
✗ Branch 3 not taken.
18720997 switch (input_block->type()) {
63 8242700 case BlockItem::kBlockStop:
64 // End of the file, no more new chunks
65 8242700 file_item->set_is_fully_chunked();
66
2/2
✓ Branch 0 taken 8244206 times.
✓ Branch 1 taken 6381 times.
8250587 if (output_block_bulk)
67
1/2
✓ Branch 1 taken 8241170 times.
✗ Branch 2 not taken.
8244206 output_block_bulk->MakeStop();
68
2/2
✓ Branch 0 taken 555 times.
✓ Branch 1 taken 8246996 times.
8247551 if (chunk_info.next_chunk != NULL) {
69
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 555 times.
555 assert(file_item->size() >= chunk_info.next_chunk->offset());
70 1110 chunk_info.next_chunk->set_size(file_item->size()
71 555 - chunk_info.next_chunk->offset());
72 BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk,
73
2/4
✓ Branch 1 taken 555 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 555 times.
✗ Branch 5 not taken.
555 allocator_);
74
1/2
✓ Branch 1 taken 555 times.
✗ Branch 2 not taken.
555 block_stop->SetFileItem(file_item);
75
1/2
✓ Branch 1 taken 555 times.
✗ Branch 2 not taken.
555 block_stop->SetChunkItem(chunk_info.next_chunk);
76
1/2
✓ Branch 1 taken 555 times.
✗ Branch 2 not taken.
555 block_stop->MakeStop();
77
1/2
✓ Branch 1 taken 555 times.
✗ Branch 2 not taken.
555 tubes_out_->Dispatch(block_stop);
78 }
79
1/2
✓ Branch 1 taken 8238344 times.
✗ Branch 2 not taken.
8247551 tag_map_.Erase(input_tag);
80 8238344 break;
81
82 10483544 case BlockItem::kBlockData:
83
2/2
✓ Branch 0 taken 9994130 times.
✓ Branch 1 taken 489414 times.
10483544 if (output_block_bulk) {
84
2/2
✓ Branch 0 taken 895125 times.
✓ Branch 1 taken 9099005 times.
9994130 if (chunk_info.next_chunk != NULL) {
85 // Reserve zero-copy for the regular chunk
86
1/2
✓ Branch 3 taken 893805 times.
✗ Branch 4 not taken.
895125 output_block_bulk->MakeDataCopy(input_block->data(),
87 input_block->size());
88 } else {
89 // There is only the bulk chunk, zero copy
90
1/2
✓ Branch 1 taken 9097256 times.
✗ Branch 2 not taken.
9099005 output_block_bulk->MakeDataMove(input_block);
91 }
92 }
93
94
2/2
✓ Branch 0 taken 1384341 times.
✓ Branch 1 taken 9096134 times.
10480475 if (chunk_info.next_chunk != NULL) {
95 1384341 unsigned offset_in_block = 0;
96 1384341 uint64_t cut_mark = 0;
97
3/4
✓ Branch 1 taken 1637622 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 253182 times.
✓ Branch 4 taken 1384440 times.
1637523 while ((cut_mark = chunk_detector->FindNextCutMark(input_block)) != 0) {
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253182 times.
253182 assert(cut_mark >= chunk_info.offset + offset_in_block);
99 253182 const uint64_t cut_mark_in_block = cut_mark - chunk_info.offset;
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253182 times.
253182 assert(cut_mark_in_block >= offset_in_block);
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 253182 times.
253182 assert(cut_mark_in_block <= input_block->size());
102 253182 const unsigned tail_size = cut_mark_in_block - offset_in_block;
103
104
1/2
✓ Branch 0 taken 253182 times.
✗ Branch 1 not taken.
253182 if (tail_size > 0) {
105 BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk,
106
2/4
✓ Branch 1 taken 253182 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 253182 times.
✗ Branch 5 not taken.
253182 allocator_);
107
1/2
✓ Branch 1 taken 253182 times.
✗ Branch 2 not taken.
253182 block_tail->SetFileItem(file_item);
108
1/2
✓ Branch 1 taken 253182 times.
✗ Branch 2 not taken.
253182 block_tail->SetChunkItem(chunk_info.next_chunk);
109
1/2
✓ Branch 2 taken 253182 times.
✗ Branch 3 not taken.
253182 block_tail->MakeDataCopy(input_block->data() + offset_in_block,
110 tail_size);
111
1/2
✓ Branch 1 taken 253182 times.
✗ Branch 2 not taken.
253182 tubes_out_->Dispatch(block_tail);
112 }
113
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 253182 times.
253182 assert(cut_mark >= chunk_info.next_chunk->offset());
115 // If the cut mark happens to at the end of file, let the final
116 // incoming stop block schedule dispatch of the chunk stop block
117
2/2
✓ Branch 1 taken 253134 times.
✓ Branch 2 taken 48 times.
253182 if (cut_mark < file_item->size()) {
118 253134 chunk_info.next_chunk->set_size(cut_mark
119 253134 - chunk_info.next_chunk->offset());
120 BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk,
121
2/4
✓ Branch 1 taken 253134 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 253134 times.
✗ Branch 5 not taken.
253134 allocator_);
122
1/2
✓ Branch 1 taken 253134 times.
✗ Branch 2 not taken.
253134 block_stop->SetFileItem(file_item);
123
1/2
✓ Branch 1 taken 253134 times.
✗ Branch 2 not taken.
253134 block_stop->SetChunkItem(chunk_info.next_chunk);
124
1/2
✓ Branch 1 taken 253134 times.
✗ Branch 2 not taken.
253134 block_stop->MakeStop();
125
1/2
✓ Branch 1 taken 253134 times.
✗ Branch 2 not taken.
253134 tubes_out_->Dispatch(block_stop);
126
127
2/4
✓ Branch 1 taken 253134 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 253134 times.
✗ Branch 5 not taken.
253134 chunk_info.next_chunk = new ChunkItem(file_item, cut_mark);
128 253134 chunk_info.output_tag_chunk = tag_seq_.fetch_add(1);
129 }
130 253182 offset_in_block = cut_mark_in_block;
131 }
132 1384440 chunk_info.offset += offset_in_block;
133
134
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1384407 times.
1384440 assert(input_block->size() >= offset_in_block);
135 1384407 const unsigned tail_size = input_block->size() - offset_in_block;
136
2/2
✓ Branch 0 taken 1382562 times.
✓ Branch 1 taken 1845 times.
1384407 if (tail_size > 0) {
137 BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk,
138
2/4
✓ Branch 1 taken 1382562 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1382430 times.
✗ Branch 5 not taken.
1382562 allocator_);
139
1/2
✓ Branch 1 taken 1382529 times.
✗ Branch 2 not taken.
1382430 block_tail->SetFileItem(file_item);
140
1/2
✓ Branch 1 taken 1382529 times.
✗ Branch 2 not taken.
1382529 block_tail->SetChunkItem(chunk_info.next_chunk);
141
1/2
✓ Branch 2 taken 1382496 times.
✗ Branch 3 not taken.
1382529 block_tail->MakeDataCopy(input_block->data() + offset_in_block,
142 tail_size);
143
1/2
✓ Branch 1 taken 1382628 times.
✗ Branch 2 not taken.
1382496 tubes_out_->Dispatch(block_tail);
144 1382628 chunk_info.offset += tail_size;
145 }
146
147 // Delete data from incoming block
148
1/2
✓ Branch 1 taken 1384704 times.
✗ Branch 2 not taken.
1384473 input_block->Reset();
149 }
150
151
1/2
✓ Branch 1 taken 10485788 times.
✗ Branch 2 not taken.
10480838 tag_map_.Insert(input_tag, chunk_info);
152 10485788 break;
153
154 ✗ default:
155 ✗ PANIC(NULL);
156 }
157
158
2/2
✓ Branch 0 taken 18720337 times.
✓ Branch 1 taken 3795 times.
18724132 delete input_block;
159
2/2
✓ Branch 0 taken 18235927 times.
✓ Branch 1 taken 489393 times.
18725320 if (output_block_bulk)
160
1/2
✓ Branch 1 taken 18215203 times.
✗ Branch 2 not taken.
18235927 tubes_out_->Dispatch(output_block_bulk);
161 18704596 }
162