CernVM-FS  2.9.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(), weight(1), dirent(), path(path),
114  is_new_nested_catalog(false) {
115  catalog_mgr->LookupPath(path, kLookupSole, &dirent);
116  }
117  VirtualNode(const std::string &path, const DirectoryEntry &dirent,
118  CatalogMgrT *catalog_mgr)
119  : children(), weight(1), dirent(dirent), path(path),
120  is_new_nested_catalog(false) {
121  if (!IsCatalog() && IsDirectory())
122  ExtractChildren(catalog_mgr);
123  }
124  bool IsDirectory() { return dirent.IsDirectory(); }
125  bool IsCatalog() { return is_new_nested_catalog ||
127  };
129 
130  void PartitionOptimally(VirtualNode *virtual_node);
131  void AddCatalogMarker(std::string path);
133  uid_t uid,
134  gid_t gid);
135  static VirtualNode *MaxChild(VirtualNode *virtual_node);
136  void AddCatalog(VirtualNode *child_node);
137 
138  CatalogMgrT *catalog_mgr_;
139 };
140 
141 } // namespace catalog
142 
143 #include "catalog_balancer_impl.h"
144 
145 #endif // CVMFS_CATALOG_BALANCER_H_
146 
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
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)