| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/ingestion/task_chunk.cc |
| Date: | 2026-05-19 11:45:12 |
| 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 | 15878995 | void TaskChunk::Process(BlockItem *input_block) { | |
| 25 | 15878995 | FileItem *file_item = input_block->file_item(); | |
| 26 | 15870063 | const int64_t input_tag = input_block->tag(); | |
| 27 |
2/4✓ Branch 0 taken 15887255 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15887815 times.
✗ Branch 3 not taken.
|
15884875 | assert((file_item != NULL) && (input_tag >= 0)); |
| 28 | |||
| 29 | 15887815 | ChunkInfo chunk_info; | |
| 30 | // Do we see blocks of the file for the first time? | ||
| 31 |
3/4✓ Branch 1 taken 15936171 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6988786 times.
✓ Branch 4 taken 8947385 times.
|
15881963 | 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 504 times.
✓ Branch 2 taken 6987750 times.
|
6988786 | if (file_item->may_have_chunks()) { |
| 36 |
2/4✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 504 times.
✗ Branch 5 not taken.
|
504 | chunk_info.next_chunk = new ChunkItem(file_item, 0); |
| 37 | 504 | chunk_info.output_tag_chunk = atomic_xadd64(&tag_seq_, 1); | |
| 38 |
2/2✓ Branch 1 taken 329 times.
✓ Branch 2 taken 175 times.
|
504 | if (file_item->has_legacy_bulk_chunk()) { |
| 39 |
2/4✓ Branch 1 taken 329 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 329 times.
✗ Branch 5 not taken.
|
329 | chunk_info.bulk_chunk = new ChunkItem(file_item, 0); |
| 40 | } | ||
| 41 | } else { | ||
| 42 |
2/4✓ Branch 1 taken 6994078 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6989990 times.
✗ Branch 5 not taken.
|
6987750 | chunk_info.bulk_chunk = new ChunkItem(file_item, 0); |
| 43 | } | ||
| 44 | |||
| 45 |
1/2✓ Branch 0 taken 6990739 times.
✗ Branch 1 not taken.
|
6990494 | if (chunk_info.bulk_chunk != NULL) { |
| 46 |
1/2✓ Branch 1 taken 6985083 times.
✗ Branch 2 not taken.
|
6990739 | chunk_info.bulk_chunk->MakeBulkChunk(); |
| 47 | 6985083 | chunk_info.bulk_chunk->set_size(file_item->size()); | |
| 48 | 6982059 | chunk_info.output_tag_bulk = atomic_xadd64(&tag_seq_, 1); | |
| 49 | } | ||
| 50 |
1/2✓ Branch 1 taken 6982654 times.
✗ Branch 2 not taken.
|
6999650 | tag_map_.Insert(input_tag, chunk_info); |
| 51 | } | ||
| 52 |
3/4✓ Branch 0 taken 498127 times.
✓ Branch 1 taken 15431912 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 498127 times.
|
15930039 | assert((chunk_info.bulk_chunk != NULL) || (chunk_info.next_chunk != NULL)); |
| 53 | |||
| 54 | 15930039 | BlockItem *output_block_bulk = NULL; | |
| 55 |
2/2✓ Branch 0 taken 15444876 times.
✓ Branch 1 taken 485163 times.
|
15930039 | if (chunk_info.bulk_chunk != NULL) { |
| 56 |
2/4✓ Branch 1 taken 15450812 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15408868 times.
✗ Branch 5 not taken.
|
15444876 | output_block_bulk = new BlockItem(chunk_info.output_tag_bulk, allocator_); |
| 57 |
1/2✓ Branch 1 taken 15409232 times.
✗ Branch 2 not taken.
|
15408868 | output_block_bulk->SetFileItem(file_item); |
| 58 |
1/2✓ Branch 1 taken 15413208 times.
✗ Branch 2 not taken.
|
15409232 | output_block_bulk->SetChunkItem(chunk_info.bulk_chunk); |
| 59 | } | ||
| 60 | |||
| 61 | 15898371 | ChunkDetector *chunk_detector = file_item->chunk_detector(); | |
| 62 |
2/3✓ Branch 1 taken 6974926 times.
✓ Branch 2 taken 8964129 times.
✗ Branch 3 not taken.
|
15906659 | switch (input_block->type()) { |
| 63 | 6974926 | case BlockItem::kBlockStop: | |
| 64 | // End of the file, no more new chunks | ||
| 65 | 6974926 | file_item->set_is_fully_chunked(); | |
| 66 |
2/2✓ Branch 0 taken 6994267 times.
✓ Branch 1 taken 63 times.
|
6994330 | if (output_block_bulk) |
| 67 |
1/2✓ Branch 1 taken 6981555 times.
✗ Branch 2 not taken.
|
6994267 | output_block_bulk->MakeStop(); |
| 68 |
2/2✓ Branch 0 taken 504 times.
✓ Branch 1 taken 6981114 times.
|
6981618 | if (chunk_info.next_chunk != NULL) { |
| 69 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 504 times.
|
504 | assert(file_item->size() >= chunk_info.next_chunk->offset()); |
| 70 | 1008 | chunk_info.next_chunk->set_size(file_item->size() | |
| 71 | 504 | - chunk_info.next_chunk->offset()); | |
| 72 | BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk, | ||
| 73 |
2/4✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 504 times.
✗ Branch 5 not taken.
|
504 | allocator_); |
| 74 |
1/2✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
|
504 | block_stop->SetFileItem(file_item); |
| 75 |
1/2✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
|
504 | block_stop->SetChunkItem(chunk_info.next_chunk); |
| 76 |
1/2✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
|
504 | block_stop->MakeStop(); |
| 77 |
1/2✓ Branch 1 taken 504 times.
✗ Branch 2 not taken.
|
504 | tubes_out_->Dispatch(block_stop); |
| 78 | } | ||
| 79 |
1/2✓ Branch 1 taken 6969970 times.
✗ Branch 2 not taken.
|
6981618 | tag_map_.Erase(input_tag); |
| 80 | 6969970 | break; | |
| 81 | |||
| 82 | 8964129 | case BlockItem::kBlockData: | |
| 83 |
2/2✓ Branch 0 taken 8466289 times.
✓ Branch 1 taken 497840 times.
|
8964129 | if (output_block_bulk) { |
| 84 |
2/2✓ Branch 0 taken 758688 times.
✓ Branch 1 taken 7707601 times.
|
8466289 | if (chunk_info.next_chunk != NULL) { |
| 85 | // Reserve zero-copy for the regular chunk | ||
| 86 |
1/2✓ Branch 3 taken 760116 times.
✗ Branch 4 not taken.
|
758688 | 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 7706649 times.
✗ Branch 2 not taken.
|
7707601 | output_block_bulk->MakeDataMove(input_block); |
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 |
2/2✓ Branch 0 taken 1257396 times.
✓ Branch 1 taken 7707209 times.
|
8964605 | if (chunk_info.next_chunk != NULL) { |
| 95 | 1257396 | unsigned offset_in_block = 0; | |
| 96 | 1257396 | uint64_t cut_mark = 0; | |
| 97 |
3/4✓ Branch 1 taken 1513645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 256193 times.
✓ Branch 4 taken 1257452 times.
|
1513589 | while ((cut_mark = chunk_detector->FindNextCutMark(input_block)) != 0) { |
| 98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 256193 times.
|
256193 | assert(cut_mark >= chunk_info.offset + offset_in_block); |
| 99 | 256193 | const uint64_t cut_mark_in_block = cut_mark - chunk_info.offset; | |
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 256193 times.
|
256193 | assert(cut_mark_in_block >= offset_in_block); |
| 101 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 256193 times.
|
256193 | assert(cut_mark_in_block <= input_block->size()); |
| 102 | 256193 | const unsigned tail_size = cut_mark_in_block - offset_in_block; | |
| 103 | |||
| 104 |
1/2✓ Branch 0 taken 256193 times.
✗ Branch 1 not taken.
|
256193 | if (tail_size > 0) { |
| 105 | BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk, | ||
| 106 |
2/4✓ Branch 1 taken 256193 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 256193 times.
✗ Branch 5 not taken.
|
256193 | allocator_); |
| 107 |
1/2✓ Branch 1 taken 256193 times.
✗ Branch 2 not taken.
|
256193 | block_tail->SetFileItem(file_item); |
| 108 |
1/2✓ Branch 1 taken 256193 times.
✗ Branch 2 not taken.
|
256193 | block_tail->SetChunkItem(chunk_info.next_chunk); |
| 109 |
1/2✓ Branch 2 taken 256193 times.
✗ Branch 3 not taken.
|
256193 | block_tail->MakeDataCopy(input_block->data() + offset_in_block, |
| 110 | tail_size); | ||
| 111 |
1/2✓ Branch 1 taken 256193 times.
✗ Branch 2 not taken.
|
256193 | tubes_out_->Dispatch(block_tail); |
| 112 | } | ||
| 113 | |||
| 114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 256193 times.
|
256193 | 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 256144 times.
✓ Branch 2 taken 49 times.
|
256193 | if (cut_mark < file_item->size()) { |
| 118 | 256144 | chunk_info.next_chunk->set_size(cut_mark | |
| 119 | 256144 | - chunk_info.next_chunk->offset()); | |
| 120 | BlockItem *block_stop = new BlockItem(chunk_info.output_tag_chunk, | ||
| 121 |
2/4✓ Branch 1 taken 256144 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 256144 times.
✗ Branch 5 not taken.
|
256144 | allocator_); |
| 122 |
1/2✓ Branch 1 taken 256144 times.
✗ Branch 2 not taken.
|
256144 | block_stop->SetFileItem(file_item); |
| 123 |
1/2✓ Branch 1 taken 256144 times.
✗ Branch 2 not taken.
|
256144 | block_stop->SetChunkItem(chunk_info.next_chunk); |
| 124 |
1/2✓ Branch 1 taken 256144 times.
✗ Branch 2 not taken.
|
256144 | block_stop->MakeStop(); |
| 125 |
1/2✓ Branch 1 taken 256144 times.
✗ Branch 2 not taken.
|
256144 | tubes_out_->Dispatch(block_stop); |
| 126 | |||
| 127 |
2/4✓ Branch 1 taken 256144 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 256144 times.
✗ Branch 5 not taken.
|
256144 | chunk_info.next_chunk = new ChunkItem(file_item, cut_mark); |
| 128 | 256144 | chunk_info.output_tag_chunk = atomic_xadd64(&tag_seq_, 1); | |
| 129 | } | ||
| 130 | 256193 | offset_in_block = cut_mark_in_block; | |
| 131 | } | ||
| 132 | 1257452 | chunk_info.offset += offset_in_block; | |
| 133 | |||
| 134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1257424 times.
|
1257452 | assert(input_block->size() >= offset_in_block); |
| 135 | 1257424 | const unsigned tail_size = input_block->size() - offset_in_block; | |
| 136 |
2/2✓ Branch 0 taken 1255954 times.
✓ Branch 1 taken 1470 times.
|
1257424 | if (tail_size > 0) { |
| 137 | BlockItem *block_tail = new BlockItem(chunk_info.output_tag_chunk, | ||
| 138 |
2/4✓ Branch 1 taken 1255786 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1255506 times.
✗ Branch 5 not taken.
|
1255954 | allocator_); |
| 139 |
1/2✓ Branch 1 taken 1255310 times.
✗ Branch 2 not taken.
|
1255506 | block_tail->SetFileItem(file_item); |
| 140 |
1/2✓ Branch 1 taken 1255394 times.
✗ Branch 2 not taken.
|
1255310 | block_tail->SetChunkItem(chunk_info.next_chunk); |
| 141 |
1/2✓ Branch 2 taken 1255982 times.
✗ Branch 3 not taken.
|
1255394 | block_tail->MakeDataCopy(input_block->data() + offset_in_block, |
| 142 | tail_size); | ||
| 143 |
1/2✓ Branch 1 taken 1255730 times.
✗ Branch 2 not taken.
|
1255982 | tubes_out_->Dispatch(block_tail); |
| 144 | 1255730 | chunk_info.offset += tail_size; | |
| 145 | } | ||
| 146 | |||
| 147 | // Delete data from incoming block | ||
| 148 |
1/2✓ Branch 1 taken 1257648 times.
✗ Branch 2 not taken.
|
1257200 | input_block->Reset(); |
| 149 | } | ||
| 150 | |||
| 151 |
1/2✓ Branch 1 taken 8970373 times.
✗ Branch 2 not taken.
|
8964857 | tag_map_.Insert(input_tag, chunk_info); |
| 152 | 8970373 | break; | |
| 153 | |||
| 154 | ✗ | default: | |
| 155 | ✗ | PANIC(NULL); | |
| 156 | } | ||
| 157 | |||
| 158 |
2/2✓ Branch 0 taken 15912371 times.
✓ Branch 1 taken 27972 times.
|
15940343 | delete input_block; |
| 159 |
2/2✓ Branch 0 taken 15464616 times.
✓ Branch 1 taken 498127 times.
|
15962743 | if (output_block_bulk) |
| 160 |
1/2✓ Branch 1 taken 15394616 times.
✗ Branch 2 not taken.
|
15464616 | tubes_out_->Dispatch(output_block_bulk); |
| 161 | 15892743 | } | |
| 162 |