GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/catalog_traversal_parallel.h
Date: 2026-11-08 02:41:18
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 705 explicit CatalogTraversalParallel(const Parameters &params)
43 : CatalogTraversalBase<ObjectFetcherT>(params)
44 705 , num_threads_(params.num_threads)
45
4/8
✓ Branch 2 taken 705 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 705 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 705 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 705 times.
✗ Branch 12 not taken.
705 , serialize_callbacks_(params.serialize_callbacks) {
46 705 num_errors_.store(0);
47
1/2
✓ Branch 1 taken 705 times.
✗ Branch 2 not taken.
705 shash::Any null_hash;
48 705 null_hash.SetNull();
49
1/2
✓ Branch 1 taken 705 times.
✗ Branch 2 not taken.
705 catalogs_processing_.Init(1024, null_hash, hasher);
50
1/2
✓ Branch 1 taken 705 times.
✗ Branch 2 not taken.
705 catalogs_done_.Init(1024, null_hash, hasher);
51 705 pthread_mutex_init(&catalog_callback_lock_, NULL);
52 705 pthread_mutex_init(&catalogs_lock_, NULL);
53 705 effective_history_depth_ = this->default_history_depth_;
54 705 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
55 705 }
56
57 protected:
58 struct CatalogJob : public CatalogTraversal<ObjectFetcherT>::CatalogJob,
59 public Observable<int> {
60 5524401 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 5524401 history_depth, parent) {
67 5524401 children_unprocessed.store(0);
68 5524401 }
69
70
1/2
✓ Branch 1 taken 2754453 times.
✗ Branch 2 not taken.
2754813 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 453 bool Traverse(const TraversalType type = Base::kBreadthFirst) {
86
1/2
✓ Branch 1 taken 453 times.
✗ Branch 2 not taken.
453 const shash::Any root_catalog_hash = this->GetRepositoryRootCatalogHash();
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 453 times.
453 if (root_catalog_hash.IsNull()) {
88 ✗ return false;
89 }
90
1/2
✓ Branch 1 taken 453 times.
✗ Branch 2 not taken.
453 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 678 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 1356 if (this->no_repeat_history_
104
4/6
✓ Branch 0 taken 348 times.
✓ Branch 1 taken 330 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 348 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 678 times.
678 && catalogs_done_.Contains(root_catalog_hash)) {
105 ✗ return true;
106 }
107 678 effective_traversal_type_ = type;
108
3/6
✓ Branch 2 taken 678 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 678 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 678 times.
✗ Branch 9 not taken.
678 CatalogJob *root_job = new CatalogJob("", root_catalog_hash, 0, 0);
109 678 PushJob(root_job);
110 678 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 423 bool TraverseList(const HashList &root_catalog_list,
119 const TraversalType type = Base::kBreadthFirst) {
120 // Push in reverse order for CatalogTraversal-like behavior
121 423 HashList::const_reverse_iterator i = root_catalog_list.rbegin();
122 423 const HashList::const_reverse_iterator iend = root_catalog_list.rend();
123 423 bool has_pushed = false;
124 {
125 423 MutexLockGuard const m(&catalogs_lock_);
126
3/4
✓ Branch 2 taken 1338 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 915 times.
✓ Branch 5 taken 423 times.
1338 for (; i != iend; ++i) {
127
7/8
✓ Branch 0 taken 780 times.
✓ Branch 1 taken 135 times.
✓ Branch 4 taken 780 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 330 times.
✓ Branch 7 taken 450 times.
✓ Branch 8 taken 330 times.
✓ Branch 9 taken 585 times.
915 if (this->no_repeat_history_ && catalogs_done_.Contains(*i)) {
128 330 continue;
129 }
130
131
3/6
✓ Branch 2 taken 585 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 585 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 585 times.
✗ Branch 10 not taken.
585 CatalogJob *root_job = new CatalogJob("", *i, 0, 0);
132
1/2
✓ Branch 1 taken 585 times.
✗ Branch 2 not taken.
585 PushJobUnlocked(root_job);
133 585 has_pushed = true;
134 }
135 423 }
136 // noop: no catalogs to traverse
137
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 279 times.
423 if (!has_pushed) {
138 144 return true;
139 }
140 279 effective_traversal_type_ = type;
141 279 effective_history_depth_ = Parameters::kNoHistory;
142 279 effective_timestamp_threshold_ = Parameters::kNoTimestampThreshold;
143
1/2
✓ Branch 1 taken 279 times.
✗ Branch 2 not taken.
279 bool const result = DoTraverse();
144 279 effective_history_depth_ = this->default_history_depth_;
145 279 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
146 279 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 30 bool TraverseRevision(const shash::Any &root_catalog_hash,
158 const TraversalType type = Base::kBreadthFirst) {
159 30 effective_history_depth_ = Parameters::kNoHistory;
160 30 effective_timestamp_threshold_ = Parameters::kNoTimestampThreshold;
161 30 bool const result = Traverse(root_catalog_hash, type);
162 30 effective_history_depth_ = this->default_history_depth_;
163 30 effective_timestamp_threshold_ = this->default_timestamp_threshold_;
164 30 return result;
165 }
166
167 protected:
168 25225731 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 25225731 *(reinterpret_cast<const uint32_t *>(key.digest) + 1));
172 }
173
174 957 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 957 threads_process_ = reinterpret_cast<pthread_t *>(
178 957 smalloc(sizeof(pthread_t) * num_threads_));
179
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 957 times.
2124 for (unsigned int i = 0; i < num_threads_; ++i) {
180 1167 int const retval = pthread_create(&threads_process_[i], NULL,
181 MainProcessQueue, this);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if (retval != 0)
183 ✗ PANIC(kLogStderr, "failed to create thread");
184 }
185
186
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 957 times.
2124 for (unsigned int i = 0; i < num_threads_; ++i) {
187 1167 int const retval = pthread_join(threads_process_[i], NULL);
188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 assert(retval == 0);
189 }
190 957 free(threads_process_);
191
192
2/2
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 942 times.
1914 if (num_errors_.load())
193 15 return false;
194
195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 942 times.
942 assert(catalogs_processing_.size() == 0);
196
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 942 times.
942 assert(pre_job_queue_.IsEmpty());
197
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 942 times.
942 assert(post_job_queue_.IsEmpty());
198 942 return true;
199 }
200
201 1167 static void *MainProcessQueue(void *data) {
202 1167 CatalogTraversalParallel<ObjectFetcherT> *traversal = reinterpret_cast<
203 CatalogTraversalParallel<ObjectFetcherT> *>(data);
204 CatalogJob *current_job;
205 while (true) {
206 6032418 current_job = traversal->post_job_queue_.TryPopFront();
207
2/2
✓ Branch 0 taken 509472 times.
✓ Branch 1 taken 5524101 times.
6033573 if (current_job != NULL) {
208 509472 traversal->ProcessJobPost(current_job);
209 } else {
210 5524101 current_job = traversal->pre_job_queue_.PopFront();
211 // NULL means the master thread tells us to finish
212
2/2
✓ Branch 1 taken 1167 times.
✓ Branch 2 taken 5523159 times.
5524386 if (current_job->hash.IsNull()) {
213
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 delete current_job;
214 1167 break;
215 }
216 5523159 traversal->ProcessJobPre(current_job);
217 }
218 }
219 1167 return NULL;
220 }
221
222 957 void NotifyFinished() {
223
1/2
✓ Branch 1 taken 957 times.
✗ Branch 2 not taken.
957 shash::Any null_hash;
224 957 null_hash.SetNull();
225
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 957 times.
2124 for (unsigned i = 0; i < num_threads_; ++i) {
226
3/6
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1167 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1167 times.
✗ Branch 9 not taken.
1167 CatalogJob *job = new CatalogJob("", null_hash, 0, 0);
227
1/2
✓ Branch 1 taken 1167 times.
✗ Branch 2 not taken.
1167 pre_job_queue_.EnqueueFront(job);
228 }
229 957 }
230
231 678 void PushJob(CatalogJob *job) {
232 678 MutexLockGuard const m(&catalogs_lock_);
233
1/2
✓ Branch 1 taken 678 times.
✗ Branch 2 not taken.
678 PushJobUnlocked(job);
234 678 }
235
236 5523234 void PushJobUnlocked(CatalogJob *job) {
237 5523234 catalogs_processing_.Insert(job->hash, job);
238 5523234 pre_job_queue_.EnqueueFront(job);
239 5523234 }
240
241 5523114 void ProcessJobPre(CatalogJob *job) {
242
4/6
✓ Branch 0 taken 5523114 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 5522874 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✓ Branch 6 taken 5522859 times.
5523114 if (!this->PrepareCatalog(job)) {
243 15 num_errors_.fetch_add(1);
244
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
15 NotifyFinished();
245 5012637 return;
246 }
247
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 5522796 times.
5522859 if (job->ignore) {
248
1/2
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
63 FinalizeJob(job);
249 63 return;
250 }
251
1/2
✓ Branch 1 taken 5511771 times.
✗ Branch 2 not taken.
5522796 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 5511771 MutexLockGuard const m(&catalogs_lock_);
258
2/2
✓ Branch 0 taken 2768205 times.
✓ Branch 1 taken 2754936 times.
5523141 if (effective_traversal_type_ == Base::kBreadthFirst) {
259
1/2
✓ Branch 1 taken 2768205 times.
✗ Branch 2 not taken.
2768205 num_children = PushPreviousRevision(job)
260
1/2
✓ Branch 1 taken 2768205 times.
✗ Branch 2 not taken.
2768205 + PushNestedCatalogs(job, catalog_list);
261 } else {
262
1/2
✓ Branch 1 taken 2754936 times.
✗ Branch 2 not taken.
2754936 num_children = PushNestedCatalogs(job, catalog_list)
263
1/2
✓ Branch 1 taken 2754936 times.
✗ Branch 2 not taken.
2754936 + PushPreviousRevision(job);
264 2754936 job->children_unprocessed.store(num_children);
265 }
266
3/6
✓ Branch 0 taken 5523141 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 5523141 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5523141 times.
5523141 if (!this->CloseCatalog(false, job)) {
267 ✗ num_errors_.fetch_add(1);
268 ✗ NotifyFinished();
269 }
270 5523141 }
271
272 // breadth-first: can post-process immediately
273 // depth-first: no children -> can post-process immediately
274
4/4
✓ Branch 0 taken 2754921 times.
✓ Branch 1 taken 2768145 times.
✓ Branch 2 taken 2245434 times.
✓ Branch 3 taken 509487 times.
5523066 if (effective_traversal_type_ == Base::kBreadthFirst || num_children == 0) {
275
1/2
✓ Branch 1 taken 5012169 times.
✗ Branch 2 not taken.
5013579 ProcessJobPost(job);
276 5012169 return;
277 }
278
2/2
✓ Branch 1 taken 509487 times.
✓ Branch 2 taken 5012559 times.
5521656 }
279
280 5523141 unsigned int PushNestedCatalogs(CatalogJob *job,
281 const NestedCatalogList &catalog_list) {
282 5523141 typename NestedCatalogList::const_iterator i = catalog_list.begin();
283 5523141 typename NestedCatalogList::const_iterator const iend = catalog_list.end();
284 5523141 unsigned int num_children = 0;
285
2/2
✓ Branch 2 taken 5521941 times.
✓ Branch 3 taken 5523141 times.
11045082 for (; i != iend; ++i) {
286
7/8
✓ Branch 0 taken 8061 times.
✓ Branch 1 taken 5513880 times.
✓ Branch 4 taken 8061 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 939 times.
✓ Branch 7 taken 7122 times.
✓ Branch 8 taken 939 times.
✓ Branch 9 taken 5521002 times.
5521941 if (this->no_repeat_history_ && catalogs_done_.Contains(i->hash)) {
287 939 continue;
288 }
289
290 CatalogJob *child;
291 11042004 if (!this->no_repeat_history_
292
7/8
✓ Branch 0 taken 7122 times.
✓ Branch 1 taken 5513880 times.
✓ Branch 4 taken 7122 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7002 times.
✓ Branch 7 taken 120 times.
✓ Branch 8 taken 5520882 times.
✓ Branch 9 taken 120 times.
5521002 || !catalogs_processing_.Lookup(i->hash, &child)) {
293
2/2
✓ Branch 0 taken 5499555 times.
✓ Branch 1 taken 21327 times.
5520882 CatalogTN *parent = (this->no_close_) ? job->catalog : NULL;
294
1/2
✓ Branch 2 taken 5520882 times.
✗ Branch 3 not taken.
11041764 child = new CatalogJob(i->mountpoint.ToString(),
295
1/2
✓ Branch 2 taken 5520882 times.
✗ Branch 3 not taken.
5520882 i->hash,
296 5520882 job->tree_level + 1,
297
1/2
✓ Branch 1 taken 5520882 times.
✗ Branch 2 not taken.
5520882 job->history_depth,
298 parent);
299
1/2
✓ Branch 1 taken 5520882 times.
✗ Branch 2 not taken.
5520882 PushJobUnlocked(child);
300 }
301
302
2/2
✓ Branch 0 taken 2754522 times.
✓ Branch 1 taken 2766480 times.
5521002 if (effective_traversal_type_ == Base::kDepthFirst) {
303
1/2
✓ Branch 1 taken 2754522 times.
✗ Branch 2 not taken.
2754522 child->RegisterListener(&CatalogTraversalParallel::OnChildFinished,
304 this, job);
305 }
306 5521002 ++num_children;
307 }
308 5523141 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 5523141 unsigned int PushPreviousRevision(CatalogJob *job) {
316 // only root catalogs are used for entering a previous revision (graph)
317
2/2
✓ Branch 1 taken 5520846 times.
✓ Branch 2 taken 2295 times.
5523141 if (!job->catalog->IsRoot()) {
318 5520846 return 0;
319 }
320
321
1/2
✓ Branch 1 taken 2295 times.
✗ Branch 2 not taken.
2295 const shash::Any previous_revision = job->catalog->GetPreviousRevision();
322
2/2
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 2076 times.
2295 if (previous_revision.IsNull()) {
323 219 return 0;
324 }
325
326 // check if the next deeper history level is actually requested
327
3/4
✓ Branch 1 taken 2076 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 987 times.
✓ Branch 4 taken 1089 times.
2076 if (this->IsBelowPruningThresholds(*job, effective_history_depth_,
328 effective_timestamp_threshold_)) {
329 987 return 0;
330 }
331
332 2178 if (this->no_repeat_history_
333
5/8
✓ Branch 0 taken 669 times.
✓ Branch 1 taken 420 times.
✓ Branch 3 taken 669 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 669 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1089 times.
1089 && catalogs_done_.Contains(previous_revision)) {
334 ✗ return 0;
335 }
336
337 CatalogJob *prev_job;
338 2178 if (!this->no_repeat_history_
339
5/8
✓ Branch 0 taken 669 times.
✓ Branch 1 taken 420 times.
✓ Branch 3 taken 669 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 669 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1089 times.
✗ Branch 8 not taken.
1089 || !catalogs_processing_.Lookup(previous_revision, &prev_job)) {
340
2/4
✓ Branch 2 taken 1089 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1089 times.
✗ Branch 6 not taken.
2178 prev_job = new CatalogJob("", previous_revision, 0,
341
1/2
✓ Branch 1 taken 1089 times.
✗ Branch 2 not taken.
1089 job->history_depth + 1);
342
1/2
✓ Branch 1 taken 1089 times.
✗ Branch 2 not taken.
1089 PushJobUnlocked(prev_job);
343 }
344
345
2/2
✓ Branch 0 taken 225 times.
✓ Branch 1 taken 864 times.
1089 if (effective_traversal_type_ == Base::kDepthFirst) {
346
1/2
✓ Branch 1 taken 225 times.
✗ Branch 2 not taken.
225 prev_job->RegisterListener(&CatalogTraversalParallel::OnChildFinished,
347 this, job);
348 }
349 1089 return 1;
350 }
351
352 5522391 void ProcessJobPost(CatalogJob *job) {
353 // Save time by keeping catalog open when suitable
354
2/2
✓ Branch 0 taken 5522376 times.
✓ Branch 1 taken 15 times.
5522391 if (job->catalog == NULL) {
355
2/4
✓ Branch 0 taken 5522376 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 5508921 times.
5522376 if (!this->ReopenCatalog(job)) {
356 ✗ num_errors_.fetch_add(1);
357 ✗ NotifyFinished();
358 ✗ return;
359 }
360 }
361
1/2
✓ Branch 0 taken 5509071 times.
✗ Branch 1 not taken.
5508936 if (serialize_callbacks_) {
362 5509071 MutexLockGuard const m(&catalog_callback_lock_);
363
2/4
✓ Branch 1 taken 5523141 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5523141 times.
✗ Branch 5 not taken.
5523141 this->NotifyListeners(job->GetCallbackData());
364 5523141 } else {
365 ✗ this->NotifyListeners(job->GetCallbackData());
366 }
367
2/2
✓ Branch 0 taken 23511 times.
✓ Branch 1 taken 5499600 times.
5523111 if (!this->no_close_) {
368
2/4
✓ Branch 0 taken 23511 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 23511 times.
23511 if (!this->CloseCatalog(true, job)) {
369 ✗ num_errors_.fetch_add(1);
370 ✗ NotifyFinished();
371 ✗ return;
372 }
373 }
374 5523111 FinalizeJob(job);
375 }
376
377 5523099 void FinalizeJob(CatalogJob *job) {
378 {
379 5523099 MutexLockGuard const m(&catalogs_lock_);
380
1/2
✓ Branch 1 taken 5523204 times.
✗ Branch 2 not taken.
5523204 catalogs_processing_.Erase(job->hash);
381
1/2
✓ Branch 1 taken 5523204 times.
✗ Branch 2 not taken.
5523204 catalogs_done_.Insert(job->hash, true);
382 // No more catalogs to process -> finish
383
1/2
✓ Branch 2 taken 942 times.
✗ Branch 3 not taken.
5524146 if (catalogs_processing_.size() == 0 && pre_job_queue_.IsEmpty()
384
5/6
✓ Branch 0 taken 942 times.
✓ Branch 1 taken 5522262 times.
✓ Branch 3 taken 942 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 942 times.
✓ Branch 6 taken 5522262 times.
5524146 && post_job_queue_.IsEmpty()) {
385
1/2
✓ Branch 1 taken 942 times.
✗ Branch 2 not taken.
942 NotifyFinished();
386 }
387 5523204 }
388
2/2
✓ Branch 0 taken 2754813 times.
✓ Branch 1 taken 2768106 times.
5522919 if (effective_traversal_type_ == Base::kDepthFirst) {
389 2754813 job->WakeParents();
390 }
391
1/2
✓ Branch 0 taken 5522544 times.
✗ Branch 1 not taken.
5522544 delete job;
392 5521884 }
393
394 2754417 void OnChildFinished(const int &a, CatalogJob *job) {
395 // atomic_xadd32 returns value before subtraction -> needs to equal 1
396
2/2
✓ Branch 0 taken 509487 times.
✓ Branch 1 taken 2244930 times.
5508834 if (job->children_unprocessed.fetch_add(-1) == 1) {
397 509487 post_job_queue_.EnqueueFront(job);
398 }
399 2754402 }
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