Directory: | cvmfs/ |
---|---|
File: | cvmfs/ingestion/task_chunk.cc |
Date: | 2025-06-22 02:36:02 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 89 | 91 | 97.8% |
Branches: | 91 | 149 | 61.1% |
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 | 693077 | void TaskChunk::Process(BlockItem *input_block) { | |
25 | 693077 | FileItem *file_item = input_block->file_item(); | |
26 | 692867 | const int64_t input_tag = input_block->tag(); | |
27 |
2/4✓ Branch 0 taken 693315 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 693324 times.
✗ Branch 3 not taken.
|
693282 | assert((file_item != NULL) && (input_tag >= 0)); |
28 | |||
29 | 693324 | ChunkInfo chunk_info; | |
30 | // Do we see blocks of the file for the first time? | ||
31 |
3/4✓ Branch 1 taken 694786 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 251340 times.
✓ Branch 4 taken 443446 times.
|
693046 | 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 67 times.
✓ Branch 2 taken 251233 times.
|
251340 | if (file_item->may_have_chunks()) { |
36 |
2/4✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
|
67 | chunk_info.next_chunk = new ChunkItem(file_item, 0); |
37 | 67 | chunk_info.output_tag_chunk = atomic_xadd64(&tag_seq_, 1); | |
38 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 43 times.
|
67 | if (file_item->has_legacy_bulk_chunk()) { |
39 |
2/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
|
24 | chunk_info.bulk_chunk = new ChunkItem(file_item, 0); |
40 | } | ||
41 | } else { | ||
42 |
2/4✓ Branch 1 taken 251455 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 251301 times.
✗ Branch 5 not taken.
|
251233 | chunk_info.bulk_chunk = new ChunkItem(file_item, 0); |
43 | } | ||
44 | |||
45 |
2/2✓ Branch 0 taken 251334 times.
✓ Branch 1 taken 34 times.
|
251368 | if (chunk_info.bulk_chunk != NULL) { |
46 |
1/2✓ Branch 1 taken 251108 times.
✗ Branch 2 not taken.
|
251334 | chunk_info.bulk_chunk->MakeBulkChunk(); |
47 | 251108 | chunk_info.bulk_chunk->set_size(file_item->size()); | |
48 | 250987 | chunk_info.output_tag_bulk = atomic_xadd64(&tag_seq_, 1); | |
49 | } | ||
50 |
1/2✓ Branch 1 taken 251171 times.
✗ Branch 2 not taken.
|
251825 | tag_map_.Insert(input_tag, chunk_info); |
51 | } | ||
52 |
3/4✓ Branch 0 taken 140523 times.
✓ Branch 1 taken 554094 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 140523 times.
|
694617 | assert((chunk_info.bulk_chunk != NULL) || (chunk_info.next_chunk != NULL)); |
53 | |||
54 | 694617 | BlockItem *output_block_bulk = NULL; | |
55 |
2/2✓ Branch 0 taken 554744 times.
✓ Branch 1 taken 139873 times.
|
694617 | if (chunk_info.bulk_chunk != NULL) { |
56 |
2/4✓ Branch 1 taken 554946 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 553711 times.
✗ Branch 5 not taken.
|
554744 | output_block_bulk = new BlockItem(chunk_info.output_tag_bulk, allocator_); |
57 |
1/2✓ Branch 1 taken 553738 times.
✗ Branch 2 not taken.
|
553711 | output_block_bulk->SetFileItem(file_item); |
58 |
1/2✓ Branch 1 taken 554025 times.
✗ Branch 2 not taken.
|
553738 | output_block_bulk->SetChunkItem(chunk_info.bulk_chunk); |
59 | } | ||
60 | |||
61 | 693898 | ChunkDetector *chunk_detector = file_item->chunk_detector(); | |
62 |
2/3✓ Branch 1 taken 250845 times.
✓ Branch 2 taken 444731 times.
✗ Branch 3 not taken.
|
694312 | switch (input_block->type()) { |
63 | 250845 | case BlockItem::kBlockStop: | |
64 | // End of the file, no more new chunks | ||
65 | 250845 | file_item->set_is_fully_chunked(); | |
66 |
2/2✓ Branch 0 taken 251558 times.
✓ Branch 1 taken 35 times.
|
251593 | if (output_block_bulk) |
67 |
1/2✓ Branch 1 taken 251026 times.
✗ Branch 2 not taken.
|
251558 | output_block_bulk->MakeStop(); |
68 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 250994 times.
|
251061 | if (chunk_info.next_chunk != NULL) { |
69 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 67 times.
|
67 | assert(file_item->size() >= chunk_info.next_chunk->offset()); |
70 | 134 | chunk_info.next_chunk->set_size(file_item->size() | |
71 | 67 | - chunk_info.next_chunk->offset()); | |
72 | BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk, | ||
73 |
2/4✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
|
67 | allocator_); |
74 |
1/2✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
|
67 | block_stop->SetFileItem(file_item); |
75 |
1/2✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
|
67 | block_stop->SetChunkItem(chunk_info.next_chunk); |
76 |
1/2✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
|
67 | block_stop->MakeStop(); |
77 |
1/2✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
|
67 | tubes_out_->Dispatch(block_stop); |
78 | } | ||
79 |
1/2✓ Branch 1 taken 250641 times.
✗ Branch 2 not taken.
|
251061 | tag_map_.Erase(input_tag); |
80 | 250641 | break; | |
81 | |||
82 | 444731 | case BlockItem::kBlockData: | |
83 |
2/2✓ Branch 0 taken 304270 times.
✓ Branch 1 taken 140461 times.
|
444731 | if (output_block_bulk) { |
84 |
2/2✓ Branch 0 taken 27120 times.
✓ Branch 1 taken 277150 times.
|
304270 | if (chunk_info.next_chunk != NULL) { |
85 | // Reserve zero-copy for the regular chunk | ||
86 |
1/2✓ Branch 3 taken 27167 times.
✗ Branch 4 not taken.
|
27120 | 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 277138 times.
✗ Branch 2 not taken.
|
277150 | output_block_bulk->MakeDataMove(input_block); |
91 | } | ||
92 | } | ||
93 | |||
94 |
2/2✓ Branch 0 taken 167610 times.
✓ Branch 1 taken 277156 times.
|
444766 | if (chunk_info.next_chunk != NULL) { |
95 | 167610 | unsigned offset_in_block = 0; | |
96 | 167610 | uint64_t cut_mark = 0; | |
97 |
3/4✓ Branch 1 taken 238017 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 70412 times.
✓ Branch 4 taken 167605 times.
|
238022 | while ((cut_mark = chunk_detector->FindNextCutMark(input_block)) != 0) { |
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70412 times.
|
70412 | assert(cut_mark >= chunk_info.offset + offset_in_block); |
99 | 70412 | const uint64_t cut_mark_in_block = cut_mark - chunk_info.offset; | |
100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70412 times.
|
70412 | assert(cut_mark_in_block >= offset_in_block); |
101 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 70412 times.
|
70412 | assert(cut_mark_in_block <= input_block->size()); |
102 | 70412 | const unsigned tail_size = cut_mark_in_block - offset_in_block; | |
103 | |||
104 |
1/2✓ Branch 0 taken 70412 times.
✗ Branch 1 not taken.
|
70412 | if (tail_size > 0) { |
105 | BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk, | ||
106 |
2/4✓ Branch 1 taken 70412 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 70412 times.
✗ Branch 5 not taken.
|
70412 | allocator_); |
107 |
1/2✓ Branch 1 taken 70412 times.
✗ Branch 2 not taken.
|
70412 | block_tail->SetFileItem(file_item); |
108 |
1/2✓ Branch 1 taken 70412 times.
✗ Branch 2 not taken.
|
70412 | block_tail->SetChunkItem(chunk_info.next_chunk); |
109 |
1/2✓ Branch 2 taken 70412 times.
✗ Branch 3 not taken.
|
70412 | block_tail->MakeDataCopy(input_block->data() + offset_in_block, |
110 | tail_size); | ||
111 |
1/2✓ Branch 1 taken 70412 times.
✗ Branch 2 not taken.
|
70412 | tubes_out_->Dispatch(block_tail); |
112 | } | ||
113 | |||
114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 70412 times.
|
70412 | 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 70398 times.
✓ Branch 2 taken 14 times.
|
70412 | if (cut_mark < file_item->size()) { |
118 | 70398 | chunk_info.next_chunk->set_size(cut_mark | |
119 | 70398 | - chunk_info.next_chunk->offset()); | |
120 | BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk, | ||
121 |
2/4✓ Branch 1 taken 70398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 70398 times.
✗ Branch 5 not taken.
|
70398 | allocator_); |
122 |
1/2✓ Branch 1 taken 70398 times.
✗ Branch 2 not taken.
|
70398 | block_stop->SetFileItem(file_item); |
123 |
1/2✓ Branch 1 taken 70398 times.
✗ Branch 2 not taken.
|
70398 | block_stop->SetChunkItem(chunk_info.next_chunk); |
124 |
1/2✓ Branch 1 taken 70398 times.
✗ Branch 2 not taken.
|
70398 | block_stop->MakeStop(); |
125 |
1/2✓ Branch 1 taken 70398 times.
✗ Branch 2 not taken.
|
70398 | tubes_out_->Dispatch(block_stop); |
126 | |||
127 |
2/4✓ Branch 1 taken 70398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 70398 times.
✗ Branch 5 not taken.
|
70398 | chunk_info.next_chunk = new ChunkItem(file_item, cut_mark); |
128 | 70398 | chunk_info.output_tag_chunk = atomic_xadd64(&tag_seq_, 1); | |
129 | } | ||
130 | 70412 | offset_in_block = cut_mark_in_block; | |
131 | } | ||
132 | 167605 | chunk_info.offset += offset_in_block; | |
133 | |||
134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 167606 times.
|
167605 | assert(input_block->size() >= offset_in_block); |
135 | 167606 | const unsigned tail_size = input_block->size() - offset_in_block; | |
136 |
2/2✓ Branch 0 taken 167524 times.
✓ Branch 1 taken 81 times.
|
167605 | if (tail_size > 0) { |
137 | BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk, | ||
138 |
2/4✓ Branch 1 taken 167524 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 167518 times.
✗ Branch 5 not taken.
|
167524 | allocator_); |
139 |
1/2✓ Branch 1 taken 167514 times.
✗ Branch 2 not taken.
|
167518 | block_tail->SetFileItem(file_item); |
140 |
1/2✓ Branch 1 taken 167514 times.
✗ Branch 2 not taken.
|
167514 | block_tail->SetChunkItem(chunk_info.next_chunk); |
141 |
1/2✓ Branch 2 taken 167533 times.
✗ Branch 3 not taken.
|
167514 | block_tail->MakeDataCopy(input_block->data() + offset_in_block, |
142 | tail_size); | ||
143 |
1/2✓ Branch 1 taken 167523 times.
✗ Branch 2 not taken.
|
167533 | tubes_out_->Dispatch(block_tail); |
144 | 167523 | chunk_info.offset += tail_size; | |
145 | } | ||
146 | |||
147 | // Delete data from incoming block | ||
148 |
1/2✓ Branch 1 taken 167606 times.
✗ Branch 2 not taken.
|
167604 | input_block->Reset(); |
149 | } | ||
150 | |||
151 |
1/2✓ Branch 1 taken 445186 times.
✗ Branch 2 not taken.
|
444762 | tag_map_.Insert(input_tag, chunk_info); |
152 | 445186 | break; | |
153 | |||
154 | ✗ | default: | |
155 | ✗ | PANIC(NULL); | |
156 | } | ||
157 | |||
158 |
2/2✓ Branch 0 taken 694758 times.
✓ Branch 1 taken 1069 times.
|
695827 | delete input_block; |
159 |
2/2✓ Branch 0 taken 555776 times.
✓ Branch 1 taken 140523 times.
|
696299 | if (output_block_bulk) |
160 |
1/2✓ Branch 1 taken 553181 times.
✗ Branch 2 not taken.
|
555776 | tubes_out_->Dispatch(output_block_bulk); |
161 | 693704 | } | |
162 |