5 #ifndef CVMFS_CATALOG_BALANCER_IMPL_H_
6 #define CVMFS_CATALOG_BALANCER_IMPL_H_
27 template<
class CatalogMgrT>
29 string name, uid_t uid, gid_t gid) {
34 void *empty_compressed;
35 uint64_t sz_empty_compressed;
37 &sz_empty_compressed);
40 sz_empty_compressed, &file_hash);
41 free(empty_compressed);
45 deb.
mode_ = S_IFREG | S_IRUSR | S_IWUSR;
53 template<
class CatalogMgrT>
61 ".cvmfscatalog", parent.
uid(), parent.
gid());
63 ".cvmfsautocatalog", parent.
uid(), parent.
gid());
64 string relative_path = path.substr(1);
69 template<
class CatalogMgrT>
71 if (catalog == NULL) {
77 reverse(catalogs.begin(), catalogs.end());
78 for (
unsigned i = 0; i < catalogs.size(); ++i)
82 string catalog_path = catalog->mountpoint().ToString();
86 PartitionOptimally(&root_node);
89 template<
class CatalogMgrT>
93 for (
unsigned i = 0; i < virtual_node->
children.size(); ++i) {
96 PartitionOptimally(virtual_child);
103 if (heaviest_node != NULL
107 unsigned max_weight = heaviest_node->
weight;
108 AddCatalogMarker(heaviest_node->
path);
109 AddCatalog(heaviest_node);
110 virtual_node->
weight -= (max_weight - 1);
115 "Couldn't create a new nested catalog"
116 " in any subdirectory of '%s' even though"
117 " currently it is overflowed",
118 virtual_node->
path.c_str());
124 template<
class CatalogMgrT>
128 unsigned max_weight = 0;
131 for (
unsigned i = 0; i < virtual_node->
children.size(); ++i) {
134 && max_weight < child->
weight) {
135 max_weight = child->
weight;
143 template<
class CatalogMgrT>
145 assert(child_node != NULL);
146 string new_catalog_path = child_node->
path.substr(1);
151 "Automatic creation of nested"
153 child_node->
path.c_str());
156 template<
class CatalogMgrT>
158 CatalogMgrT *catalog_mgr) {
160 catalog_mgr->Listing(path, &direntlist);
161 for (
unsigned i = 0; i < direntlist.size(); ++i) {
162 string child_path = path +
"/" + direntlist[i].name().ToString();
163 children.push_back(
virtual_node_t(child_path, direntlist[i], catalog_mgr));
164 weight += children[i].weight;
181 template<
class CatalogMgrT>
184 if (!IsCatalog() && IsDirectory()) {
185 for (
unsigned i = 0; i < children.size(); ++i) {
186 weight += children[i].weight;
193 #endif // CVMFS_CATALOG_BALANCER_IMPL_H_
ShortString< kDefaultMaxName, 1 > NameString
void Balance(catalog_t *catalog)
assert((mem||(size==0))&&"Out Of Memory")
bool LookupPath(const PathString &path, const LookupOptions options, DirectoryEntry *entry)
CatalogMgrT::catalog_t catalog_t
const unsigned balance_weight_
const unsigned kLookupDefault
catalog::WritableCatalogManager * catalog_mgr_
std::vector< DirectoryEntry > DirectoryEntryList
bool is_new_nested_catalog
upload::Spooler * spooler_
const unsigned min_weight_
void HashMem(const unsigned char *buffer, const unsigned buffer_size, Any *any_digest)
ShortString< kDefaultMaxPath, 0 > PathString
const std::vector< CatalogT * > & GetCatalogs() const
bool CompressMem2Mem(const void *buf, const int64_t size, void **out_buf, uint64_t *out_size)
void ExtractChildren(CatalogMgrT *catalog_mgr)
std::vector< VirtualNode > children
void AddFile(const DirectoryEntryBase &entry, const XattrList &xattrs, const std::string &parent_directory)
void CreateNestedCatalog(const std::string &mountpoint)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)