GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/catalog_traversal_parallel.h
Date: 2026-11-01 02:41:19
Exec Total Coverage
Lines: 186 199 93.5%
Branches: 159 244 65.2%

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 2720 explicit CatalogTraversalParallel(const Parameters &params)
43 : CatalogTraversalBase<ObjectFetcherT>(params)
44 2720 , num_threads_(params.num_threads)
45
4/8
✓ Branch 2 taken 2720 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2720 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2720 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 2720 times.
✗ Branch 12 not taken.
2720 , serialize_callbacks_(params.serialize_callbacks) {
46 2720 num_errors_.store(0);
47
1/2
✓ Branch 1 taken 2720 times.
✗ Branch 2 not taken.
2720 shash::Any null_hash;
48 2720 null_hash.SetNull();
49
1/2
✓ Branch 1 taken 2720 times.
✗ Branch 2 not taken.
2720 catalogs_processing_.Init(1024, null_hash, hasher);
50
1/2
✓ Branch 1 taken 2720 times.
✗ Branch 2 not taken.
2720 catalogs_done_.Init(1024, null_hash, hasher);
51 2720 pthread_mutex_init(&catalog_callback_lock_, NULL);
52 2720 pthread_mutex_init(&catalogs_lock_, NULL);
53 2720 effective_history_depth_ = this->default_history_depth_;
54 2720 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
55 2720 }
56
57 protected:
58 struct CatalogJob : public CatalogTraversal<ObjectFetcherT>::CatalogJob,
59 public Observable<int> {
60 14744924 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 14744924 history_depth, parent) {
67 14744924 children_unprocessed.store(0);
68 14744924 }
69
70
1/2
✓ Branch 1 taken 7347752 times.
✗ Branch 2 not taken.
7348312 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 1992 bool Traverse(const TraversalType type = Base::kBreadthFirst) {
86
1/2
✓ Branch 1 taken 1992 times.
✗ Branch 2 not taken.
1992 const shash::Any root_catalog_hash = this->GetRepositoryRootCatalogHash();
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1992 times.
1992 if (root_catalog_hash.IsNull()) {
88 ✗ return false;
89 }
90
1/2
✓ Branch 1 taken 1992 times.
✗ Branch 2 not taken.
1992 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 2592 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 5184 if (this->no_repeat_history_
104
4/6
✓ Branch 0 taken 1712 times.
✓ Branch 1 taken 880 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1712 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2592 times.
2592 && catalogs_done_.Contains(root_catalog_hash)) {
105 ✗ return true;
106 }
107 2592 effective_traversal_type_ = type;
108
3/6
✓ Branch 2 taken 2592 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2592 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2592 times.
✗ Branch 9 not taken.
2592 CatalogJob *root_job = new CatalogJob("", root_catalog_hash, 0, 0);
109 2592 PushJob(root_job);
110 2592 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 2612 bool TraverseList(const HashList &root_catalog_list,
119 const TraversalType type = Base::kBreadthFirst) {
120 // Push in reverse order for CatalogTraversal-like behavior
121 2612 HashList::const_reverse_iterator i = root_catalog_list.rbegin();
122 2612 const HashList::const_reverse_iterator iend = root_catalog_list.rend();
123 2612 bool has_pushed = false;
124 {
125 2612 MutexLockGuard const m(&catalogs_lock_);
126
3/4
✓ Branch 2 taken 7852 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5240 times.
✓ Branch 5 taken 2612 times.
7852 for (; i != iend; ++i) {
127
7/8
✓ Branch 0 taken 4880 times.
✓ Branch 1 taken 360 times.
✓ Branch 4 taken 4880 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2420 times.
✓ Branch 7 taken 2460 times.
✓ Branch 8 taken 2420 times.
✓ Branch 9 taken 2820 times.
5240 if (this->no_repeat_history_ && catalogs_done_.Contains(*i)) {
128 2420 continue;
129 }
130
131
3/6
✓ Branch 2 taken 2820 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 2820 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2820 times.
✗ Branch 10 not taken.
2820 CatalogJob *root_job = new CatalogJob("", *i, 0, 0);
132
1/2
✓ Branch 1 taken 2820 times.
✗ Branch 2 not taken.
2820 PushJobUnlocked(root_job);
133 2820 has_pushed = true;
134 }
135 2612 }
136 // noop: no catalogs to traverse
137
2/2
✓ Branch 0 taken 1056 times.
✓ Branch 1 taken 1556 times.
2612 if (!has_pushed) {
138 1056 return true;
139 }
140 1556 effective_traversal_type_ = type;
141 1556 effective_history_depth_ = Parameters::kNoHistory;
142 1556 effective_timestamp_threshold_ = Parameters::kNoTimestampThreshold;
143
1/2
✓ Branch 1 taken 1556 times.
✗ Branch 2 not taken.
1556 bool const result = DoTraverse();
144 1556 effective_history_depth_ = this->default_history_depth_;
145 1556 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
146 1556 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 80 bool TraverseRevision(const shash::Any &root_catalog_hash,
158 const TraversalType type = Base::kBreadthFirst) {
159 80 effective_history_depth_ = Parameters::kNoHistory;
160 80 effective_timestamp_threshold_ = Parameters::kNoTimestampThreshold;
161 80 bool const result = Traverse(root_catalog_hash, type);
162 80 effective_history_depth_ = this->default_history_depth_;
163 80 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
164 80 return result;
165 }
166
167 protected:
168 67735684 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 67735684 *(reinterpret_cast<const uint32_t *>(key.digest) + 1));
172 }
173
174 4148 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 4148 threads_process_ = reinterpret_cast<pthread_t *>(
178 4148 smalloc(sizeof(pthread_t) * num_threads_));
179
2/2
✓ Branch 0 taken 4708 times.
✓ Branch 1 taken 4148 times.
8856 for (unsigned int i = 0; i < num_threads_; ++i) {
180 4708 int const retval = pthread_create(&threads_process_[i], NULL,
181 MainProcessQueue, this);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4708 times.
4708 if (retval != 0)
183 ✗ PANIC(kLogStderr, "failed to create thread");
184 }
185
186
2/2
✓ Branch 0 taken 4708 times.
✓ Branch 1 taken 4148 times.
8856 for (unsigned int i = 0; i < num_threads_; ++i) {
187 4708 int const retval = pthread_join(threads_process_[i], NULL);
188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4708 times.
4708 assert(retval == 0);
189 }
190 4148 free(threads_process_);
191
192
2/2
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 4108 times.
8296 if (num_errors_.load())
193 40 return false;
194
195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4108 times.
4108 assert(catalogs_processing_.size() == 0);
196
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4108 times.
4108 assert(pre_job_queue_.IsEmpty());
197
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4108 times.
4108 assert(post_job_queue_.IsEmpty());
198 4108 return true;
199 }
200
201 4708 static void *MainProcessQueue(void *data) {
202 4708 CatalogTraversalParallel<ObjectFetcherT> *traversal = reinterpret_cast<
203 CatalogTraversalParallel<ObjectFetcherT> *>(data);
204 CatalogJob *current_job;
205 while (true) {
206 16100792 current_job = traversal->post_job_queue_.TryPopFront();
207
2/2
✓ Branch 0 taken 1359388 times.
✓ Branch 1 taken 14744524 times.
16103912 if (current_job != NULL) {
208 1359388 traversal->ProcessJobPost(current_job);
209 } else {
210 14744524 current_job = traversal->pre_job_queue_.PopFront();
211 // NULL means the master thread tells us to finish
212
2/2
✓ Branch 1 taken 4668 times.
✓ Branch 2 taken 14739896 times.
14744604 if (current_job->hash.IsNull()) {
213
1/2
✓ Branch 0 taken 4668 times.
✗ Branch 1 not taken.
4668 delete current_job;
214 4668 break;
215 }
216 14739896 traversal->ProcessJobPre(current_job);
217 }
218 }
219 4668 return NULL;
220 }
221
222 4148 void NotifyFinished() {
223
1/2
✓ Branch 1 taken 4148 times.
✗ Branch 2 not taken.
4148 shash::Any null_hash;
224 4148 null_hash.SetNull();
225
2/2
✓ Branch 0 taken 4708 times.
✓ Branch 1 taken 4148 times.
8856 for (unsigned i = 0; i < num_threads_; ++i) {
226
3/6
✓ Branch 2 taken 4708 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4708 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4708 times.
✗ Branch 9 not taken.
4708 CatalogJob *job = new CatalogJob("", null_hash, 0, 0);
227
1/2
✓ Branch 1 taken 4708 times.
✗ Branch 2 not taken.
4708 pre_job_queue_.EnqueueFront(job);
228 }
229 4148 }
230
231 2592 void PushJob(CatalogJob *job) {
232 2592 MutexLockGuard const m(&catalogs_lock_);
233
1/2
✓ Branch 1 taken 2592 times.
✗ Branch 2 not taken.
2592 PushJobUnlocked(job);
234 2592 }
235
236 14740216 void PushJobUnlocked(CatalogJob *job) {
237 14740216 catalogs_processing_.Insert(job->hash, job);
238 14740216 pre_job_queue_.EnqueueFront(job);
239 14740216 }
240
241 14739856 void ProcessJobPre(CatalogJob *job) {
242
4/6
✓ Branch 0 taken 14739856 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 14738296 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✓ Branch 6 taken 14738256 times.
14739856 if (!this->PrepareCatalog(job)) {
243 40 num_errors_.fetch_add(1);
244
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 NotifyFinished();
245 13378148 return;
246 }
247
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 14738004 times.
14738256 if (job->ignore) {
248
1/2
✓ Branch 1 taken 252 times.
✗ Branch 2 not taken.
252 FinalizeJob(job);
249 252 return;
250 }
251
1/2
✓ Branch 1 taken 14699884 times.
✗ Branch 2 not taken.
14738004 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 14699884 MutexLockGuard const m(&catalogs_lock_);
258
2/2
✓ Branch 0 taken 7391540 times.
✓ Branch 1 taken 7348344 times.
14739884 if (effective_traversal_type_ == Base::kBreadthFirst) {
259
1/2
✓ Branch 1 taken 7391540 times.
✗ Branch 2 not taken.
7391540 num_children = PushPreviousRevision(job)
260
1/2
✓ Branch 1 taken 7391540 times.
✗ Branch 2 not taken.
7391540 + PushNestedCatalogs(job, catalog_list);
261 } else {
262
1/2
✓ Branch 1 taken 7348344 times.
✗ Branch 2 not taken.
7348344 num_children = PushNestedCatalogs(job, catalog_list)
263
1/2
✓ Branch 1 taken 7348344 times.
✗ Branch 2 not taken.
7348344 + PushPreviousRevision(job);
264 7348344 job->children_unprocessed.store(num_children);
265 }
266
3/6
✓ Branch 0 taken 14739884 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 14739884 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 14739884 times.
14739884 if (!this->CloseCatalog(false, job)) {
267 ✗ num_errors_.fetch_add(1);
268 ✗ NotifyFinished();
269 }
270 14739884 }
271
272 // breadth-first: can post-process immediately
273 // depth-first: no children -> can post-process immediately
274
4/4
✓ Branch 0 taken 7348304 times.
✓ Branch 1 taken 7391500 times.
✓ Branch 2 taken 5988916 times.
✓ Branch 3 taken 1359388 times.
14739804 if (effective_traversal_type_ == Base::kBreadthFirst || num_children == 0) {
275
1/2
✓ Branch 1 taken 13377496 times.
✗ Branch 2 not taken.
13380416 ProcessJobPost(job);
276 13377496 return;
277 }
278
2/2
✓ Branch 1 taken 1359388 times.
✓ Branch 2 taken 13377856 times.
14736884 }
279
280 14739884 unsigned int PushNestedCatalogs(CatalogJob *job,
281 const NestedCatalogList &catalog_list) {
282 14739884 typename NestedCatalogList::const_iterator i = catalog_list.begin();
283 14739884 typename NestedCatalogList::const_iterator const iend = catalog_list.end();
284 14739884 unsigned int num_children = 0;
285
2/2
✓ Branch 2 taken 14733744 times.
✓ Branch 3 taken 14739884 times.
29473628 for (; i != iend; ++i) {
286
7/8
✓ Branch 0 taken 30064 times.
✓ Branch 1 taken 14703680 times.
✓ Branch 4 taken 30064 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3036 times.
✓ Branch 7 taken 27028 times.
✓ Branch 8 taken 3036 times.
✓ Branch 9 taken 14730708 times.
14733744 if (this->no_repeat_history_ && catalogs_done_.Contains(i->hash)) {
287 3036 continue;
288 }
289
290 CatalogJob *child;
291 29461416 if (!this->no_repeat_history_
292
7/8
✓ Branch 0 taken 27028 times.
✓ Branch 1 taken 14703680 times.
✓ Branch 4 taken 27028 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 26708 times.
✓ Branch 7 taken 320 times.
✓ Branch 8 taken 14730388 times.
✓ Branch 9 taken 320 times.
14730708 || !catalogs_processing_.Lookup(i->hash, &child)) {
293
2/2
✓ Branch 0 taken 14665480 times.
✓ Branch 1 taken 64908 times.
14730388 CatalogTN *parent = (this->no_close_) ? job->catalog : NULL;
294
1/2
✓ Branch 2 taken 14730388 times.
✗ Branch 3 not taken.
29460776 child = new CatalogJob(i->mountpoint.ToString(),
295
1/2
✓ Branch 2 taken 14730388 times.
✗ Branch 3 not taken.
14730388 i->hash,
296 14730388 job->tree_level + 1,
297
1/2
✓ Branch 1 taken 14730388 times.
✗ Branch 2 not taken.
14730388 job->history_depth,
298 parent);
299
1/2
✓ Branch 1 taken 14730388 times.
✗ Branch 2 not taken.
14730388 PushJobUnlocked(child);
300 }
301
302
2/2
✓ Branch 0 taken 7346568 times.
✓ Branch 1 taken 7384140 times.
14730708 if (effective_traversal_type_ == Base::kDepthFirst) {
303
1/2
✓ Branch 1 taken 7346568 times.
✗ Branch 2 not taken.
7346568 child->RegisterListener(&CatalogTraversalParallel::OnChildFinished,
304 this, job);
305 }
306 14730708 ++num_children;
307 }
308 14739884 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 14739884 unsigned int PushPreviousRevision(CatalogJob *job) {
316 // only root catalogs are used for entering a previous revision (graph)
317
2/2
✓ Branch 1 taken 14730264 times.
✓ Branch 2 taken 9620 times.
14739884 if (!job->catalog->IsRoot()) {
318 14730264 return 0;
319 }
320
321
1/2
✓ Branch 1 taken 9620 times.
✗ Branch 2 not taken.
9620 const shash::Any previous_revision = job->catalog->GetPreviousRevision();
322
2/2
✓ Branch 1 taken 1116 times.
✓ Branch 2 taken 8504 times.
9620 if (previous_revision.IsNull()) {
323 1116 return 0;
324 }
325
326 // check if the next deeper history level is actually requested
327
3/4
✓ Branch 1 taken 8504 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4088 times.
✓ Branch 4 taken 4416 times.
8504 if (this->IsBelowPruningThresholds(*job, effective_history_depth_,
328 effective_timestamp_threshold_)) {
329 4088 return 0;
330 }
331
332 8832 if (this->no_repeat_history_
333
5/8
✓ Branch 0 taken 3296 times.
✓ Branch 1 taken 1120 times.
✓ Branch 3 taken 3296 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 3296 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4416 times.
4416 && catalogs_done_.Contains(previous_revision)) {
334 ✗ return 0;
335 }
336
337 CatalogJob *prev_job;
338 8832 if (!this->no_repeat_history_
339
5/8
✓ Branch 0 taken 3296 times.
✓ Branch 1 taken 1120 times.
✓ Branch 3 taken 3296 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3296 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4416 times.
✗ Branch 8 not taken.
4416 || !catalogs_processing_.Lookup(previous_revision, &prev_job)) {
340
2/4
✓ Branch 2 taken 4416 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4416 times.
✗ Branch 6 not taken.
8832 prev_job = new CatalogJob("", previous_revision, 0,
341
1/2
✓ Branch 1 taken 4416 times.
✗ Branch 2 not taken.
4416 job->history_depth + 1);
342
1/2
✓ Branch 1 taken 4416 times.
✗ Branch 2 not taken.
4416 PushJobUnlocked(prev_job);
343 }
344
345
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 3816 times.
4416 if (effective_traversal_type_ == Base::kDepthFirst) {
346
1/2
✓ Branch 1 taken 600 times.
✗ Branch 2 not taken.
600 prev_job->RegisterListener(&CatalogTraversalParallel::OnChildFinished,
347 this, job);
348 }
349 4416 return 1;
350 }
351
352 14738604 void ProcessJobPost(CatalogJob *job) {
353 // Save time by keeping catalog open when suitable
354
2/2
✓ Branch 0 taken 14738564 times.
✓ Branch 1 taken 40 times.
14738604 if (job->catalog == NULL) {
355
2/4
✓ Branch 0 taken 14738564 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 14698644 times.
14738564 if (!this->ReopenCatalog(job)) {
356 ✗ num_errors_.fetch_add(1);
357 ✗ NotifyFinished();
358 ✗ return;
359 }
360 }
361
1/2
✓ Branch 0 taken 14698724 times.
✗ Branch 1 not taken.
14698684 if (serialize_callbacks_) {
362 14698724 MutexLockGuard const m(&catalog_callback_lock_);
363
2/4
✓ Branch 1 taken 14739884 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14739884 times.
✗ Branch 5 not taken.
14739884 this->NotifyListeners(job->GetCallbackData());
364 14739884 } else {
365 ✗ this->NotifyListeners(job->GetCallbackData());
366 }
367
2/2
✓ Branch 0 taken 74204 times.
✓ Branch 1 taken 14665640 times.
14739844 if (!this->no_close_) {
368
2/4
✓ Branch 0 taken 74204 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 74204 times.
74204 if (!this->CloseCatalog(true, job)) {
369 ✗ num_errors_.fetch_add(1);
370 ✗ NotifyFinished();
371 ✗ return;
372 }
373 }
374 14739844 FinalizeJob(job);
375 }
376
377 14740016 void FinalizeJob(CatalogJob *job) {
378 {
379 14740016 MutexLockGuard const m(&catalogs_lock_);
380
1/2
✓ Branch 1 taken 14740136 times.
✗ Branch 2 not taken.
14740136 catalogs_processing_.Erase(job->hash);
381
1/2
✓ Branch 1 taken 14740136 times.
✗ Branch 2 not taken.
14740136 catalogs_done_.Insert(job->hash, true);
382 // No more catalogs to process -> finish
383
1/2
✓ Branch 2 taken 4108 times.
✗ Branch 3 not taken.
14744244 if (catalogs_processing_.size() == 0 && pre_job_queue_.IsEmpty()
384
5/6
✓ Branch 0 taken 4108 times.
✓ Branch 1 taken 14736028 times.
✓ Branch 3 taken 4108 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4108 times.
✓ Branch 6 taken 14736028 times.
14744244 && post_job_queue_.IsEmpty()) {
385
1/2
✓ Branch 1 taken 4108 times.
✗ Branch 2 not taken.
4108 NotifyFinished();
386 }
387 14740136 }
388
2/2
✓ Branch 0 taken 7348392 times.
✓ Branch 1 taken 7391384 times.
14739776 if (effective_traversal_type_ == Base::kDepthFirst) {
389 7348392 job->WakeParents();
390 }
391
1/2
✓ Branch 0 taken 14739016 times.
✗ Branch 1 not taken.
14738976 delete job;
392 14737936 }
393
394 7346488 void OnChildFinished(const int &a, CatalogJob *job) {
395 // atomic_xadd32 returns value before subtraction -> needs to equal 1
396
2/2
✓ Branch 0 taken 1359388 times.
✓ Branch 1 taken 5987100 times.
14692976 if (job->children_unprocessed.fetch_add(-1) == 1) {
397 1359388 post_job_queue_.EnqueueFront(job);
398 }
399 7346488 }
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