5 #define __STDC_FORMAT_MACROS
22 const double WritableCatalog::kMaximalFreePageRatio = 0.20;
23 const double WritableCatalog::kMaximalRowIdWasteRatio = 0.25;
26 WritableCatalog::WritableCatalog(
const string &path,
29 const bool is_not_root) :
38 sql_chunk_insert_(NULL),
39 sql_chunks_remove_(NULL),
40 sql_chunks_count_(NULL),
41 sql_max_link_id_(NULL),
42 sql_inc_linkcount_(NULL),
53 const bool is_not_root) {
57 if (!successful_init) {
145 const string &entry_path,
146 const string &parent_path)
157 effective_entry.set_has_xattrs(!xattrs.
IsEmpty());
271 "and chunk size: %ld bytes",
369 vector<string> GrandChildMountpoints;
371 &GrandChildMountpoints);
408 const string directory,
410 vector<string> *grand_child_mountpoints)
415 const bool resolve_magic_symlinks =
false;
417 resolve_magic_symlinks);
422 for (DirectoryEntryList::const_iterator i = listing.begin(),
423 iEnd = listing.end(); i != iEnd; ++i)
425 const string full_path = i->GetFullPath(directory);
428 if (i->HasXattrs()) {
433 new_nested_catalog->
AddEntry(*i, xattrs, full_path);
435 new_nested_catalog->
AddEntry(*i, empty_xattrs, full_path);
439 if (i->IsNestedCatalogMountpoint()) {
440 grand_child_mountpoints->push_back(full_path);
441 }
else if (i->IsDirectory()) {
444 grand_child_mountpoints);
445 }
else if (i->IsChunkedFile()) {
457 const vector<string> &nested_catalogs,
460 for (vector<string>::const_iterator i = nested_catalogs.begin(),
461 iEnd = nested_catalogs.end(); i != iEnd; ++i)
464 uint64_t size_nested;
468 Catalog *attached_reference = NULL;
472 hash_nested, size_nested);
478 const std::string &full_path,
486 for (
unsigned i = 0; i < chunks.
size(); ++i) {
507 const string hash_string = (!content_hash.
IsNull()) ?
511 "VALUES (:p, :sha1, :size);");
521 if (attached_reference != NULL)
536 const string &mountpoint,
541 "INSERT INTO bind_mountpoints (path, sha1, size) "
542 "VALUES (:p, :sha1, :size);");
567 &dummy, &dummy_size);
571 "DELETE FROM nested_catalogs WHERE path = :p;");
583 if (attached_reference != NULL)
584 *attached_reference = child;
601 &dummy, &dummy_size);
605 "DELETE FROM bind_mountpoints WHERE path = :p;");
629 const string hash_str = hash.
ToString();
630 const string sql =
"UPDATE nested_catalogs SET sha1 = :sha1, size = :size "
631 "WHERE path = :path;";
688 for (NestedCatalogList::const_iterator i = nested_catalog_references.begin(),
689 iEnd = nested_catalog_references.end(); i != iEnd; ++i)
693 i->mountpoint.ToString(), child, i->
hash, i->size);
713 const uint64_t offset =
static_cast<uint64_t
>(parent->
GetMaxLinkId()) << 32;
714 const string update_link_ids =
715 "UPDATE catalog SET hardlinks = hardlinks + " +
StringifyInt(offset) +
716 " WHERE hardlinks > (1 << 32);";
719 bool retval = sql_update_link_ids.
Execute();
737 "SELECT * FROM main.catalog;").
Execute();
740 "SELECT * FROM main.chunks;").
Execute();
778 bool needs_defragmentation =
false;
783 needs_defragmentation =
true;
784 reason =
"free pages";
786 needs_defragmentation =
true;
787 reason =
"wasted row IDs";
790 if (needs_defragmentation) {
792 "Note: Catalog at %s gets defragmented (%.2f%% %s)... ",
void MoveFileChunksToNested(const std::string &full_path, const shash::Algorithms algorithm, WritableCatalog *new_nested_catalog)
void RemoveFileChunks(const std::string &entry_path)
bool BindPathHash(const shash::Md5 &hash)
const Counters & GetCounters() const
uint32_t GetMaxGroupId() const
std::string GetLastErrorMsg() const
SqlDirentInsert * sql_insert_
double GetFreePageRatio() const
bool BindText(const int index, const std::string &value)
std::string database_path() const
bool BindDirentBase(const DirectoryEntryBase &entry)
bool ListPathChunks(const PathString &path, const shash::Algorithms interpret_hashes_as, FileChunkList *chunks) const
static const double kMaximalFreePageRatio
bool IsChunkedFile() const
bool BindDirent(const DirectoryEntry &entry)
uint32_t GetMaxLinkId() const
void UpdateNestedCatalog(const std::string &path, const shash::Any &hash, const uint64_t size, const DeltaCounters &child_counters)
std::string ToString(const bool with_suffix=false) const
void InsertBindMountpoint(const std::string &mountpoint, const shash::Any content_hash, const uint64_t size)
void set_is_nested_catalog_root(const bool val)
bool BindFileChunk(const FileChunk &chunk)
bool LookupPath(const PathString &path, DirectoryEntry *dirent) const
void UpdateLastModified()
bool BindPathHash(const shash::Md5 &hash)
void ApplyDelta(const DeltaCounters &delta)
bool ListingPath(const PathString &path, DirectoryEntryList *listing, const bool expand_symlink=true) const
bool BeginTransaction() const
bool BindPathHash(const shash::Md5 &hash)
static DeltaCounters Diff(const Counters &from, const Counters &to)
void InsertNestedCatalog(const std::string &mountpoint, Catalog *attached_reference, const shash::Any content_hash, const uint64_t size)
void RemoveBindMountpoint(const std::string &mountpoint)
virtual void InitPreparedStatements()
void TouchEntry(const DirectoryEntryBase &entry, const XattrList &xattrs, const shash::Md5 &path_hash)
assert((mem||(size==0))&&"Out Of Memory")
void Increment(const DirectoryEntry &dirent)
SqlChunksCount * sql_chunks_count_
bool BindPathHash(const shash::Md5 &hash)
bool InitStandalone(const std::string &database_file)
int GetChunkCount() const
void CopyCatalogsToParent()
void SetPreviousRevision(const shash::Any &hash)
SqlChunkInsert * sql_chunk_insert_
void MoveToNestedRecursively(const std::string dir_structure_root, WritableCatalog *new_nested_catalog, std::vector< std::string > *grand_child_mountpoints)
Catalog * FindChild(const PathString &mountpoint) const
SqlChunksRemove * sql_chunks_remove_
void MakeTransitionPoint(const std::string &mountpoint)
SqlIncLinkcount * sql_inc_linkcount_
void MoveToNested(const std::string &dir_structure_root, WritableCatalog *new_nested_catalog, std::vector< std::string > *grand_child_mountpoints)
bool WriteToDatabase(const CatalogDatabase &database) const
bool IsNestedCatalogMountpoint() const
bool BindPathHash(const shash::Md5 &hash)
bool BindXattr(const XattrList &xattrs)
static WritableCatalog * AttachFreely(const std::string &root_path, const std::string &file, const shash::Any &catalog_hash, Catalog *parent=NULL, const bool is_not_root=false)
bool IsNestedCatalogRoot() const
uint64_t GetRevision() const
void AddFileChunk(const std::string &entry_path, const FileChunk &chunk)
std::vector< DirectoryEntry > DirectoryEntryList
void FinalizePreparedStatements()
bool BindDelta(const int delta)
atomic_int32 dirty_children_
bool BindPathHash(const shash::Md5 &hash)
SqlDirentUpdate * sql_update_
void SetTTL(const uint64_t new_ttl)
SqlMaxHardlinkGroup * sql_max_link_id_
bool LookupXattrsPath(const PathString &path, XattrList *xattrs) const
bool LookupMd5Path(const shash::Md5 &md5path, DirectoryEntry *dirent) const
void AddChild(Catalog *child)
void PopulateToParent(DeltaCounters *parent) const
bool BindXattr(const XattrList &xattrs)
void Decrement(const DirectoryEntry &dirent)
void ResetNestedCatalogCacheUnprotected()
bool SetVOMSAuthz(const std::string &)
PathString mountpoint() const
string StringifyInt(const int64_t value)
WritableCatalog(const std::string &path, const shash::Any &catalog_hash, Catalog *parent, const bool is_not_root=false)
bool CommitTransaction() const
bool BindInt64(const int index, const sqlite3_int64 value)
void RemoveChild(Catalog *child)
bool SetProperty(const std::string &key, const T value)
static const double kMaximalRowIdWasteRatio
void RemoveNestedCatalog(const std::string &mountpoint, Catalog **attached_reference)
bool SetVOMSAuthz(const std::string &voms_authz)
void AddEntry(const DirectoryEntry &entry, const XattrList &xattr, const std::string &entry_path, const std::string &parent_path)
SqlDirentTouch * sql_touch_
std::string ToString() const
void InitPreparedStatements()
std::vector< NestedCatalog > NestedCatalogList
SqlDirentUnlink * sql_unlink_
void SetBranch(const std::string &branch_name)
const NestedCatalogList ListOwnNestedCatalogs() const
void Partition(WritableCatalog *new_nested_catalog)
ShortString< kDefaultMaxPath, 0 > PathString
void SetRevision(const uint64_t new_revision)
void MoveCatalogsToNested(const std::vector< std::string > &nested_catalogs, WritableCatalog *new_nested_catalog)
virtual ~WritableCatalog()
WritableCatalog * GetWritableParent() const
DeltaCounters delta_counters_
const CatalogDatabase & database() const
bool FindNested(const PathString &mountpoint, shash::Any *hash, uint64_t *size) const
void VacuumDatabaseIfNecessary()
bool ReadCatalogCounters()
Counters & GetWritableCounters()
double GetRowIdWasteRatio() const
const char * c_str() const
void RemoveEntry(const std::string &entry_path)
bool BindParentPathHash(const shash::Md5 &hash)
void MergeIntoParent(DeltaCounters *parent_delta) const
void IncLinkcount(const std::string &path_within_group, const int delta)
const Item * AtPtr(const size_t index) const
void set_is_nested_catalog_mountpoint(const bool val)
bool BindPathHash(const shash::Md5 &hash)
void UpdateEntry(const DirectoryEntry &entry, const shash::Md5 &path_hash)
void RemoveFromSubtree(const DeltaCounters &child)
bool BindPathHash(const shash::Md5 &hash)
bool BindDirent(const DirectoryEntry &entry)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)