CernVM-FS  2.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fetch.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_FETCH_H_
6 #define CVMFS_FETCH_H_
7 
8 #include <pthread.h>
9 
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 #include "cache.h"
15 #include "crypto/hash.h"
16 #include "gtest/gtest_prod.h"
17 #include "network/download.h"
18 #include "network/sink.h"
19 
20 class BackoffThrottle;
21 
22 namespace perf {
23 class Statistics;
24 }
25 
26 namespace cvmfs {
27 
33 class TransactionSink : public Sink {
34  public:
35  TransactionSink(CacheManager *cache_mgr, void *open_txn)
36  : cache_mgr_(cache_mgr)
37  , open_txn_(open_txn)
38  { }
39  virtual ~TransactionSink() { }
40  virtual int64_t Write(const void *buf, uint64_t sz) {
41  return cache_mgr_->Write(buf, sz, open_txn_);
42  }
43  virtual int Reset() {
44  return cache_mgr_->Reset(open_txn_);
45  }
46 
47  private:
49  void *open_txn_;
50 };
51 
52 
62  FRIEND_TEST(T_Fetcher, GetTls);
64  friend void *TestGetTls(void *data);
65  friend void *TestFetchCollapse(void *data);
66  friend void *TestFetchCollapse2(void *data);
67  friend void TLSDestructor(void *data);
68 
69  public:
72  BackoffThrottle *backoff_throttle,
73  perf::StatisticsTemplate statistics,
74  bool external_data = false);
75  ~Fetcher();
76  // TODO(jblomer): reduce number of arguments
77  int Fetch(const shash::Any &id,
78  const uint64_t size,
79  const std::string &name,
80  const zlib::Algorithms compression_algorithm,
81  const CacheManager::ObjectType object_type,
82  const std::string &alt_url = "",
83  off_t range_offset = -1);
84 
87 
88  private:
96  pipe_wait[0] = -1;
97  pipe_wait[1] = -1;
98  fetcher = NULL;
99  }
100 
109  int pipe_wait[2];
114  std::vector<int> other_pipes_waiting;
120  };
121 
128  typedef std::map< shash::Any, std::vector<int> * > ThreadQueues;
129 
131  void CleanupTls(ThreadLocalStorage *tls);
132  void SignalWaitingThreads(const int fd, const shash::Any &id,
133  ThreadLocalStorage *tls);
134  int OpenSelect(const shash::Any &id,
135  const std::string &name,
136  const CacheManager::ObjectType object_type);
137 
143  bool external_;
144 
148  pthread_key_t thread_local_storage_;
149 
151  pthread_mutex_t *lock_queues_download_;
152 
157  std::vector<ThreadLocalStorage *> tls_blocks_;
158  pthread_mutex_t *lock_tls_blocks_;
159 
165 };
166 
167 } // namespace cvmfs
168 
169 #endif // CVMFS_FETCH_H_
void CleanupTls(ThreadLocalStorage *tls)
Definition: fetch.cc:51
friend void TLSDestructor(void *data)
Definition: fetch.cc:25
virtual int64_t Write(const void *buf, uint64_t sz)
Definition: fetch.h:40
BackoffThrottle * backoff_throttle_
Definition: fetch.h:162
std::map< shash::Any, std::vector< int > * > ThreadQueues
Definition: fetch.h:128
ThreadLocalStorage * GetTls()
Definition: fetch.cc:60
download::DownloadManager * download_mgr()
Definition: fetch.h:86
perf::Counter * n_invocations
Definition: fetch.h:164
Fetcher(CacheManager *cache_mgr, download::DownloadManager *download_mgr, BackoffThrottle *backoff_throttle, perf::StatisticsTemplate statistics, bool external_data=false)
Definition: fetch.cc:209
CacheManager * cache_mgr_
Definition: fetch.h:160
ThreadQueues queues_download_
Definition: fetch.h:150
CacheManager * cache_mgr()
Definition: fetch.h:85
std::vector< ThreadLocalStorage * > tls_blocks_
Definition: fetch.h:157
std::vector< int > other_pipes_waiting
Definition: fetch.h:114
pthread_mutex_t * lock_tls_blocks_
Definition: fetch.h:158
pthread_mutex_t * lock_queues_download_
Definition: fetch.h:151
CacheManager * cache_mgr_
Definition: fetch.h:48
Algorithms
Definition: compression.h:44
TransactionSink(CacheManager *cache_mgr, void *open_txn)
Definition: fetch.h:35
download::DownloadManager * download_mgr_
Definition: fetch.h:161
virtual ~TransactionSink()
Definition: fetch.h:39
int OpenSelect(const shash::Any &id, const std::string &name, const CacheManager::ObjectType object_type)
Definition: fetch.cc:266
void SignalWaitingThreads(const int fd, const shash::Any &id, ThreadLocalStorage *tls)
Definition: fetch.cc:280
FRIEND_TEST(T_Fetcher, GetTls)
virtual int Reset(void *txn)=0
download::JobInfo download_job
Definition: fetch.h:119
friend void * TestFetchCollapse2(void *data)
friend void * TestGetTls(void *data)
perf::Counter * n_downloads
Definition: fetch.h:163
virtual int Reset()
Definition: fetch.h:43
static void size_t size
Definition: smalloc.h:47
pthread_key_t thread_local_storage_
Definition: fetch.h:148
friend void * TestFetchCollapse(void *data)
virtual int64_t Write(const void *buf, uint64_t sz, void *txn)=0
bool external_
Definition: fetch.h:143
int Fetch(const shash::Any &id, const uint64_t size, const std::string &name, const zlib::Algorithms compression_algorithm, const CacheManager::ObjectType object_type, const std::string &alt_url="", off_t range_offset=-1)
Definition: fetch.cc:82