| 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, const RepositoryTag &tag); |
| 57 |
|
|
|
| 58 |
|
✗ |
void WaitForUpload() { } |
| 59 |
|
|
|
| 60 |
|
|
ObjectPack::BucketHandle NewBucket(); |
| 61 |
|
|
|
| 62 |
|
|
bool CommitBucket(const ObjectPack::BucketContentType type, |
| 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 |
|
|
|
| 78 |
|
|
Tube<Future<bool> > upload_results_; |
| 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 |
|
|
|
| 92 |
|
|
ObjectPack *current_pack_; |
| 93 |
|
|
pthread_mutex_t current_pack_mtx_; |
| 94 |
|
|
|
| 95 |
|
|
uint64_t bytes_committed_; |
| 96 |
|
|
uint64_t bytes_dispatched_; |
| 97 |
|
|
|
| 98 |
|
|
bool initialized_; |
| 99 |
|
|
}; |
| 100 |
|
|
|
| 101 |
|
|
class SessionContext : public SessionContextBase { |
| 102 |
|
|
public: |
| 103 |
|
|
SessionContext(); |
| 104 |
|
|
|
| 105 |
|
|
protected: |
| 106 |
|
|
struct UploadJob { |
| 107 |
|
|
ObjectPack *pack; |
| 108 |
|
|
Future<bool> *result; |
| 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 |
|
|
|
| 119 |
|
|
virtual Future<bool> *DispatchObjectPack(ObjectPack *pack); |
| 120 |
|
|
|
| 121 |
|
|
virtual bool DoUpload(const UploadJob *job); |
| 122 |
|
|
|
| 123 |
|
|
private: |
| 124 |
|
|
static void *UploadLoop(void *data); |
| 125 |
|
|
|
| 126 |
|
|
UniquePtr<Tube<UploadJob> > upload_jobs_; |
| 127 |
|
|
|
| 128 |
|
|
pthread_t worker_; |
| 129 |
|
|
|
| 130 |
|
|
static UploadJob terminator_; |
| 131 |
|
|
}; |
| 132 |
|
|
|
| 133 |
|
|
} // namespace upload |
| 134 |
|
|
|
| 135 |
|
|
#endif // CVMFS_SESSION_CONTEXT_H_ |
| 136 |
|
|
|