Directory: | cvmfs/ |
---|---|
File: | cvmfs/ingestion/task_chunk.h |
Date: | 2025-02-09 02:34:19 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 15 | 15 | 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 | 355 | TaskChunk(Tube<BlockItem> *tube_in, | |
25 | TubeGroup<BlockItem> *tubes_out, | ||
26 | ItemAllocator *allocator) | ||
27 | 355 | : TubeConsumer<BlockItem>(tube_in) | |
28 | 355 | , tubes_out_(tubes_out) | |
29 |
1/2✓ Branch 2 taken 355 times.
✗ Branch 3 not taken.
|
355 | , allocator_(allocator) |
30 | { | ||
31 |
1/2✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
|
355 | tag_map_.Init(16, -1, hasher_int64t); |
32 | 355 | } | |
33 | |||
34 | protected: | ||
35 | virtual void Process(BlockItem *input_block); | ||
36 | |||
37 | private: | ||
38 | 1363178 | static inline uint32_t hasher_int64t(const int64_t &value) { | |
39 | 1363178 | return MurmurHash2(&value, sizeof(value), 0x07387a4f); | |
40 | } | ||
41 | |||
42 | /** | ||
43 | * State of the chunk creation for a file | ||
44 | */ | ||
45 | struct ChunkInfo { | ||
46 | 566732 | ChunkInfo() | |
47 | 566732 | : offset(0) | |
48 | 566732 | , output_tag_chunk(-1) | |
49 | 566732 | , output_tag_bulk(-1) | |
50 | 566732 | , next_chunk(NULL) | |
51 | 566732 | , bulk_chunk(NULL) | |
52 | 566732 | { } | |
53 | /** | ||
54 | * Sum of input block size of the file that has been processed so far | ||
55 | */ | ||
56 | uint64_t offset; | ||
57 | /** | ||
58 | * Blocks of the current regular chunk get tagged consistently | ||
59 | */ | ||
60 | int64_t output_tag_chunk; | ||
61 | /** | ||
62 | * Blocks of the corresponding bulk chunk get a unique tag | ||
63 | */ | ||
64 | int64_t output_tag_bulk; | ||
65 | /** | ||
66 | * The current regular chunk that corresponds to the output block stream; | ||
67 | * may be NULL. | ||
68 | */ | ||
69 | ChunkItem *next_chunk; | ||
70 | /** | ||
71 | * The whole file chunk attached to the file; may be NULL | ||
72 | */ | ||
73 | ChunkItem *bulk_chunk; | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * Maps input block tag (hence: file) to the state information on chunks. | ||
78 | */ | ||
79 | typedef SmallHashDynamic<int64_t, ChunkInfo> TagMap; | ||
80 | |||
81 | /** | ||
82 | * Every new chunk increases the tag sequence counter that is used to annotate | ||
83 | * BlockItems. | ||
84 | */ | ||
85 | static atomic_int64 tag_seq_; | ||
86 | |||
87 | TubeGroup<BlockItem> *tubes_out_; | ||
88 | ItemAllocator *allocator_; | ||
89 | TagMap tag_map_; | ||
90 | }; | ||
91 | |||
92 | #endif // CVMFS_INGESTION_TASK_CHUNK_H_ | ||
93 |