From 342afcb7b6223fb86d63860818265d25873abc5e Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sat, 14 Mar 2026 16:03:38 +0100 Subject: [PATCH] Improve object file store logging --- src/lib/object_store/Directory.cpp | 30 +++++++++++++++++++++++++---- src/lib/object_store/Generation.cpp | 19 ++++++++++++++++++ src/lib/object_store/OSToken.cpp | 28 +++++++++++++++++++++------ src/lib/object_store/ObjectFile.cpp | 8 +++++++- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/lib/object_store/Directory.cpp b/src/lib/object_store/Directory.cpp index 8776c6422..d1a0a324d 100644 --- a/src/lib/object_store/Directory.cpp +++ b/src/lib/object_store/Directory.cpp @@ -108,7 +108,7 @@ bool Directory::refresh() if (dir == NULL) { - DEBUG_MSG("Failed to open directory %s", path.c_str()); + ERROR_MSG("Failed to open directory %s (%s)", path.c_str(), strerror(errno)); return false; } @@ -168,6 +168,10 @@ bool Directory::refresh() DEBUG_MSG("File not used %s", name.c_str()); } } + else + { + WARNING_MSG("Failed to stat %s (%s)", fullPath.c_str(), strerror(errno)); + } } } @@ -192,7 +196,7 @@ bool Directory::refresh() if (errno == ENOENT) goto finished; - DEBUG_MSG("Failed to open directory %s", path.c_str()); + ERROR_MSG("Failed to open directory %s (%s)", path.c_str(), strerror(errno)); return false; } @@ -218,6 +222,8 @@ bool Directory::refresh() valid = true; + DEBUG_MSG("Directory %s refreshed: %zu files, %zu subdirs", path.c_str(), files.size(), subDirs.size()); + return true; } @@ -255,10 +261,16 @@ bool Directory::rmdir(std::string name, bool doRefresh /* = false */) #ifndef _WIN32 if (::rmdir(fullPath.c_str()) != 0) + { + ERROR_MSG("Failed to remove directory %s (%s)", fullPath.c_str(), strerror(errno)); return false; + } #else if (_rmdir(fullPath.c_str()) != 0) + { + ERROR_MSG("Failed to remove directory %s (%s)", fullPath.c_str(), strerror(errno)); return false; + } #endif if (doRefresh) return refresh(); @@ -271,9 +283,19 @@ bool Directory::remove(std::string name) std::string fullPath = path + OS_PATHSEP + name; #ifndef _WIN32 - return (!::remove(fullPath.c_str()) && refresh()); + if (::remove(fullPath.c_str()) != 0) + { + ERROR_MSG("Failed to remove file %s (%s)", fullPath.c_str(), strerror(errno)); + return false; + } + return refresh(); #else - return (!_unlink(fullPath.c_str()) && refresh()); + if (_unlink(fullPath.c_str()) != 0) + { + ERROR_MSG("Failed to remove file %s (%s)", fullPath.c_str(), strerror(errno)); + return false; + } + return refresh(); #endif } diff --git a/src/lib/object_store/Generation.cpp b/src/lib/object_store/Generation.cpp index cb858796c..f22695ea8 100644 --- a/src/lib/object_store/Generation.cpp +++ b/src/lib/object_store/Generation.cpp @@ -96,6 +96,7 @@ bool Generation::wasUpdated() if (!genFile.isValid()) { + WARNING_MSG("Generation::wasUpdated: could not open %s; assuming updated", path.c_str()); return true; } @@ -105,11 +106,13 @@ bool Generation::wasUpdated() if (!genFile.readULong(onDisk)) { + WARNING_MSG("Generation::wasUpdated: could not read %s; assuming updated", path.c_str()); return true; } if (onDisk != currentValue) { + DEBUG_MSG("Generation::wasUpdated: %s changed %lu -> %lu", path.c_str(), currentValue, onDisk); currentValue = onDisk; return true; } @@ -122,6 +125,7 @@ bool Generation::wasUpdated() if (!objectFile.isValid()) { + WARNING_MSG("Generation::wasUpdated: could not open %s; assuming updated", path.c_str()); return true; } @@ -131,9 +135,15 @@ bool Generation::wasUpdated() if (!objectFile.readULong(onDisk)) { + WARNING_MSG("Generation::wasUpdated: could not read %s; assuming updated", path.c_str()); return true; } + if (onDisk != currentValue) + { + DEBUG_MSG("Generation::wasUpdated: %s changed %lu -> %lu", path.c_str(), currentValue, onDisk); + } + return (onDisk != currentValue); } } @@ -155,6 +165,7 @@ void Generation::commit() if (!genFile.isValid()) { + WARNING_MSG("Generation::commit: could not open %s for writing", path.c_str()); return; } @@ -175,6 +186,8 @@ void Generation::commit() genFile.unlock(); + DEBUG_MSG("Generation::commit: initialized %s to %lu", path.c_str(), currentValue); + return; } @@ -202,6 +215,12 @@ void Generation::commit() currentValue = onDisk; pendingUpdate = false; + + DEBUG_MSG("Generation::commit: %s committed generation %lu", path.c_str(), currentValue); + } + else + { + WARNING_MSG("Generation::commit: failed to update %s", path.c_str()); } genFile.unlock(); diff --git a/src/lib/object_store/OSToken.cpp b/src/lib/object_store/OSToken.cpp index 7cfb3db83..aecc9f00e 100644 --- a/src/lib/object_store/OSToken.cpp +++ b/src/lib/object_store/OSToken.cpp @@ -62,7 +62,7 @@ OSToken::OSToken(const std::string inTokenPath, int inUmask) tokenMutex = MutexFactory::i()->getMutex(); valid = (gen != NULL) && (tokenMutex != NULL) && tokenDir->isValid() && tokenObject->valid; - DEBUG_MSG("Opened token %s", tokenPath.c_str()); + DEBUG_MSG("Opened token %s (valid=%d)", tokenPath.c_str(), valid); index(true); } @@ -596,9 +596,18 @@ bool OSToken::index(bool isFirstTime /* = false */) } // Check the integrity - if (!tokenDir->refresh() || !tokenObject->valid) + if (!tokenDir->refresh()) { - ERROR_MSG("Token integrity check failed"); + ERROR_MSG("Failed to refresh token directory %s", tokenPath.c_str()); + + valid = false; + + return false; + } + + if (!tokenObject->valid) + { + ERROR_MSG("Token object is not valid for %s", tokenPath.c_str()); valid = false; @@ -658,8 +667,13 @@ bool OSToken::index(bool isFirstTime /* = false */) currentFiles = newSet; - DEBUG_MSG("%d objects were added and %d objects were removed", addedFiles.size(), removedFiles.size()); - DEBUG_MSG("Current directory set contains %d objects", currentFiles.size()); + DEBUG_MSG("%zu objects were added and %zu objects were removed", addedFiles.size(), removedFiles.size()); + DEBUG_MSG("Current directory set contains %zu objects", currentFiles.size()); + + if (!removedFiles.empty()) + { + WARNING_MSG("Token %s: %zu object(s) no longer on disk", tokenPath.c_str(), removedFiles.size()); + } // Now update the set of objects @@ -709,6 +723,8 @@ bool OSToken::index(bool isFirstTime /* = false */) } else { + WARNING_MSG("Token %s: invalidating object %s (file no longer present)", + tokenPath.c_str(), fileObject->getFilename().c_str()); fileObject->invalidate(); } } @@ -716,7 +732,7 @@ bool OSToken::index(bool isFirstTime /* = false */) // Set the new objects objects = newObjects; - DEBUG_MSG("The token now contains %d objects", objects.size()); + DEBUG_MSG("The token now contains %zu objects", objects.size()); return true; } diff --git a/src/lib/object_store/ObjectFile.cpp b/src/lib/object_store/ObjectFile.cpp index 7bd743edf..d3cd9f796 100644 --- a/src/lib/object_store/ObjectFile.cpp +++ b/src/lib/object_store/ObjectFile.cpp @@ -275,6 +275,8 @@ bool ObjectFile::isValid() // been deleted. void ObjectFile::invalidate() { + DEBUG_MSG("Object %s invalidated", path.c_str()); + valid = false; discardAttributes(); @@ -678,7 +680,7 @@ void ObjectFile::store(bool isCommit /* = false */) if (!objectFile.isValid()) { - DEBUG_MSG("Cannot open object %s for writing", path.c_str()); + ERROR_MSG("Cannot open object %s for writing", path.c_str()); valid = false; @@ -693,6 +695,8 @@ void ObjectFile::store(bool isCommit /* = false */) if (!writeAttributes(objectFile)) { + ERROR_MSG("Failed to write attributes to object %s", path.c_str()); + valid = false; return; @@ -702,6 +706,8 @@ void ObjectFile::store(bool isCommit /* = false */) { if (!writeAttributes(objectFile)) { + ERROR_MSG("Failed to commit attributes to object %s", path.c_str()); + valid = false; return;