CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
catalog_balancer.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_CATALOG_BALANCER_H_
6 #define CVMFS_CATALOG_BALANCER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "catalog_mgr.h"
12 #include "directory_entry.h"
13 
14 
15 namespace catalog {
16 
45 template<class CatalogMgrT>
47  public:
48  typedef typename CatalogMgrT::catalog_t catalog_t;
49  explicit CatalogBalancer(CatalogMgrT *catalog_mgr)
50  : catalog_mgr_(catalog_mgr) { }
51 
79  void Balance(catalog_t *catalog);
80 
81  private:
94  struct VirtualNode {
95  std::vector<VirtualNode> children;
96  unsigned weight;
98  std::string path;
100 
110  void ExtractChildren(CatalogMgrT *catalog_mgr);
111  void FixWeight();
112  VirtualNode(const std::string &path, CatalogMgrT *catalog_mgr)
113  : children()
114  , weight(1)
115  , dirent()
116  , path(path)
117  , is_new_nested_catalog(false) {
118  catalog_mgr->LookupPath(path, kLookupDefault, &dirent);
119  }
120  VirtualNode(const std::string &path, const DirectoryEntry &dirent,
121  CatalogMgrT *catalog_mgr)
122  : children()
123  , weight(1)
124  , dirent(dirent)
125  , path(path)
126  , is_new_nested_catalog(false) {
127  if (!IsCatalog() && IsDirectory())
128  ExtractChildren(catalog_mgr);
129  }
130  bool IsDirectory() { return dirent.IsDirectory(); }
131  bool IsCatalog() {
133  }
134  };
136 
137  void PartitionOptimally(VirtualNode *virtual_node);
138  void AddCatalogMarker(std::string path);
140  uid_t uid,
141  gid_t gid);
142  static VirtualNode *MaxChild(VirtualNode *virtual_node);
143  void AddCatalog(VirtualNode *child_node);
144 
145  CatalogMgrT *catalog_mgr_;
146 };
147 
148 } // namespace catalog
149 
150 #include "catalog_balancer_impl.h"
151 
152 #endif // CVMFS_CATALOG_BALANCER_H_
void PartitionOptimally(VirtualNode *virtual_node)
bool IsDirectory() const
CatalogBalancer(CatalogMgrT *catalog_mgr)
void Balance(catalog_t *catalog)
DirectoryEntryBase MakeEmptyDirectoryEntryBase(std::string name, uid_t uid, gid_t gid)
VirtualNode(const std::string &path, CatalogMgrT *catalog_mgr)
CatalogMgrT::catalog_t catalog_t
const unsigned kLookupDefault
Definition: catalog_mgr.h:43
bool IsNestedCatalogMountpoint() const
CatalogBalancer< CatalogMgrT >::VirtualNode virtual_node_t
static VirtualNode * MaxChild(VirtualNode *virtual_node)
void ExtractChildren(CatalogMgrT *catalog_mgr)
std::vector< VirtualNode > children
void AddCatalog(VirtualNode *child_node)
VirtualNode(const std::string &path, const DirectoryEntry &dirent, CatalogMgrT *catalog_mgr)
void AddCatalogMarker(std::string path)