CernVM-FS  2.10.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 "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 uint64_t GetCleanupRate(uint64_t period_s) = 0;
79 
80  virtual void Spawn() = 0;
81  virtual pid_t GetPid() = 0;
82  virtual uint32_t GetProtocolRevision() = 0;
83 
84  virtual void RegisterBackChannel(int back_channel[2],
85  const std::string &channel_id) = 0;
86  virtual void UnregisterBackChannel(int back_channel[2],
87  const std::string &channel_id) = 0;
88  void BroadcastBackchannels(const std::string &message);
89 
90  protected:
94  std::map<shash::Md5, int> back_channels_;
95  pthread_mutex_t *lock_back_channels_;
97  int retval = pthread_mutex_lock(lock_back_channels_);
98  assert(retval == 0);
99  }
101  int retval = pthread_mutex_unlock(lock_back_channels_);
102  assert(retval == 0);
103  }
104 
110 };
111 
112 
117  public:
118  virtual ~NoopQuotaManager() { }
119  virtual bool HasCapability(Capabilities capability) { return false; }
120 
121  virtual void Insert(const shash::Any &hash, const uint64_t size,
122  const std::string &description) { }
123  virtual void InsertVolatile(const shash::Any &hash, const uint64_t size,
124  const std::string &description) { }
125  virtual bool Pin(const shash::Any &hash, const uint64_t size,
126  const std::string &description, const bool is_catalog)
127  {
128  return true;
129  }
130  virtual void Unpin(const shash::Any &hash) { }
131  virtual void Touch(const shash::Any &hash) { }
132  virtual void Remove(const shash::Any &file) { }
133  virtual bool Cleanup(const uint64_t leave_size) { return false; }
134 
135  virtual void RegisterBackChannel(int back_channel[2],
136  const std::string &channel_id) { }
137  virtual void UnregisterBackChannel(int back_channel[2],
138  const std::string &channel_id) { }
139 
140  virtual std::vector<std::string> List() { return std::vector<std::string>(); }
141  virtual std::vector<std::string> ListPinned() {
142  return std::vector<std::string>();
143  }
144  virtual std::vector<std::string> ListCatalogs() {
145  return std::vector<std::string>();
146  }
147  virtual std::vector<std::string> ListVolatile() {
148  return std::vector<std::string>();
149  }
150  virtual uint64_t GetMaxFileSize() { return uint64_t(-1); }
151  virtual uint64_t GetCapacity() { return uint64_t(-1); }
152  virtual uint64_t GetSize() { return 0; }
153  virtual uint64_t GetSizePinned() { return 0; }
154  virtual uint64_t GetCleanupRate(uint64_t period_s) { return 0; }
155 
156  virtual void Spawn() { }
157  virtual pid_t GetPid() { return getpid(); }
158  virtual uint32_t GetProtocolRevision() { return 0; }
159 };
160 
161 #endif // CVMFS_QUOTA_H_
virtual bool HasCapability(Capabilities capability)
Definition: quota.h:119
pthread_mutex_t * lock_back_channels_
Definition: quota.h:95
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:156
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:150
virtual std::vector< std::string > ListPinned()=0
virtual ~QuotaManager()
Definition: quota.cc:62
virtual std::vector< std::string > ListCatalogs()
Definition: quota.h:144
assert((mem||(size==0))&&"Out Of Memory")
virtual uint64_t GetCleanupRate(uint64_t period_s)
Definition: quota.h:154
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:140
virtual void InsertVolatile(const shash::Any &hash, const uint64_t size, const std::string &description)
Definition: quota.h:123
virtual pid_t GetPid()
Definition: quota.h:157
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:153
virtual uint64_t GetSize()
Definition: quota.h:152
virtual ~NoopQuotaManager()
Definition: quota.h:118
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:96
virtual bool Cleanup(const uint64_t leave_size)
Definition: quota.h:133
virtual uint64_t GetSizePinned()=0
QuotaManager()
Definition: quota.cc:54
uint32_t protocol_revision_
Definition: quota.h:109
virtual void RegisterBackChannel(int back_channel[2], const std::string &channel_id)=0
std::map< shash::Md5, int > back_channels_
Definition: quota.h:94
virtual uint64_t GetCapacity()
Definition: quota.h:151
virtual std::vector< std::string > ListVolatile()
Definition: quota.h:147
virtual bool Pin(const shash::Any &hash, const uint64_t size, const std::string &description, const bool is_catalog)
Definition: quota.h:125
virtual uint32_t GetProtocolRevision()
Definition: quota.h:158
virtual void UnregisterBackChannel(int back_channel[2], const std::string &channel_id)
Definition: quota.h:137
virtual void UnregisterBackChannel(int back_channel[2], const std::string &channel_id)=0
virtual void Touch(const shash::Any &hash)
Definition: quota.h:131
virtual void Insert(const shash::Any &hash, const uint64_t size, const std::string &description)
Definition: quota.h:121
virtual void Remove(const shash::Any &file)
Definition: quota.h:132
virtual void RegisterBackChannel(int back_channel[2], const std::string &channel_id)
Definition: quota.h:135
virtual uint64_t GetMaxFileSize()=0
virtual void Unpin(const shash::Any &hash)
Definition: quota.h:130
virtual void Remove(const shash::Any &file)=0
static void size_t size
Definition: smalloc.h:47
virtual uint32_t GetProtocolRevision()=0
void UnlockBackChannels()
Definition: quota.h:100
virtual bool HasCapability(Capabilities capability)=0
virtual std::vector< std::string > ListPinned()
Definition: quota.h:141