Directory: | cvmfs/ |
---|---|
File: | cvmfs/ingestion/task_chunk.h |
Date: | 2025-06-22 02:36:02 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 14 | 14 | 100.0% |
Branches: | 2 | 4 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * This file is part of the CernVM File System. | ||
3 | */ | ||
4 | |||
5 | #ifndef CVMFS_INGESTION_TASK_CHUNK_H_ | ||
6 | #define CVMFS_INGESTION_TASK_CHUNK_H_ | ||
7 | |||
8 | #include <stdint.h> | ||
9 | |||
10 | #include <map> | ||
11 | |||
12 | #include "ingestion/item.h" | ||
13 | #include "ingestion/task.h" | ||
14 | #include "smallhash.h" | ||
15 | #include "util/atomic.h" | ||
16 | #include "util/murmur.hxx" | ||
17 | #include "util/posix.h" | ||
18 | #include "util/tube.h" | ||
19 | |||
20 | class ItemAllocator; | ||
21 | |||
22 | class TaskChunk : public TubeConsumer<BlockItem> { | ||
23 | public: | ||
24 | 8986 | TaskChunk(Tube<BlockItem> *tube_in, | |
25 | TubeGroup<BlockItem> *tubes_out, | ||
26 | ItemAllocator *allocator) | ||
27 | 8986 | : TubeConsumer<BlockItem>(tube_in) | |
28 | 8986 | , tubes_out_(tubes_out) | |
29 |
1/2✓ Branch 2 taken 8986 times.
✗ Branch 3 not taken.
|
8986 | , allocator_(allocator) { |
30 |
1/2✓ Branch 1 taken 8986 times.
✗ Branch 2 not taken.
|
8986 | tag_map_.Init(16, -1, hasher_int64t); |
31 | 8986 | } | |
32 | |||
33 | protected: | ||
34 | virtual void Process(BlockItem *input_block); | ||
35 | |||
36 | private: | ||
37 | 1630783 | static inline uint32_t hasher_int64t(const int64_t &value) { | |
38 | 1630783 | return MurmurHash2(&value, sizeof(value), 0x07387a4f); | |
39 | } | ||
40 | |||
41 | /** | ||
42 | * State of the chunk creation for a file | ||
43 | */ | ||
44 | struct ChunkInfo { | ||
45 | 881918 | ChunkInfo() | |
46 | 881918 | : offset(0) | |
47 | 881918 | , output_tag_chunk(-1) | |
48 | 881918 | , output_tag_bulk(-1) | |
49 | 881918 | , next_chunk(NULL) | |
50 | 881918 | , bulk_chunk(NULL) { } | |
51 | /** | ||
52 | * Sum of input block size of the file that has been processed so far | ||
53 | */ | ||
54 | uint64_t offset; | ||
55 | /** | ||
56 | * Blocks of the current regular chunk get tagged consistently | ||
57 | */ | ||
58 | int64_t output_tag_chunk; | ||
59 | /** | ||
60 | * Blocks of the corresponding bulk chunk get a unique tag | ||
61 | */ | ||
62 | int64_t output_tag_bulk; | ||
63 | /** | ||
64 | * The current regular chunk that corresponds to the output block stream; | ||
65 | * may be NULL. | ||
66 | */ | ||
67 | ChunkItem *next_chunk; | ||
68 | /** | ||
69 | * The whole file chunk attached to the file; may be NULL | ||
70 | */ | ||
71 | ChunkItem *bulk_chunk; | ||
72 | }; | ||
73 | |||
74 | /** | ||
75 | * Maps input block tag (hence: file) to the state information on chunks. | ||
76 | */ | ||
77 | typedef SmallHashDynamic<int64_t, ChunkInfo> TagMap; | ||
78 | |||
79 | /** | ||
80 | * Every new chunk increases the tag sequence counter that is used to annotate | ||
81 | * BlockItems. | ||
82 | */ | ||
83 | static atomic_int64 tag_seq_; | ||
84 | |||
85 | TubeGroup<BlockItem> *tubes_out_; | ||
86 | ItemAllocator *allocator_; | ||
87 | TagMap tag_map_; | ||
88 | }; | ||
89 | |||
90 | #endif // CVMFS_INGESTION_TASK_CHUNK_H_ | ||
91 |