GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/ingestion/task_chunk.cc
Date: 2025-11-09 02:35:23
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 atomic_int64 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 16137625 void TaskChunk::Process(BlockItem *input_block) {
25 16137625 FileItem *file_item = input_block->file_item();
26 16133333 const int64_t input_tag = input_block->tag();
27
3/4
✓ Branch 0 taken 16148152 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16136668 times.
✓ Branch 3 taken 11484 times.
16146673 assert((file_item != NULL) && (input_tag >= 0));
28
29 16136668 ChunkInfo chunk_info;
30 // Do we see blocks of the file for the first time?
31
3/4
✓ Branch 1 taken 16185997 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7239794 times.
✓ Branch 4 taken 8946203 times.
16138002 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 399 times.
✓ Branch 2 taken 7238351 times.
7239794 if (file_item->may_have_chunks()) {
36
2/4
✓ Branch 1 taken 399 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 chunk_info.next_chunk = new ChunkItem(file_item, 0);
37 399 chunk_info.output_tag_chunk = atomic_xadd64(&tag_seq_, 1);
38
2/2
✓ Branch 1 taken 310 times.
✓ Branch 2 taken 89 times.
399 if (file_item->has_legacy_bulk_chunk()) {
39
2/4
✓ Branch 1 taken 310 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 310 times.
✗ Branch 5 not taken.
310 chunk_info.bulk_chunk = new ChunkItem(file_item, 0);
40 }
41 } else {
42
2/4
✓ Branch 1 taken 7243571 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7236959 times.
✗ Branch 5 not taken.
7238351 chunk_info.bulk_chunk = new ChunkItem(file_item, 0);
43 }
44
45
1/2
✓ Branch 0 taken 7237385 times.
✗ Branch 1 not taken.
7237358 if (chunk_info.bulk_chunk != NULL) {
46
1/2
✓ Branch 1 taken 7232426 times.
✗ Branch 2 not taken.
7237385 chunk_info.bulk_chunk->MakeBulkChunk();
47 7232426 chunk_info.bulk_chunk->set_size(file_item->size());
48 7231237 chunk_info.output_tag_bulk = atomic_xadd64(&tag_seq_, 1);
49 }
50
1/2
✓ Branch 1 taken 7233907 times.
✗ Branch 2 not taken.
7249567 tag_map_.Insert(input_tag, chunk_info);
51 }
52
3/4
✓ Branch 0 taken 207833 times.
✓ Branch 1 taken 15972277 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 207833 times.
16180110 assert((chunk_info.bulk_chunk != NULL) || (chunk_info.next_chunk != NULL));
53
54 16180110 BlockItem *output_block_bulk = NULL;
55
2/2
✓ Branch 0 taken 15999363 times.
✓ Branch 1 taken 180747 times.
16180110 if (chunk_info.bulk_chunk != NULL) {
56
2/4
✓ Branch 1 taken 16002959 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15971639 times.
✗ Branch 5 not taken.
15999363 output_block_bulk = new BlockItem(chunk_info.output_tag_bulk, allocator_);
57
1/2
✓ Branch 1 taken 15968217 times.
✗ Branch 2 not taken.
15971639 output_block_bulk->SetFileItem(file_item);
58
1/2
✓ Branch 1 taken 15970537 times.
✗ Branch 2 not taken.
15968217 output_block_bulk->SetChunkItem(chunk_info.bulk_chunk);
59 }
60
61 16151284 ChunkDetector *chunk_detector = file_item->chunk_detector();
62
2/3
✓ Branch 1 taken 7220219 times.
✓ Branch 2 taken 8995880 times.
✗ Branch 3 not taken.
16174571 switch (input_block->type()) {
63 7220219 case BlockItem::kBlockStop:
64 // End of the file, no more new chunks
65 7220219 file_item->set_is_fully_chunked();
66
1/2
✓ Branch 0 taken 7242228 times.
✗ Branch 1 not taken.
7242143 if (output_block_bulk)
67
1/2
✓ Branch 1 taken 7225640 times.
✗ Branch 2 not taken.
7242228 output_block_bulk->MakeStop();
68
2/2
✓ Branch 0 taken 399 times.
✓ Branch 1 taken 7225156 times.
7225555 if (chunk_info.next_chunk != NULL) {
69
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 399 times.
399 assert(file_item->size() >= chunk_info.next_chunk->offset());
70 798 chunk_info.next_chunk->set_size(file_item->size()
71 399 - chunk_info.next_chunk->offset());
72 BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk,
73
2/4
✓ Branch 1 taken 399 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 allocator_);
74
1/2
✓ Branch 1 taken 399 times.
✗ Branch 2 not taken.
399 block_stop->SetFileItem(file_item);
75
1/2
✓ Branch 1 taken 399 times.
✗ Branch 2 not taken.
399 block_stop->SetChunkItem(chunk_info.next_chunk);
76
1/2
✓ Branch 1 taken 399 times.
✗ Branch 2 not taken.
399 block_stop->MakeStop();
77
1/2
✓ Branch 1 taken 399 times.
✗ Branch 2 not taken.
399 tubes_out_->Dispatch(block_stop);
78 }
79
1/2
✓ Branch 1 taken 7223728 times.
✗ Branch 2 not taken.
7225555 tag_map_.Erase(input_tag);
80 7223728 break;
81
82 8995880 case BlockItem::kBlockData:
83
2/2
✓ Branch 0 taken 8784424 times.
✓ Branch 1 taken 211456 times.
8995880 if (output_block_bulk) {
84
2/2
✓ Branch 0 taken 785958 times.
✓ Branch 1 taken 7998466 times.
8784424 if (chunk_info.next_chunk != NULL) {
85 // Reserve zero-copy for the regular chunk
86
1/2
✓ Branch 3 taken 783319 times.
✗ Branch 4 not taken.
785958 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 7996581 times.
✗ Branch 2 not taken.
7998466 output_block_bulk->MakeDataMove(input_block);
91 }
92 }
93
94
2/2
✓ Branch 0 taken 994369 times.
✓ Branch 1 taken 7996987 times.
8991356 if (chunk_info.next_chunk != NULL) {
95 994369 unsigned offset_in_block = 0;
96 994369 uint64_t cut_mark = 0;
97
3/4
✓ Branch 1 taken 1105873 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 111562 times.
✓ Branch 4 taken 994311 times.
1105931 while ((cut_mark = chunk_detector->FindNextCutMark(input_block)) != 0) {
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111562 times.
111562 assert(cut_mark >= chunk_info.offset + offset_in_block);
99 111562 const uint64_t cut_mark_in_block = cut_mark - chunk_info.offset;
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111562 times.
111562 assert(cut_mark_in_block >= offset_in_block);
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 111562 times.
111562 assert(cut_mark_in_block <= input_block->size());
102 111562 const unsigned tail_size = cut_mark_in_block - offset_in_block;
103
104
1/2
✓ Branch 0 taken 111562 times.
✗ Branch 1 not taken.
111562 if (tail_size > 0) {
105 BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk,
106
2/4
✓ Branch 1 taken 111562 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 111562 times.
✗ Branch 5 not taken.
111562 allocator_);
107
1/2
✓ Branch 1 taken 111562 times.
✗ Branch 2 not taken.
111562 block_tail->SetFileItem(file_item);
108
1/2
✓ Branch 1 taken 111562 times.
✗ Branch 2 not taken.
111562 block_tail->SetChunkItem(chunk_info.next_chunk);
109
1/2
✓ Branch 2 taken 111562 times.
✗ Branch 3 not taken.
111562 block_tail->MakeDataCopy(input_block->data() + offset_in_block,
110 tail_size);
111
1/2
✓ Branch 1 taken 111562 times.
✗ Branch 2 not taken.
111562 tubes_out_->Dispatch(block_tail);
112 }
113
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 111562 times.
111562 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 111542 times.
✓ Branch 2 taken 20 times.
111562 if (cut_mark < file_item->size()) {
118 111542 chunk_info.next_chunk->set_size(cut_mark
119 111542 - chunk_info.next_chunk->offset());
120 BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk,
121
2/4
✓ Branch 1 taken 111542 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 111542 times.
✗ Branch 5 not taken.
111542 allocator_);
122
1/2
✓ Branch 1 taken 111542 times.
✗ Branch 2 not taken.
111542 block_stop->SetFileItem(file_item);
123
1/2
✓ Branch 1 taken 111542 times.
✗ Branch 2 not taken.
111542 block_stop->SetChunkItem(chunk_info.next_chunk);
124
1/2
✓ Branch 1 taken 111542 times.
✗ Branch 2 not taken.
111542 block_stop->MakeStop();
125
1/2
✓ Branch 1 taken 111542 times.
✗ Branch 2 not taken.
111542 tubes_out_->Dispatch(block_stop);
126
127
2/4
✓ Branch 1 taken 111542 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 111542 times.
✗ Branch 5 not taken.
111542 chunk_info.next_chunk = new ChunkItem(file_item, cut_mark);
128 111542 chunk_info.output_tag_chunk = atomic_xadd64(&tag_seq_, 1);
129 }
130 111562 offset_in_block = cut_mark_in_block;
131 }
132 994311 chunk_info.offset += offset_in_block;
133
134
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 994282 times.
994311 assert(input_block->size() >= offset_in_block);
135 994282 const unsigned tail_size = input_block->size() - offset_in_block;
136
2/2
✓ Branch 0 taken 992734 times.
✓ Branch 1 taken 1577 times.
994311 if (tail_size > 0) {
137 BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk,
138
2/4
✓ Branch 1 taken 992734 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 992647 times.
✗ Branch 5 not taken.
992734 allocator_);
139
1/2
✓ Branch 1 taken 992589 times.
✗ Branch 2 not taken.
992647 block_tail->SetFileItem(file_item);
140
1/2
✓ Branch 1 taken 992647 times.
✗ Branch 2 not taken.
992589 block_tail->SetChunkItem(chunk_info.next_chunk);
141
1/2
✓ Branch 2 taken 992821 times.
✗ Branch 3 not taken.
992647 block_tail->MakeDataCopy(input_block->data() + offset_in_block,
142 tail_size);
143
1/2
✓ Branch 1 taken 992676 times.
✗ Branch 2 not taken.
992821 tubes_out_->Dispatch(block_tail);
144 992676 chunk_info.offset += tail_size;
145 }
146
147 // Delete data from incoming block
148
1/2
✓ Branch 1 taken 994427 times.
✗ Branch 2 not taken.
994253 input_block->Reset();
149 }
150
151
1/2
✓ Branch 1 taken 8997968 times.
✗ Branch 2 not taken.
8991414 tag_map_.Insert(input_tag, chunk_info);
152 8997968 break;
153
154 default:
155 PANIC(NULL);
156 }
157
158
2/2
✓ Branch 0 taken 16202614 times.
✓ Branch 1 taken 19082 times.
16221696 delete input_block;
159
2/2
✓ Branch 0 taken 16028595 times.
✓ Branch 1 taken 207833 times.
16236428 if (output_block_bulk)
160
1/2
✓ Branch 1 taken 15950179 times.
✗ Branch 2 not taken.
16028595 tubes_out_->Dispatch(output_block_bulk);
161 16158012 }
162