CernVM-FS  2.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
session_context.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SESSION_CONTEXT_H_
6 #define CVMFS_SESSION_CONTEXT_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "pack.h"
12 #include "repository_tag.h"
13 #include "util/concurrency.h"
14 #include "util/pointer.h"
15 
16 namespace upload {
17 
19  const std::string* json_message;
21  size_t index;
22 };
23 
24 size_t SendCB(void* ptr, size_t size, size_t nmemb, void* userp);
25 size_t RecvCB(void* buffer, size_t size, size_t nmemb, void* userp);
26 
40  public:
42 
43  virtual ~SessionContextBase();
44 
45 // By default, the maximum number of queued jobs is limited to 10,
46 // representing 10 * 200 MB = 2GB max memory used by the queue
47 bool Initialize(const std::string& api_url, const std::string& session_token,
48  const std::string& key_id, const std::string& secret,
49  uint64_t max_pack_size = ObjectPack::kDefaultLimit,
50  uint64_t max_queue_size = 10);
51  bool Finalize(bool commit, const std::string& old_root_hash,
52  const std::string& new_root_hash,
53  const RepositoryTag& tag);
54 
55  void WaitForUpload() {}
56 
58 
60  const shash::Any& id, const ObjectPack::BucketHandle handle,
61  const std::string& name = "",
62  const bool force_dispatch = false);
63 
64  protected:
65  virtual bool InitializeDerived(uint64_t max_queue_size) = 0;
66 
67  virtual bool FinalizeDerived() = 0;
68 
69  virtual bool Commit(const std::string& old_root_hash,
70  const std::string& new_root_hash,
71  const RepositoryTag& tag) = 0;
72 
73  virtual Future<bool>* DispatchObjectPack(ObjectPack* pack) = 0;
74 
75  int64_t NumJobsSubmitted() const;
76 
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 
92  pthread_mutex_t current_pack_mtx_;
93 
95  uint64_t bytes_committed_;
97 
99 };
100 
102  public:
103  SessionContext();
104 
105  protected:
106  struct UploadJob {
109  };
110 
111  virtual bool InitializeDerived(uint64_t max_queue_size);
112 
113  virtual bool FinalizeDerived();
114 
115  virtual bool Commit(const std::string& old_root_hash,
116  const std::string& new_root_hash,
117  const RepositoryTag& tag);
118 
120 
121  virtual bool DoUpload(const UploadJob* job);
122 
123  private:
124  static void* UploadLoop(void* data);
125 
127 
128  pthread_t worker_;
129 
131 };
132 
133 } // namespace upload
134 
135 #endif // CVMFS_SESSION_CONTEXT_H_
static void * UploadLoop(void *data)
int64_t atomic_int64
Definition: atomic.h:18
BucketContentType
Definition: pack.h:53
virtual Future< bool > * DispatchObjectPack(ObjectPack *pack)=0
pthread_mutex_t current_pack_mtx_
virtual bool InitializeDerived(uint64_t max_queue_size)
virtual bool Commit(const std::string &old_root_hash, const std::string &new_root_hash, const RepositoryTag &tag)=0
ObjectPack::BucketHandle NewBucket()
virtual Future< bool > * DispatchObjectPack(ObjectPack *pack)
virtual bool Commit(const std::string &old_root_hash, const std::string &new_root_hash, const RepositoryTag &tag)
static const uint64_t kDefaultLimit
Definition: pack.h:55
bool CommitBucket(const ObjectPack::BucketContentType type, const shash::Any &id, const ObjectPack::BucketHandle handle, const std::string &name="", const bool force_dispatch=false)
virtual bool DoUpload(const UploadJob *job)
UniquePtr< FifoChannel< UploadJob * > > upload_jobs_
const std::string * json_message
ObjectPackProducer * pack_serializer
virtual bool FinalizeDerived()=0
FifoChannel< Future< bool > * > upload_results_
std::vector< ObjectPack::BucketHandle > active_handles_
bool Finalize(bool commit, const std::string &old_root_hash, const std::string &new_root_hash, const RepositoryTag &tag)
virtual bool InitializeDerived(uint64_t max_queue_size)=0
static UploadJob terminator_
size_t SendCB(void *ptr, size_t size, size_t nmemb, void *userp)
bool Initialize(const std::string &api_url, const std::string &session_token, const std::string &key_id, const std::string &secret, uint64_t max_pack_size=ObjectPack::kDefaultLimit, uint64_t max_queue_size=10)
virtual bool FinalizeDerived()
int64_t NumJobsSubmitted() const
static void size_t size
Definition: smalloc.h:54
size_t RecvCB(void *buffer, size_t size, size_t nmemb, void *userp)