Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/lib/object_store/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}
}
}

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
Expand All @@ -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
}

19 changes: 19 additions & 0 deletions src/lib/object_store/Generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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);
}
}
Expand All @@ -155,6 +165,7 @@ void Generation::commit()

if (!genFile.isValid())
{
WARNING_MSG("Generation::commit: could not open %s for writing", path.c_str());
return;
}

Expand All @@ -175,6 +186,8 @@ void Generation::commit()

genFile.unlock();

DEBUG_MSG("Generation::commit: initialized %s to %lu", path.c_str(), currentValue);

return;
}

Expand Down Expand Up @@ -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();
Expand Down
28 changes: 22 additions & 6 deletions src/lib/object_store/OSToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -709,14 +723,16 @@ 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();
}
}

// 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;
}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/object_store/ObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ bool ObjectFile::isValid()
// been deleted.
void ObjectFile::invalidate()
{
DEBUG_MSG("Object %s invalidated", path.c_str());

valid = false;

discardAttributes();
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading