GCC Code Coverage Report


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