dmlite
0.6
|
00001 /// @file include/dmlite/cpp/pooldriver.h 00002 /// @brief Pool handling API. 00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch> 00004 #ifndef DMLITE_CPP_POOLDRIVER_H 00005 #define DMLITE_CPP_POOLDRIVER_H 00006 00007 #include "../common/config.h" 00008 #include "base.h" 00009 #include "exceptions.h" 00010 #include "inode.h" 00011 #include "utils/urls.h" 00012 00013 #include <map> 00014 #include <vector> 00015 00016 namespace dmlite { 00017 00018 // Forward declarations. 00019 class Pool; 00020 class StackInstance; 00021 00022 /// Represents a chunk of a file. 00023 struct Chunk { 00024 off_t offset; 00025 size_t size; 00026 Url url; 00027 00028 bool operator == (const Chunk&) const; 00029 bool operator != (const Chunk&) const; 00030 bool operator < (const Chunk&) const; 00031 bool operator > (const Chunk&) const; 00032 }; 00033 00034 /// Represent the complete location of a file. 00035 struct Location: public std::vector<Chunk> { 00036 Location() {} 00037 Location(int nitems, const Chunk& proto): std::vector<Chunk>(nitems, proto) {} 00038 00039 Location(const Location& l): std::vector<Chunk>(l) {} 00040 }; 00041 00042 /// Handler for a pool. Works similary to a file handler. 00043 class PoolHandler { 00044 public: 00045 /// Destructor 00046 virtual ~PoolHandler(); 00047 00048 /// Get the pool type of this pool. 00049 virtual std::string getPoolType(void) throw (DmException); 00050 00051 /// Get the pool name of this pool. 00052 virtual std::string getPoolName(void) throw (DmException); 00053 00054 /// Get the total space of this pool. 00055 virtual uint64_t getTotalSpace(void) throw (DmException); 00056 00057 /// Get the free space of this pool. 00058 virtual uint64_t getFreeSpace(void) throw (DmException); 00059 00060 /// Check if the pool is actually available. 00061 virtual bool poolIsAvailable(bool write = true) throw (DmException); 00062 00063 /// Check if a replica is available. 00064 virtual bool replicaIsAvailable(const Replica& replica) throw (DmException); 00065 00066 /// Get the actual location of the file replica. This is pool-specific. 00067 virtual Location whereToRead(const Replica& replica) throw (DmException); 00068 00069 /// Remove a replica from the pool. 00070 virtual void removeReplica(const Replica& replica) throw (DmException); 00071 00072 /// Get where to put a file. 00073 virtual Location whereToWrite(const std::string& path) throw (DmException); 00074 00075 /// Cancel a write. 00076 virtual void cancelWrite(const Location& loc) throw (DmException); 00077 }; 00078 00079 /// Interface for a pool driver 00080 class PoolDriver: public virtual BaseInterface { 00081 public: 00082 /// Destructor 00083 virtual ~PoolDriver(); 00084 00085 /// Create a handler. 00086 virtual PoolHandler* createPoolHandler(const std::string& poolName) throw (DmException); 00087 00088 /// Called just before adding the pool to the database. 00089 /// To be used by a plugin, in case it needs to do some previous preparations. 00090 /// (i.e. legacy filesystem will actually create the pool here) 00091 virtual void toBeCreated(const Pool& pool) throw (DmException); 00092 00093 /// Called just after a pool is added to the database. 00094 virtual void justCreated(const Pool& pool) throw (DmException); 00095 00096 /// Called when updating a pool. 00097 virtual void update(const Pool& pool) throw (DmException); 00098 00099 /// Called just before a pool of this type is removed. 00100 /// @note The driver may remove the pool itself (i.e. filesystem) 00101 virtual void toBeDeleted(const Pool& pool) throw (DmException); 00102 }; 00103 00104 /// PoolDriver factory 00105 class PoolDriverFactory: public virtual BaseFactory { 00106 public: 00107 /// Destructor. 00108 virtual ~PoolDriverFactory(); 00109 00110 /// Supported pool type 00111 virtual std::string implementedPool() throw (); 00112 00113 protected: 00114 friend class StackInstance; 00115 00116 /// Instantiate the implemented pool driver. 00117 virtual PoolDriver* createPoolDriver(void) throw (DmException); 00118 }; 00119 00120 }; 00121 00122 #endif // DMLITE_CPP_POOLDRIVER_H