CernVM-FS  2.12.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 <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 
23  const std::string* json_message;
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 
44  public:
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 
62 
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 
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 
94  pthread_mutex_t current_pack_mtx_;
95 
96  uint64_t bytes_committed_;
98 
100 };
101 
103  public:
104  SessionContext();
105 
106  protected:
107  struct UploadJob {
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 
121 
122  virtual bool DoUpload(const UploadJob* job);
123 
124  private:
125  static void* UploadLoop(void* data);
126 
128 
129  pthread_t worker_;
130 
132 };
133 
134 } // namespace upload
135 
136 #endif // CVMFS_SESSION_CONTEXT_H_
static void * UploadLoop(void *data)
UniquePtr< Tube< UploadJob > > upload_jobs_
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)
const std::string * json_message
ObjectPackProducer * pack_serializer
virtual bool FinalizeDerived()=0
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)
Definition: tube.h:39
Tube< Future< bool > > upload_results_
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()
static void size_t size
Definition: smalloc.h:54
size_t RecvCB(void *buffer, size_t size, size_t nmemb, void *userp)