GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/session_context.h
Date: 2026-04-26 02:35:59
Exec Total Coverage
Lines: 0 1 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_SESSION_CONTEXT_H_
6 #define CVMFS_SESSION_CONTEXT_H_
7
8 #include <pthread.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "pack.h"
14 #include "repository_tag.h"
15 #include "util/future.h"
16 #include "util/pointer.h"
17 #include "util/tube.h"
18
19 namespace upload {
20
21 struct CurlSendPayload {
22 const std::string *json_message;
23 ObjectPackProducer *pack_serializer;
24 size_t index;
25 };
26
27 size_t SendCB(void *ptr, size_t size, size_t nmemb, void *userp);
28 size_t RecvCB(void *buffer, size_t size, size_t nmemb, void *userp);
29
30 /**
31 * This class implements a context for a single publish operation
32 *
33 * The context is created at the start of a publish operation and
34 * is supposed to live at least until the payload has been submitted
35 * to the repo services.
36 *
37 * It is the GatewayUploader concrete class which handles the creation and
38 * destruction of the SessionContext. A session should begin when the spooler
39 * and uploaders are initialized and should last until the call to
40 * Spooler::WaitForUpload().
41 */
42 class SessionContextBase {
43 public:
44 SessionContextBase();
45
46 virtual ~SessionContextBase();
47
48 // By default, the maximum number of queued jobs is limited to 10,
49 // representing 10 * 200 MB = 2GB max memory used by the queue
50 bool Initialize(const std::string &api_url, const std::string &session_token,
51 const std::string &key_id, const std::string &secret,
52 uint64_t max_pack_size = ObjectPack::kDefaultLimit,
53 uint64_t max_queue_size = 10);
54 bool Finalize(bool commit, const std::string &old_root_hash,
55 const std::string &new_root_hash, const RepositoryTag &tag);
56
57 void WaitForUpload() { }
58
59 ObjectPack::BucketHandle NewBucket();
60
61 bool CommitBucket(const ObjectPack::BucketContentType type,
62 const shash::Any &id, const ObjectPack::BucketHandle handle,
63 const std::string &name = "",
64 const bool force_dispatch = false);
65
66 protected:
67 virtual bool InitializeDerived(uint64_t max_queue_size) = 0;
68
69 virtual bool FinalizeDerived() = 0;
70
71 virtual bool Commit(const std::string &old_root_hash,
72 const std::string &new_root_hash,
73 const RepositoryTag &tag) = 0;
74
75 virtual Future<bool> *DispatchObjectPack(ObjectPack *pack) = 0;
76
77 Tube<Future<bool> > upload_results_;
78
79 std::string api_url_;
80 std::string session_token_;
81 std::string key_id_;
82 std::string secret_;
83
84 private:
85 void Dispatch();
86
87 uint64_t max_pack_size_;
88
89 std::vector<ObjectPack::BucketHandle> active_handles_;
90
91 ObjectPack *current_pack_;
92 pthread_mutex_t current_pack_mtx_;
93
94 uint64_t bytes_committed_;
95 uint64_t bytes_dispatched_;
96
97 bool initialized_;
98 };
99
100 class SessionContext : public SessionContextBase {
101 public:
102 SessionContext();
103
104 protected:
105 struct UploadJob {
106 ObjectPack *pack;
107 Future<bool> *result;
108 };
109
110 virtual bool InitializeDerived(uint64_t max_queue_size);
111
112 virtual bool FinalizeDerived();
113
114 virtual bool Commit(const std::string &old_root_hash,
115 const std::string &new_root_hash,
116 const RepositoryTag &tag);
117
118 virtual Future<bool> *DispatchObjectPack(ObjectPack *pack);
119
120 virtual bool DoUpload(const UploadJob *job);
121
122 private:
123 static void *UploadLoop(void *data);
124
125 UniquePtr<Tube<UploadJob> > upload_jobs_;
126
127 pthread_t worker_;
128
129 static UploadJob terminator_;
130 };
131
132 } // namespace upload
133
134 #endif // CVMFS_SESSION_CONTEXT_H_
135