CernVM-FS  2.13.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, const RepositoryTag &tag);
57 
58  void WaitForUpload() { }
59 
61 
63  const shash::Any &id, const ObjectPack::BucketHandle handle,
64  const std::string &name = "",
65  const bool force_dispatch = false);
66 
67  protected:
68  virtual bool InitializeDerived(uint64_t max_queue_size) = 0;
69 
70  virtual bool FinalizeDerived() = 0;
71 
72  virtual bool Commit(const std::string &old_root_hash,
73  const std::string &new_root_hash,
74  const RepositoryTag &tag) = 0;
75 
76  virtual Future<bool> *DispatchObjectPack(ObjectPack *pack) = 0;
77 
79 
80  std::string api_url_;
81  std::string session_token_;
82  std::string key_id_;
83  std::string secret_;
84 
85  private:
86  void Dispatch();
87 
88  uint64_t max_pack_size_;
89 
90  std::vector<ObjectPack::BucketHandle> active_handles_;
91 
93  pthread_mutex_t current_pack_mtx_;
94 
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)
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:59
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)