CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cache_posix.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_CACHE_POSIX_H_
6 #define CVMFS_CACHE_POSIX_H_
7 
8 #include <stdint.h>
9 #include <sys/types.h>
10 
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #include "atomic.h"
16 #include "backoff.h"
17 #include "cache.h"
18 #include "catalog_mgr.h"
19 #include "file_chunk.h"
20 #include "gtest/gtest_prod.h"
21 #include "manifest_fetch.h"
22 #include "shortstring.h"
23 #include "signature.h"
24 #include "statistics.h"
25 
26 namespace catalog {
27 class DirectoryEntry;
28 class Catalog;
29 }
30 
31 namespace download {
32 class DownloadManager;
33 }
34 
40  FRIEND_TEST(T_CacheManager, CommitTxnQuotaNotifications);
41  FRIEND_TEST(T_CacheManager, CommitTxnRenameFail);
42  FRIEND_TEST(T_CacheManager, Open);
43  FRIEND_TEST(T_CacheManager, OpenFromTxn);
44  FRIEND_TEST(T_CacheManager, OpenPinned);
45  FRIEND_TEST(T_CacheManager, Rename);
46  FRIEND_TEST(T_CacheManager, StartTxn);
47  FRIEND_TEST(T_CacheManager, TearDown2ReadOnly);
48 
49  public:
50  enum CacheModes {
53  };
54 
59  };
60 
66  static const uint64_t kBigFile;
67 
68  virtual CacheManagerIds id() { return kPosixCacheManager; }
69  virtual std::string Describe();
70 
71  static PosixCacheManager *Create(
72  const std::string &cache_path,
73  const bool alien_cache,
74  const RenameWorkarounds rename_workaround = kRenameNormal);
75  virtual ~PosixCacheManager() { }
77 
78  virtual int Open(const BlessedObject &object);
79  virtual int64_t GetSize(int fd);
80  virtual int Close(int fd);
81  virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset);
82  virtual int Dup(int fd);
83  virtual int Readahead(int fd);
84 
85  virtual uint32_t SizeOfTxn() { return sizeof(Transaction); }
86  virtual int StartTxn(const shash::Any &id, uint64_t size, void *txn);
87  virtual void CtrlTxn(const ObjectInfo &object_info,
88  const int flags,
89  void *txn);
90  virtual int64_t Write(const void *buf, uint64_t size, void *txn);
91  virtual int Reset(void *txn);
92  virtual int OpenFromTxn(void *txn);
93  virtual int AbortTxn(void *txn);
94  virtual int CommitTxn(void *txn);
95 
96  virtual void Spawn() { }
97 
98  virtual manifest::Breadcrumb LoadBreadcrumb(const std::string &fqrn);
99  virtual bool StoreBreadcrumb(const manifest::Manifest &manifest);
100  bool StoreBreadcrumb(std::string fqrn, manifest::Breadcrumb breadcrumb);
101 
102  void TearDown2ReadOnly();
104  bool alien_cache() { return alien_cache_; }
105  std::string cache_path() { return cache_path_; }
106 
107  protected:
108  virtual void *DoSaveState();
109  virtual int DoRestoreState(void *data);
110  virtual bool DoFreeState(void *data);
111 
112  private:
113  struct Transaction {
114  Transaction(const shash::Any &id, const std::string &final_path)
115  : buf_pos(0)
116  , size(0)
118  , fd(-1)
120  , tmp_path()
121  , final_path(final_path)
122  , id(id)
123  { }
124 
125  unsigned char buffer[4096];
126  unsigned buf_pos;
127  uint64_t size;
128  uint64_t expected_size;
129  int fd;
131  std::string tmp_path;
132  std::string final_path;
134  };
135 
136  PosixCacheManager(const std::string &cache_path, const bool alien_cache)
137  : cache_path_(cache_path)
138  , txn_template_path_(cache_path_ + "/txn/fetchXXXXXX")
139  , alien_cache_(alien_cache)
143  {
144  atomic_init32(&no_inflight_txns_);
145  }
146 
147  std::string GetPathInCache(const shash::Any &id);
148  int Rename(const char *oldpath, const char *newpath);
149  int Flush(Transaction *transaction);
150 
151  std::string cache_path_;
152  std::string txn_template_path_;
156 
163 
168 }; // class PosixCacheManager
169 
170 #endif // CVMFS_CACHE_POSIX_H_
RenameWorkarounds rename_workaround_
Definition: cache_posix.h:154
virtual int64_t Write(const void *buf, uint64_t size, void *txn)
Definition: cache_posix.cc:550
const manifest::Manifest * manifest() const
Definition: repository.h:123
int Flush(Transaction *transaction)
Definition: cache_posix.cc:326
void TearDown2ReadOnly()
Definition: cache_posix.cc:539
int OpenPinned(const shash::Any &id, const std::string &description, bool is_catalog)
Definition: cache.cc:170
virtual int CommitTxn(void *txn)
Definition: cache_posix.cc:148
CacheModes cache_mode()
Definition: cache_posix.h:103
virtual int Open(const BlessedObject &object)
Definition: cache_posix.cc:356
virtual int AbortTxn(void *txn)
Definition: cache_posix.cc:113
virtual void * DoSaveState()
Definition: cache_posix.cc:296
virtual int64_t GetSize(int fd)
Definition: cache_posix.cc:347
virtual bool AcquireQuotaManager(QuotaManager *quota_mgr)
Definition: cache_posix.cc:131
CacheModes cache_mode_
Definition: cache_posix.h:155
std::string cache_path_
Definition: cache_posix.h:151
virtual int Dup(int fd)
Definition: cache_posix.cc:318
int Rename(const char *oldpath, const char *newpath)
Definition: cache_posix.cc:401
std::string GetPathInCache(const shash::Any &id)
Definition: cache_posix.cc:342
PosixCacheManager(const std::string &cache_path, const bool alien_cache)
Definition: cache_posix.h:136
virtual int OpenFromTxn(void *txn)
Definition: cache_posix.cc:372
virtual int Readahead(int fd)
Definition: cache_posix.cc:428
std::string txn_template_path_
Definition: cache_posix.h:152
int32_t atomic_int32
Definition: atomic.h:17
std::string cache_path()
Definition: cache_posix.h:105
unsigned char buffer[4096]
Definition: cache_posix.h:125
virtual void Spawn()
Definition: cache_posix.h:96
void Transaction()
Definition: repository.h:284
virtual void CtrlTxn(const ObjectInfo &object_info, const int flags, void *txn)
Definition: cache_posix.cc:277
static const uint64_t kBigFile
Definition: cache_posix.h:66
virtual int StartTxn(const shash::Any &id, uint64_t size, void *txn)
Definition: cache_posix.cc:457
virtual manifest::Breadcrumb LoadBreadcrumb(const std::string &fqrn)
Definition: cache_posix.cc:522
bool reports_correct_filesize_
Definition: cache_posix.h:167
CacheManagerIds
Definition: cache.h:23
virtual CacheManagerIds id()
Definition: cache_posix.h:68
FRIEND_TEST(T_CacheManager, CommitTxnQuotaNotifications)
virtual int Reset(void *txn)
Definition: cache_posix.cc:443
QuotaManager * quota_mgr()
Definition: cache.h:198
Transaction(const shash::Any &id, const std::string &final_path)
Definition: cache_posix.h:114
virtual bool DoFreeState(void *data)
Definition: cache_posix.cc:311
virtual int DoRestoreState(void *data)
Definition: cache_posix.cc:303
virtual std::string Describe()
Definition: cache_posix.cc:287
virtual bool StoreBreadcrumb(const manifest::Manifest &manifest)
Definition: cache_posix.cc:528
static void size_t size
Definition: smalloc.h:47
atomic_int32 no_inflight_txns_
Definition: cache_posix.h:162
virtual ~PosixCacheManager()
Definition: cache_posix.h:75
virtual int Close(int fd)
Definition: cache_posix.cc:140
virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset)
Definition: cache_posix.cc:384
static const uint64_t kSizeUnknown
Definition: cache.h:72
virtual uint32_t SizeOfTxn()
Definition: cache_posix.h:85
static PosixCacheManager * Create(const std::string &cache_path, const bool alien_cache, const RenameWorkarounds rename_workaround=kRenameNormal)
Definition: cache_posix.cc:230