5 #define __STDC_FORMAT_MACROS
23 const double WritableCatalog::kMaximalFreePageRatio = 0.20;
24 const double WritableCatalog::kMaximalRowIdWasteRatio = 0.25;
27 WritableCatalog::WritableCatalog(
const string &path,
30 const bool is_not_root)
39 , sql_chunk_insert_(NULL)
40 , sql_chunks_remove_(NULL)
41 , sql_chunks_count_(NULL)
42 , sql_max_link_id_(NULL)
43 , sql_inc_linkcount_(NULL)
53 const bool is_not_root) {
57 if (!successful_init) {
145 const string &entry_path,
146 const string &parent_path) {
155 effective_entry.set_has_xattrs(!xattrs.
IsEmpty());
262 "adding chunk for %s from offset %ld "
263 "and chunk size: %ld bytes",
354 vector<string> GrandChildMountpoints;
356 &GrandChildMountpoints);
369 PathString(mountpoint.data(), mountpoint.length()), &transition_entry);
393 const string directory,
395 vector<string> *grand_child_mountpoints) {
399 const bool resolve_magic_symlinks =
false;
401 resolve_magic_symlinks);
406 for (DirectoryEntryList::const_iterator i = listing.begin(),
407 iEnd = listing.end();
410 const string full_path = i->GetFullPath(directory);
413 if (i->HasXattrs()) {
418 new_nested_catalog->
AddEntry(*i, xattrs, full_path);
420 new_nested_catalog->
AddEntry(*i, empty_xattrs, full_path);
424 if (i->IsNestedCatalogMountpoint()) {
425 grand_child_mountpoints->push_back(full_path);
426 }
else if (i->IsDirectory()) {
429 grand_child_mountpoints);
430 }
else if (i->IsChunkedFile()) {
442 const vector<string> &nested_catalogs,
444 for (vector<string>::const_iterator i = nested_catalogs.begin(),
445 iEnd = nested_catalogs.end();
449 uint64_t size_nested;
453 Catalog *attached_reference = NULL;
463 const std::string &full_path,
470 for (
unsigned i = 0; i < chunks.
size(); ++i) {
489 const uint64_t
size) {
490 const string hash_string = (!content_hash.
IsNull()) ? content_hash.
ToString()
494 "VALUES (:p, :sha1, :size);");
495 const bool retval = stmt.
BindText(1, mountpoint) &&
502 if (attached_reference != NULL)
518 const uint64_t
size) {
520 "INSERT INTO bind_mountpoints (path, sha1, size) "
521 "VALUES (:p, :sha1, :size);");
522 const bool retval = stmt.
BindText(1, mountpoint) &&
539 Catalog **attached_reference) {
543 &dummy, &dummy_size);
556 if (attached_reference != NULL)
557 *attached_reference = child;
574 &dummy, &dummy_size);
599 const string hash_str = hash.
ToString();
600 const string sql =
"UPDATE nested_catalogs SET sha1 = :sha1, size = :size "
601 "WHERE path = :path;";
655 for (NestedCatalogList::const_iterator i = nested_catalog_references.begin(),
656 iEnd = nested_catalog_references.end();
681 const uint64_t offset =
static_cast<uint64_t
>(parent->
GetMaxLinkId()) << 32;
682 const string update_link_ids =
"UPDATE catalog SET hardlinks = hardlinks + "
684 +
" WHERE hardlinks > (1 << 32);";
687 bool retval = sql_update_link_ids.
Execute();
706 "SELECT * FROM main.catalog;")
710 "SELECT * FROM main.chunks;")
749 bool needs_defragmentation =
false;
754 needs_defragmentation =
true;
755 reason =
"free pages";
757 needs_defragmentation =
true;
758 reason =
"wasted row IDs";
761 if (needs_defragmentation) {
763 "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,...)