GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/catalog_traversal_parallel.h
Date: 2026-10-11 02:40:02
Exec Total Coverage
Lines: 187 199 94.0%
Branches: 160 244 65.6%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_CATALOG_TRAVERSAL_PARALLEL_H_
6 #define CVMFS_CATALOG_TRAVERSAL_PARALLEL_H_
7
8 #include <atomic>
9 #include <stack>
10 #include <string>
11 #include <vector>
12
13 #include "catalog_traversal.h"
14 #include "util/exception.h"
15 #include "util/tube.h"
16
17 namespace swissknife {
18
19 /**
20 * This class implements the same functionality as CatalogTraversal, but in
21 * parallel. For common functionality, see the documentation of
22 * CatalogTraversal. Differences:
23 * - can choose number of threads
24 * - traversal types change meaning:
25 * - depth-first -> parallelized post-order traversal (parents are processed
26 * after all children are finished)
27 * - breadth-first -> same as original, but parallelized
28 */
29 template<class ObjectFetcherT>
30 class CatalogTraversalParallel : public CatalogTraversalBase<ObjectFetcherT> {
31 public:
32 typedef CatalogTraversalBase<ObjectFetcherT> Base;
33 typedef ObjectFetcherT ObjectFetcherTN;
34 typedef typename ObjectFetcherT::CatalogTN CatalogTN;
35 typedef typename ObjectFetcherT::HistoryTN HistoryTN;
36 typedef CatalogTraversalData<CatalogTN> CallbackDataTN;
37 typedef typename CatalogTN::NestedCatalogList NestedCatalogList;
38 typedef typename Base::Parameters Parameters;
39 typedef typename Base::TraversalType TraversalType;
40 typedef std::vector<shash::Any> HashList;
41
42 1562 explicit CatalogTraversalParallel(const Parameters &params)
43 : CatalogTraversalBase<ObjectFetcherT>(params)
44 1562 , num_threads_(params.num_threads)
45
4/8
✓ Branch 2 taken 1562 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1562 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1562 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1562 times.
✗ Branch 12 not taken.
1562 , serialize_callbacks_(params.serialize_callbacks) {
46 1562 num_errors_.store(0);
47
1/2
✓ Branch 1 taken 1562 times.
✗ Branch 2 not taken.
1562 shash::Any null_hash;
48 1562 null_hash.SetNull();
49
1/2
✓ Branch 1 taken 1562 times.
✗ Branch 2 not taken.
1562 catalogs_processing_.Init(1024, null_hash, hasher);
50
1/2
✓ Branch 1 taken 1562 times.
✗ Branch 2 not taken.
1562 catalogs_done_.Init(1024, null_hash, hasher);
51 1562 pthread_mutex_init(&catalog_callback_lock_, NULL);
52 1562 pthread_mutex_init(&catalogs_lock_, NULL);
53 1562 effective_history_depth_ = this->default_history_depth_;
54 1562 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
55 1562 }
56
57 protected:
58 struct CatalogJob : public CatalogTraversal<ObjectFetcherT>::CatalogJob,
59 public Observable<int> {
60 16196972 explicit CatalogJob(const std::string &path,
61 const shash::Any &hash,
62 const unsigned tree_level,
63 const uint64_t history_depth,
64 CatalogTN *parent = NULL)
65 : CatalogTraversal<ObjectFetcherT>::CatalogJob(path, hash, tree_level,
66 16196972 history_depth, parent) {
67 16196972 children_unprocessed.store(0);
68 16196972 }
69
70
1/2
✓ Branch 1 taken 8079260 times.
✗ Branch 2 not taken.
8079568 void WakeParents() { this->NotifyListeners(0); }
71
72 std::atomic<int32_t> children_unprocessed;
73 };
74
75 public:
76 /**
77 * Starts the traversal process.
78 * After calling this methods CatalogTraversal will go through all catalogs
79 * and call the registered callback methods for each found catalog.
80 * If something goes wrong in the process, the traversal will be cancelled.
81 *
82 * @return true, when all catalogs were successfully processed. On
83 * failure the traversal is cancelled and false is returned.
84 */
85 857 bool Traverse(const TraversalType type = Base::kBreadthFirst) {
86
1/2
✓ Branch 1 taken 857 times.
✗ Branch 2 not taken.
857 const shash::Any root_catalog_hash = this->GetRepositoryRootCatalogHash();
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 857 times.
857 if (root_catalog_hash.IsNull()) {
88 ✗ return false;
89 }
90
1/2
✓ Branch 1 taken 857 times.
✗ Branch 2 not taken.
857 return Traverse(root_catalog_hash, type);
91 }
92
93 /**
94 * Starts the traversal process at the catalog pointed to by the given hash
95 *
96 * @param root_catalog_hash the entry point into the catalog traversal
97 * @return true when catalogs were successfully traversed
98 */
99 1517 bool Traverse(const shash::Any &root_catalog_hash,
100 const TraversalType type = Base::kBreadthFirst) {
101 // add the root catalog of the repository as the first element on the job
102 // stack
103 3034 if (this->no_repeat_history_
104
4/6
✓ Branch 0 taken 549 times.
✓ Branch 1 taken 968 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 549 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1517 times.
1517 && catalogs_done_.Contains(root_catalog_hash)) {
105 ✗ return true;
106 }
107 1517 effective_traversal_type_ = type;
108
3/6
✓ Branch 2 taken 1517 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1517 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1517 times.
✗ Branch 9 not taken.
1517 CatalogJob *root_job = new CatalogJob("", root_catalog_hash, 0, 0);
109 1517 PushJob(root_job);
110 1517 return DoTraverse();
111 }
112
113 /**
114 * Start the traversal process from a list of root catalogs. Same as
115 * TraverseRevision function, TraverseList does not traverse into predecessor
116 * catalog revisions and ignores TraversalParameter settings.
117 */
118 350 bool TraverseList(const HashList &root_catalog_list,
119 const TraversalType type = Base::kBreadthFirst) {
120 // Push in reverse order for CatalogTraversal-like behavior
121 350 HashList::const_reverse_iterator i = root_catalog_list.rbegin();
122 350 const HashList::const_reverse_iterator iend = root_catalog_list.rend();
123 350 bool has_pushed = false;
124 {
125 350 MutexLockGuard const m(&catalogs_lock_);
126
3/4
✓ Branch 2 taken 1353 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1003 times.
✓ Branch 5 taken 350 times.
1353 for (; i != iend; ++i) {
127
7/8
✓ Branch 0 taken 607 times.
✓ Branch 1 taken 396 times.
✓ Branch 4 taken 607 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 573 times.
✓ Branch 8 taken 34 times.
✓ Branch 9 taken 969 times.
1003 if (this->no_repeat_history_ && catalogs_done_.Contains(*i)) {
128 34 continue;
129 }
130
131
3/6
✓ Branch 2 taken 969 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 969 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 969 times.
✗ Branch 10 not taken.
969 CatalogJob *root_job = new CatalogJob("", *i, 0, 0);
132
1/2
✓ Branch 1 taken 969 times.
✗ Branch 2 not taken.
969 PushJobUnlocked(root_job);
133 969 has_pushed = true;
134 }
135 350 }
136 // noop: no catalogs to traverse
137
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 337 times.
350 if (!has_pushed) {
138 13 return true;
139 }
140 337 effective_traversal_type_ = type;
141 337 effective_history_depth_ = Parameters::kNoHistory;
142 337 effective_timestamp_threshold_ = Parameters::kNoTimestampThreshold;
143
1/2
✓ Branch 1 taken 337 times.
✗ Branch 2 not taken.
337 bool const result = DoTraverse();
144 337 effective_history_depth_ = this->default_history_depth_;
145 337 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
146 337 return result;
147 }
148
149 /**
150 * Starts the traversal process at the catalog pointed to by the given hash
151 * but doesn't traverse into predecessor catalog revisions. This overrides the
152 * TraversalParameter settings provided at construction.
153 *
154 * @param root_catalog_hash the entry point into the catalog traversal
155 * @return true when catalogs were successfully traversed
156 */
157 88 bool TraverseRevision(const shash::Any &root_catalog_hash,
158 const TraversalType type = Base::kBreadthFirst) {
159 88 effective_history_depth_ = Parameters::kNoHistory;
160 88 effective_timestamp_threshold_ = Parameters::kNoTimestampThreshold;
161 88 bool const result = Traverse(root_catalog_hash, type);
162 88 effective_history_depth_ = this->default_history_depth_;
163 88 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
164 88 return result;
165 }
166
167 protected:
168 74507834 static uint32_t hasher(const shash::Any &key) {
169 // Don't start with the first bytes, because == is using them as well
170 return static_cast<uint32_t>(
171 74507834 *(reinterpret_cast<const uint32_t *>(key.digest) + 1));
172 }
173
174 1854 bool DoTraverse() {
175 // Optimal number of threads is yet to be determined. The main event loop
176 // contains a spin-lock, so it should not be more than number of cores.
177 1854 threads_process_ = reinterpret_cast<pthread_t *>(
178 1854 smalloc(sizeof(pthread_t) * num_threads_));
179
2/2
✓ Branch 0 taken 2470 times.
✓ Branch 1 taken 1854 times.
4324 for (unsigned int i = 0; i < num_threads_; ++i) {
180 2470 int const retval = pthread_create(&threads_process_[i], NULL,
181 MainProcessQueue, this);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2470 times.
2470 if (retval != 0)
183 ✗ PANIC(kLogStderr, "failed to create thread");
184 }
185
186
2/2
✓ Branch 0 taken 2470 times.
✓ Branch 1 taken 1854 times.
4324 for (unsigned int i = 0; i < num_threads_; ++i) {
187 2470 int const retval = pthread_join(threads_process_[i], NULL);
188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2470 times.
2470 assert(retval == 0);
189 }
190 1854 free(threads_process_);
191
192
2/2
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 1810 times.
3708 if (num_errors_.load())
193 44 return false;
194
195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1810 times.
1810 assert(catalogs_processing_.size() == 0);
196
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1810 times.
1810 assert(pre_job_queue_.IsEmpty());
197
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1810 times.
1810 assert(post_job_queue_.IsEmpty());
198 1810 return true;
199 }
200
201 2470 static void *MainProcessQueue(void *data) {
202 2470 CatalogTraversalParallel<ObjectFetcherT> *traversal = reinterpret_cast<
203 CatalogTraversalParallel<ObjectFetcherT> *>(data);
204 CatalogJob *current_job;
205 while (true) {
206 17688555 current_job = traversal->post_job_queue_.TryPopFront();
207
2/2
✓ Branch 0 taken 1494047 times.
✓ Branch 1 taken 16195740 times.
17689787 if (current_job != NULL) {
208 1494047 traversal->ProcessJobPost(current_job);
209 } else {
210 16195740 current_job = traversal->pre_job_queue_.PopFront();
211 // NULL means the master thread tells us to finish
212
2/2
✓ Branch 1 taken 2470 times.
✓ Branch 2 taken 16194238 times.
16196796 if (current_job->hash.IsNull()) {
213
1/2
✓ Branch 0 taken 2470 times.
✗ Branch 1 not taken.
2470 delete current_job;
214 2470 break;
215 }
216 16194238 traversal->ProcessJobPre(current_job);
217 }
218 }
219 2470 return NULL;
220 }
221
222 1854 void NotifyFinished() {
223
1/2
✓ Branch 1 taken 1854 times.
✗ Branch 2 not taken.
1854 shash::Any null_hash;
224 1854 null_hash.SetNull();
225
2/2
✓ Branch 0 taken 2470 times.
✓ Branch 1 taken 1854 times.
4324 for (unsigned i = 0; i < num_threads_; ++i) {
226
3/6
✓ Branch 2 taken 2470 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2470 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2470 times.
✗ Branch 9 not taken.
2470 CatalogJob *job = new CatalogJob("", null_hash, 0, 0);
227
1/2
✓ Branch 1 taken 2470 times.
✗ Branch 2 not taken.
2470 pre_job_queue_.EnqueueFront(job);
228 }
229 1854 }
230
231 1517 void PushJob(CatalogJob *job) {
232 1517 MutexLockGuard const m(&catalogs_lock_);
233
1/2
✓ Branch 1 taken 1517 times.
✗ Branch 2 not taken.
1517 PushJobUnlocked(job);
234 1517 }
235
236 16194502 void PushJobUnlocked(CatalogJob *job) {
237 16194502 catalogs_processing_.Insert(job->hash, job);
238 16194502 pre_job_queue_.EnqueueFront(job);
239 16194502 }
240
241 16194150 void ProcessJobPre(CatalogJob *job) {
242
4/6
✓ Branch 0 taken 16194150 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 16189442 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 44 times.
✓ Branch 6 taken 16189398 times.
16194150 if (!this->PrepareCatalog(job)) {
243 44 num_errors_.fetch_add(1);
244
1/2
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
44 NotifyFinished();
245 14697155 return;
246 }
247
2/2
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 16189263 times.
16189398 if (job->ignore) {
248
1/2
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
135 FinalizeJob(job);
249 135 return;
250 }
251
1/2
✓ Branch 1 taken 16153271 times.
✗ Branch 2 not taken.
16189263 NestedCatalogList const catalog_list = job->catalog
252 ->ListOwnNestedCatalogs();
253 unsigned int num_children;
254 // Ensure that pushed children won't call ProcessJobPost on this job
255 // before this function finishes
256 {
257 16153271 MutexLockGuard const m(&catalogs_lock_);
258
2/2
✓ Branch 0 taken 8114229 times.
✓ Branch 1 taken 8080050 times.
16194279 if (effective_traversal_type_ == Base::kBreadthFirst) {
259
1/2
✓ Branch 1 taken 8114229 times.
✗ Branch 2 not taken.
8114229 num_children = PushPreviousRevision(job)
260
1/2
✓ Branch 1 taken 8114229 times.
✗ Branch 2 not taken.
8114229 + PushNestedCatalogs(job, catalog_list);
261 } else {
262
1/2
✓ Branch 1 taken 8080050 times.
✗ Branch 2 not taken.
8080050 num_children = PushNestedCatalogs(job, catalog_list)
263
1/2
✓ Branch 1 taken 8080050 times.
✗ Branch 2 not taken.
8080050 + PushPreviousRevision(job);
264 8080050 job->children_unprocessed.store(num_children);
265 }
266
3/6
✓ Branch 0 taken 16194279 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 16194279 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 16194279 times.
16194279 if (!this->CloseCatalog(false, job)) {
267 ✗ num_errors_.fetch_add(1);
268 ✗ NotifyFinished();
269 }
270 16194279 }
271
272 // breadth-first: can post-process immediately
273 // depth-first: no children -> can post-process immediately
274
4/4
✓ Branch 0 taken 8079478 times.
✓ Branch 1 taken 8114053 times.
✓ Branch 2 taken 6585431 times.
✓ Branch 3 taken 1494047 times.
16193531 if (effective_traversal_type_ == Base::kBreadthFirst || num_children == 0) {
275
1/2
✓ Branch 1 taken 14696756 times.
✗ Branch 2 not taken.
14699484 ProcessJobPost(job);
276 14696756 return;
277 }
278
2/2
✓ Branch 1 taken 1494047 times.
✓ Branch 2 taken 14696976 times.
16190803 }
279
280 16194279 unsigned int PushNestedCatalogs(CatalogJob *job,
281 const NestedCatalogList &catalog_list) {
282 16194279 typename NestedCatalogList::const_iterator i = catalog_list.begin();
283 16194279 typename NestedCatalogList::const_iterator const iend = catalog_list.end();
284 16194279 unsigned int num_children = 0;
285
2/2
✓ Branch 2 taken 16192530 times.
✓ Branch 3 taken 16194279 times.
32386809 for (; i != iend; ++i) {
286
7/8
✓ Branch 0 taken 18482 times.
✓ Branch 1 taken 16174048 times.
✓ Branch 4 taken 18482 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2432 times.
✓ Branch 7 taken 16050 times.
✓ Branch 8 taken 2432 times.
✓ Branch 9 taken 16190098 times.
16192530 if (this->no_repeat_history_ && catalogs_done_.Contains(i->hash)) {
287 2432 continue;
288 }
289
290 CatalogJob *child;
291 32380196 if (!this->no_repeat_history_
292
7/8
✓ Branch 0 taken 16050 times.
✓ Branch 1 taken 16174048 times.
✓ Branch 4 taken 16050 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15698 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 16189746 times.
✓ Branch 9 taken 352 times.
16190098 || !catalogs_processing_.Lookup(i->hash, &child)) {
293
2/2
✓ Branch 0 taken 16132028 times.
✓ Branch 1 taken 57718 times.
16189746 CatalogTN *parent = (this->no_close_) ? job->catalog : NULL;
294
1/2
✓ Branch 2 taken 16189746 times.
✗ Branch 3 not taken.
32379492 child = new CatalogJob(i->mountpoint.ToString(),
295
1/2
✓ Branch 2 taken 16189746 times.
✗ Branch 3 not taken.
16189746 i->hash,
296 16189746 job->tree_level + 1,
297
1/2
✓ Branch 1 taken 16189746 times.
✗ Branch 2 not taken.
16189746 job->history_depth,
298 parent);
299
1/2
✓ Branch 1 taken 16189746 times.
✗ Branch 2 not taken.
16189746 PushJobUnlocked(child);
300 }
301
302
2/2
✓ Branch 0 taken 8079234 times.
✓ Branch 1 taken 8110864 times.
16190098 if (effective_traversal_type_ == Base::kDepthFirst) {
303
1/2
✓ Branch 1 taken 8079234 times.
✗ Branch 2 not taken.
8079234 child->RegisterListener(&CatalogTraversalParallel::OnChildFinished,
304 this, job);
305 }
306 16190098 ++num_children;
307 }
308 16194279 return num_children;
309 }
310
311 /**
312 * Pushes the previous revision of a root catalog.
313 * @return the number of catalogs pushed on the processing stack
314 */
315 16194279 unsigned int PushPreviousRevision(CatalogJob *job) {
316 // only root catalogs are used for entering a previous revision (graph)
317
2/2
✓ Branch 1 taken 16189657 times.
✓ Branch 2 taken 4622 times.
16194279 if (!job->catalog->IsRoot()) {
318 16189657 return 0;
319 }
320
321
1/2
✓ Branch 1 taken 4622 times.
✗ Branch 2 not taken.
4622 const shash::Any previous_revision = job->catalog->GetPreviousRevision();
322
2/2
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 4302 times.
4622 if (previous_revision.IsNull()) {
323 320 return 0;
324 }
325
326 // check if the next deeper history level is actually requested
327
3/4
✓ Branch 1 taken 4302 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2032 times.
✓ Branch 4 taken 2270 times.
4302 if (this->IsBelowPruningThresholds(*job, effective_history_depth_,
328 effective_timestamp_threshold_)) {
329 2032 return 0;
330 }
331
332 4540 if (this->no_repeat_history_
333
5/8
✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 1232 times.
✓ Branch 3 taken 1038 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1038 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2270 times.
2270 && catalogs_done_.Contains(previous_revision)) {
334 ✗ return 0;
335 }
336
337 CatalogJob *prev_job;
338 4540 if (!this->no_repeat_history_
339
5/8
✓ Branch 0 taken 1038 times.
✓ Branch 1 taken 1232 times.
✓ Branch 3 taken 1038 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1038 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2270 times.
✗ Branch 8 not taken.
2270 || !catalogs_processing_.Lookup(previous_revision, &prev_job)) {
340
2/4
✓ Branch 2 taken 2270 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2270 times.
✗ Branch 6 not taken.
4540 prev_job = new CatalogJob("", previous_revision, 0,
341
1/2
✓ Branch 1 taken 2270 times.
✗ Branch 2 not taken.
2270 job->history_depth + 1);
342
1/2
✓ Branch 1 taken 2270 times.
✗ Branch 2 not taken.
2270 PushJobUnlocked(prev_job);
343 }
344
345
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 1610 times.
2270 if (effective_traversal_type_ == Base::kDepthFirst) {
346
1/2
✓ Branch 1 taken 660 times.
✗ Branch 2 not taken.
660 prev_job->RegisterListener(&CatalogTraversalParallel::OnChildFinished,
347 this, job);
348 }
349 2270 return 1;
350 }
351
352 16192871 void ProcessJobPost(CatalogJob *job) {
353 // Save time by keeping catalog open when suitable
354
1/2
✓ Branch 0 taken 16192871 times.
✗ Branch 1 not taken.
16192871 if (job->catalog == NULL) {
355
2/4
✓ Branch 0 taken 16192871 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 16136991 times.
16192871 if (!this->ReopenCatalog(job)) {
356 ✗ num_errors_.fetch_add(1);
357 ✗ NotifyFinished();
358 ✗ return;
359 }
360 }
361
2/2
✓ Branch 0 taken 16136419 times.
✓ Branch 1 taken 572 times.
16136991 if (serialize_callbacks_) {
362 16136419 MutexLockGuard const m(&catalog_callback_lock_);
363
2/4
✓ Branch 1 taken 16194279 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16194279 times.
✗ Branch 5 not taken.
16194279 this->NotifyListeners(job->GetCallbackData());
364 16194279 } else {
365
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
572 this->NotifyListeners(job->GetCallbackData());
366 }
367
2/2
✓ Branch 0 taken 62031 times.
✓ Branch 1 taken 16131896 times.
16193927 if (!this->no_close_) {
368
2/4
✓ Branch 0 taken 62031 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 62031 times.
62031 if (!this->CloseCatalog(true, job)) {
369 ✗ num_errors_.fetch_add(1);
370 ✗ NotifyFinished();
371 ✗ return;
372 }
373 }
374 16193927 FinalizeJob(job);
375 }
376
377 16193974 void FinalizeJob(CatalogJob *job) {
378 {
379 16193974 MutexLockGuard const m(&catalogs_lock_);
380
1/2
✓ Branch 1 taken 16194414 times.
✗ Branch 2 not taken.
16194414 catalogs_processing_.Erase(job->hash);
381
1/2
✓ Branch 1 taken 16194414 times.
✗ Branch 2 not taken.
16194414 catalogs_done_.Insert(job->hash, true);
382 // No more catalogs to process -> finish
383
1/2
✓ Branch 2 taken 1810 times.
✗ Branch 3 not taken.
16196224 if (catalogs_processing_.size() == 0 && pre_job_queue_.IsEmpty()
384
5/6
✓ Branch 0 taken 1810 times.
✓ Branch 1 taken 16192604 times.
✓ Branch 3 taken 1810 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1810 times.
✓ Branch 6 taken 16192604 times.
16196224 && post_job_queue_.IsEmpty()) {
385
1/2
✓ Branch 1 taken 1810 times.
✗ Branch 2 not taken.
1810 NotifyFinished();
386 }
387 16194414 }
388
2/2
✓ Branch 0 taken 8079744 times.
✓ Branch 1 taken 8114494 times.
16194238 if (effective_traversal_type_ == Base::kDepthFirst) {
389 8079744 job->WakeParents();
390 }
391
2/2
✓ Branch 0 taken 16193270 times.
✓ Branch 1 taken 396 times.
16193666 delete job;
392 16191686 }
393
394 8079454 void OnChildFinished(const int &a, CatalogJob *job) {
395 // atomic_xadd32 returns value before subtraction -> needs to equal 1
396
2/2
✓ Branch 0 taken 1494047 times.
✓ Branch 1 taken 6585407 times.
16158908 if (job->children_unprocessed.fetch_add(-1) == 1) {
397 1494047 post_job_queue_.EnqueueFront(job);
398 }
399 8079454 }
400
401 unsigned int num_threads_;
402 bool serialize_callbacks_;
403
404 uint64_t effective_history_depth_;
405 time_t effective_timestamp_threshold_;
406 TraversalType effective_traversal_type_;
407
408 pthread_t *threads_process_;
409 std::atomic<int32_t> num_errors_;
410
411 Tube<CatalogJob> pre_job_queue_;
412 Tube<CatalogJob> post_job_queue_;
413 SmallHashDynamic<shash::Any, CatalogJob *> catalogs_processing_;
414 SmallHashDynamic<shash::Any, bool> catalogs_done_;
415 pthread_mutex_t catalogs_lock_;
416
417 pthread_mutex_t catalog_callback_lock_;
418 };
419
420 } // namespace swissknife
421
422 #endif // CVMFS_CATALOG_TRAVERSAL_PARALLEL_H_
423