CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quota.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_QUOTA_H_
6 #define CVMFS_QUOTA_H_
7 
8 #include <pthread.h>
9 #include <stdint.h>
10 #include <unistd.h>
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include "crypto/hash.h"
17 #include "util/single_copy.h"
18 
37  public:
45  static const uint32_t kProtocolRevision;
46 
47  enum Capabilities {
53  };
54 
55  QuotaManager();
56  virtual ~QuotaManager();
57  virtual bool HasCapability(Capabilities capability) = 0;
58 
59  virtual void Insert(const shash::Any &hash, const uint64_t size,
60  const std::string &description) = 0;
61  virtual void InsertVolatile(const shash::Any &hash, const uint64_t size,
62  const std::string &description) = 0;
63  virtual bool Pin(const shash::Any &hash, const uint64_t size,
64  const std::string &description, const bool is_catalog) = 0;
65  virtual void Unpin(const shash::Any &hash) = 0;
66  virtual void Touch(const shash::Any &hash) = 0;
67  virtual void Remove(const shash::Any &file) = 0;
68  virtual bool Cleanup(const uint64_t leave_size) = 0;
69 
70  virtual std::vector<std::string> List() = 0;
71  virtual std::vector<std::string> ListPinned() = 0;
72  virtual std::vector<std::string> ListCatalogs() = 0;
73  virtual std::vector<std::string> ListVolatile() = 0;
74  virtual uint64_t GetMaxFileSize() = 0;
75  virtual uint64_t GetCapacity() = 0;
76  virtual uint64_t GetSize() = 0;
77  virtual uint64_t GetSizePinned() = 0;
78  virtual bool SetLimit(uint64_t limit) = 0;
79  virtual uint64_t GetCleanupRate(uint64_t period_s) = 0;
80 
81  virtual void Spawn() = 0;
82  virtual pid_t GetPid() = 0;
83  virtual uint32_t GetProtocolRevision() = 0;
84 
85  virtual void RegisterBackChannel(int back_channel[2],
86  const std::string &channel_id) = 0;
87  virtual void UnregisterBackChannel(int back_channel[2],
88  const std::string &channel_id) = 0;
89  void BroadcastBackchannels(const std::string &message);
90 
91  protected:
95  std::map<shash::Md5, int> back_channels_;
96  pthread_mutex_t *lock_back_channels_;
98  int retval = pthread_mutex_lock(lock_back_channels_);
99  assert(retval == 0);
100  }
102  int retval = pthread_mutex_unlock(lock_back_channels_);
103  assert(retval == 0);
104  }
105 
111 };
112 
113 
118  public:
119  virtual ~NoopQuotaManager() { }
120  virtual bool HasCapability(Capabilities capability) { return false; }
121 
122  virtual void Insert(const shash::Any &hash, const uint64_t size,
123  const std::string &description) { }
124  virtual void InsertVolatile(const shash::Any &hash, const uint64_t size,
125  const std::string &description) { }
126  virtual bool Pin(const shash::Any &hash, const uint64_t size,
127  const std::string &description, const bool is_catalog)
128  {
129  return true;
130  }
131  virtual void Unpin(const shash::Any &hash) { }
132  virtual void Touch(const shash::Any &hash) { }
133  virtual void Remove(const shash::Any &file) { }
134  virtual bool Cleanup(const uint64_t leave_size) { return false; }
135 
136  virtual void RegisterBackChannel(int back_channel[2],
137  const std::string &channel_id) { }
138  virtual void UnregisterBackChannel(int back_channel[2],
139  const std::string &channel_id) { }
140 
141  virtual std::vector<std::string> List() { return std::vector<std::string>(); }
142  virtual std::vector<std::string> ListPinned() {
143  return std::vector<std::string>();
144  }
145  virtual std::vector<std::string> ListCatalogs() {
146  return std::vector<std::string>();
147  }
148  virtual std::vector<std::string> ListVolatile() {
149  return std::vector<std::string>();
150  }
151  virtual uint64_t GetMaxFileSize() { return uint64_t(-1); }
152  virtual uint64_t GetCapacity() { return uint64_t(-1); }
153  virtual uint64_t GetSize() { return 0; }
154  virtual uint64_t GetSizePinned() { return 0; }
155  virtual bool SetLimit(uint64_t) {return false;}
156  virtual uint64_t GetCleanupRate(uint64_t period_s) { return 0; }
157 
158  virtual void Spawn() { }
159  virtual pid_t GetPid() { return getpid(); }
160  virtual uint32_t GetProtocolRevision() { return 0; }
161 };
162 
163 #endif // CVMFS_QUOTA_H_
virtual bool HasCapability(Capabilities capability)
Definition: quota.h:120
virtual bool SetLimit(uint64_t limit)=0
pthread_mutex_t * lock_back_channels_
Definition: quota.h:96
virtual bool SetLimit(uint64_t)
Definition: quota.h:155
virtual uint64_t GetCleanupRate(uint64_t period_s)=0
void BroadcastBackchannels(const std::string &message)
Definition: quota.cc:21
virtual std::vector< std::string > List()=0
virtual void Unpin(const shash::Any &hash)=0
virtual bool Cleanup(const uint64_t leave_size)=0
virtual void Spawn()
Definition: quota.h:158
virtual std::vector< std::string > ListVolatile()=0
Capabilities
Definition: quota.h:47
static const uint32_t kProtocolRevision
Definition: quota.h:45
virtual uint64_t GetMaxFileSize()
Definition: quota.h:151
virtual std::vector< std::string > ListPinned()=0
virtual ~QuotaManager()
Definition: quota.cc:62
virtual std::vector< std::string > ListCatalogs()
Definition: quota.h:145
assert((mem||(size==0))&&"Out Of Memory")
virtual uint64_t GetCleanupRate(uint64_t period_s)
Definition: quota.h:156
virtual std::vector< std::string > ListCatalogs()=0
virtual uint64_t GetSize()=0
virtual pid_t GetPid()=0
virtual std::vector< std::string > List()
Definition: quota.h:141
virtual void InsertVolatile(const shash::Any &hash, const uint64_t size, const std::string &description)
Definition: quota.h:124
virtual pid_t GetPid()
Definition: quota.h:159
virtual uint64_t GetCapacity()=0
virtual void InsertVolatile(const shash::Any &hash, const uint64_t size, const std::string &description)=0
virtual void Spawn()=0
virtual uint64_t GetSizePinned()
Definition: quota.h:154
virtual uint64_t GetSize()
Definition: quota.h:153
virtual ~NoopQuotaManager()
Definition: quota.h:119
virtual void Insert(const shash::Any &hash, const uint64_t size, const std::string &description)=0
virtual void Touch(const shash::Any &hash)=0
virtual bool Pin(const shash::Any &hash, const uint64_t size, const std::string &description, const bool is_catalog)=0
void LockBackChannels()
Definition: quota.h:97
virtual bool Cleanup(const uint64_t leave_size)
Definition: quota.h:134
virtual uint64_t GetSizePinned()=0
QuotaManager()
Definition: quota.cc:54
uint32_t protocol_revision_
Definition: quota.h:110
virtual void RegisterBackChannel(int back_channel[2], const std::string &channel_id)=0
std::map< shash::Md5, int > back_channels_
Definition: quota.h:95
virtual uint64_t GetCapacity()
Definition: quota.h:152
virtual std::vector< std::string > ListVolatile()
Definition: quota.h:148
virtual bool Pin(const shash::Any &hash, const uint64_t size, const std::string &description, const bool is_catalog)
Definition: quota.h:126
virtual uint32_t GetProtocolRevision()
Definition: quota.h:160
virtual void UnregisterBackChannel(int back_channel[2], const std::string &channel_id)
Definition: quota.h:138
virtual void UnregisterBackChannel(int back_channel[2], const std::string &channel_id)=0
virtual void Touch(const shash::Any &hash)
Definition: quota.h:132
virtual void Insert(const shash::Any &hash, const uint64_t size, const std::string &description)
Definition: quota.h:122
virtual void Remove(const shash::Any &file)
Definition: quota.h:133
virtual void RegisterBackChannel(int back_channel[2], const std::string &channel_id)
Definition: quota.h:136
virtual uint64_t GetMaxFileSize()=0
virtual void Unpin(const shash::Any &hash)
Definition: quota.h:131
virtual void Remove(const shash::Any &file)=0
static void size_t size
Definition: smalloc.h:54
virtual uint32_t GetProtocolRevision()=0
void UnlockBackChannels()
Definition: quota.h:101
virtual bool HasCapability(Capabilities capability)=0
virtual std::vector< std::string > ListPinned()
Definition: quota.h:142