Skip to content

Commit

Permalink
Refactor out counting of files/blocks by directory entry
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed May 19, 2018
1 parent f020e15 commit b621edc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 43 deletions.
99 changes: 56 additions & 43 deletions lib/backupstore/BackupStoreCheck.cpp
Expand Up @@ -383,13 +383,6 @@ object_exists_t BackupStoreCheck::CheckAndAddObject(int64_t ObjectID)
int64_t size = mrFileSystem.GetFileSizeInBlocks(ObjectID);
AddID(ObjectID, containerID, size, isFile);

// Add to usage counts
mBlocksUsed += size;
if(!isFile)
{
mBlocksInDirectories += size;
}

// If it looks like a good object, and it's non-RAID, and
// this is a RAID set, then convert it to RAID.
mrFileSystem.EnsureObjectIsPermanent(ObjectID, mFixErrors);
Expand Down Expand Up @@ -480,11 +473,6 @@ void BackupStoreCheck::CheckDirectories()
// This phase will check all the files in the directories, make
// a note of all directories which are missing, and do initial fixing.

// The root directory is not contained inside another directory, so
// it has no directory entry to scan, but we have to count it
// somewhere, so we'll count it here.
mNumDirectories++;

// Scan all objects.
for(Info_t::const_iterator i(mInfo.begin()); i != mInfo.end(); ++i)
{
Expand Down Expand Up @@ -528,6 +516,16 @@ void BackupStoreCheck::CheckDirectories()
mrFileSystem.PutDirectory(dir);
}

// The root directory is not contained inside another directory, so
// it has no directory entry to scan, but we have to count it
// somewhere, so we'll count it here.
if(pblock->mID[e] == BACKUPSTORE_ROOT_DIRECTORY_ID)
{
mNumDirectories++;
mBlocksUsed += dir.GetUserInfo1_SizeInBlocks();
mBlocksInDirectories += dir.GetUserInfo1_SizeInBlocks();
}

CountDirectoryEntries(dir);
}
}
Expand Down Expand Up @@ -650,45 +648,60 @@ void BackupStoreCheck::CountDirectoryEntries(BackupStoreDirectory& dir)
// don't double-count objects that are
// contained by another directory as well.
}
else if(en->IsDir())
else
{
mNumDirectories++;
CountDirectoryEntry(en->GetObjectID(), en->GetFlags(),
en->GetSizeInBlocks());
}
else if(!en->IsFile())
}
}

void BackupStoreCheck::CountDirectoryEntry(int64_t object_id, int16_t flags, int64_t size,
bool subtract)
{
int sense = subtract ? -1 : 1;
mBlocksUsed += size * sense;

if(flags & BackupStoreDirectory::Entry::Flags_Dir)
{
mNumDirectories += sense;
mBlocksInDirectories += size * sense;
}
else if(!(flags & BackupStoreDirectory::Entry::Flags_File))
{
BOX_WARNING("Not counting object " << BOX_FORMAT_OBJECTID(object_id) <<
" with flags " << flags);
}
else // it's a file
{
// It can be both old and deleted. If neither, then it's current.
if(flags & BackupStoreDirectory::Entry::Flags_Deleted)
{
BOX_TRACE("Not counting object " <<
BOX_FORMAT_OBJECTID(en->GetObjectID()) <<
" with flags " << en->GetFlags());
mNumDeletedFiles += sense;
mBlocksInDeletedFiles += size * sense;
}
else // it's a file
{
// Add to sizes?
// If piBlock was zero, then wasAlreadyContained
// might be uninitialized.
ASSERT(piBlock != NULL)

// It can be both old and deleted.
// If neither, then it's current.
if(en->IsDeleted())
{
mNumDeletedFiles++;
mBlocksInDeletedFiles += en->GetSizeInBlocks();
}

if(en->IsOld())
{
mNumOldFiles++;
mBlocksInOldFiles += en->GetSizeInBlocks();
}
if(flags & BackupStoreDirectory::Entry::Flags_OldVersion)
{
mNumOldFiles += sense;
mBlocksInOldFiles += size * sense;
}

if(!en->IsDeleted() && !en->IsOld())
{
mNumCurrentFiles++;
mBlocksInCurrentFiles += en->GetSizeInBlocks();
}
if((flags & (BackupStoreDirectory::Entry::Flags_Deleted |
BackupStoreDirectory::Entry::Flags_OldVersion)) == 0)
{
mNumCurrentFiles += sense;
mBlocksInCurrentFiles += size * sense;
}
}

mpNewRefs->AddReference(en->GetObjectID());
if(subtract)
{
mpNewRefs->RemoveReference(object_id);
}
else
{
mpNewRefs->AddReference(object_id);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/backupstore/BackupStoreCheck.h
Expand Up @@ -133,6 +133,8 @@ class BackupStoreCheck
bool CheckDirectoryEntry(BackupStoreDirectory::Entry& rEntry,
int64_t DirectoryID, bool& rIsModified);
void CountDirectoryEntries(BackupStoreDirectory& dir);
void CountDirectoryEntry(int64_t object_id, int16_t flags, int64_t size,
bool subtract = false);
int64_t CheckFile(int64_t ObjectID, IOStream &rStream);
int64_t CheckDirInitial(int64_t ObjectID, IOStream &rStream);

Expand Down

0 comments on commit b621edc

Please sign in to comment.