Changeset 2707 for box/trunk/bin


Ignore:
Timestamp:
27/08/2010 10:23:52 (21 months ago)
Author:
chris
Message:

Adjust numbers of files and blocks in current files during backup store
operations.

Location:
box/trunk/bin/bbstored
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbstored/BackupStoreContext.cpp

    r2535 r2707  
    9696{ 
    9797        // Make sure the store info is saved, if it has been loaded, isn't read only and has been modified 
    98         if(mpStoreInfo.get() && !(mpStoreInfo->IsReadOnly()) && mpStoreInfo->IsModified()) 
    99         { 
    100                 mpStoreInfo->Save(); 
     98        if(mapStoreInfo.get() && !(mapStoreInfo->IsReadOnly()) && 
     99                mapStoreInfo->IsModified()) 
     100        { 
     101                mapStoreInfo->Save(); 
    101102        } 
    102103} 
     
    112113void BackupStoreContext::ReceivedFinishCommand() 
    113114{ 
    114         if(!mReadOnly && mpStoreInfo.get()) 
     115        if(!mReadOnly && mapStoreInfo.get()) 
    115116        { 
    116117                // Save the store info, not delayed 
     
    176177void BackupStoreContext::LoadStoreInfo() 
    177178{ 
    178         if(mpStoreInfo.get() != 0) 
     179        if(mapStoreInfo.get() != 0) 
    179180        { 
    180181                THROW_EXCEPTION(BackupStoreException, StoreInfoAlreadyLoaded) 
     
    191192         
    192193        // Keep the pointer to it 
    193         mpStoreInfo = i; 
     194        mapStoreInfo = i; 
    194195 
    195196        BackupStoreAccountDatabase::Entry account(mClientID, mStoreDiscSet); 
     
    222223void BackupStoreContext::SaveStoreInfo(bool AllowDelay) 
    223224{ 
    224         if(mpStoreInfo.get() == 0) 
     225        if(mapStoreInfo.get() == 0) 
    225226        { 
    226227                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    242243 
    243244        // Want to save now      
    244         mpStoreInfo->Save(); 
     245        mapStoreInfo->Save(); 
    245246 
    246247        // Set count for next delay 
     
    370371int64_t BackupStoreContext::AllocateObjectID() 
    371372{ 
    372         if(mpStoreInfo.get() == 0) 
     373        if(mapStoreInfo.get() == 0) 
    373374        { 
    374375                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    384385        { 
    385386                // Attempt to allocate an ID from the store 
    386                 int64_t id = mpStoreInfo->AllocateObjectID(); 
     387                int64_t id = mapStoreInfo->AllocateObjectID(); 
    387388                 
    388389                // Generate filename 
     
    426427        bool MarkFileWithSameNameAsOldVersions) 
    427428{ 
    428         if(mpStoreInfo.get() == 0) 
     429        if(mapStoreInfo.get() == 0) 
    429430        { 
    430431                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    453454        std::string fn; 
    454455        MakeObjectFilename(id, fn, true /* make sure the directory it's in exists */); 
    455         int64_t blocksUsed = 0; 
     456        int64_t newObjectBlocksUsed = 0; 
    456457        RaidFileWrite *ppreviousVerStoreFile = 0; 
    457458        bool reversedDiffIsCompletelyDifferent = false; 
     
    461462                RaidFileWrite storeFile(mStoreDiscSet, fn); 
    462463                storeFile.Open(false /* no overwriting */); 
    463                 int64_t spaceAdjustFromDiff = 0;        // size adjustment from use of patch in old file 
     464 
     465                // size adjustment from use of patch in old file 
     466                int64_t spaceSavedByConversionToPatch = 0; 
    464467 
    465468                // Diff or full file? 
     
    541544                                 
    542545                                // And make a space adjustment for the size calculation 
    543                                 spaceAdjustFromDiff = from->GetDiscUsageInBlocks() - oldVersionNewBlocksUsed; 
     546                                spaceSavedByConversionToPatch = 
     547                                        from->GetDiscUsageInBlocks() -  
     548                                        oldVersionNewBlocksUsed; 
    544549 
    545550                                // Everything cleans up here... 
     
    554559                 
    555560                // Get the blocks used 
    556                 blocksUsed = storeFile.GetDiscUsageInBlocks(); 
     561                newObjectBlocksUsed = storeFile.GetDiscUsageInBlocks(); 
    557562                 
    558563                // Exceeds the hard limit? 
    559                 if((mpStoreInfo->GetBlocksUsed() + blocksUsed - spaceAdjustFromDiff) > mpStoreInfo->GetBlocksHardLimit()) 
     564                int64_t newBlocksUsed = mapStoreInfo->GetBlocksUsed() +  
     565                        newObjectBlocksUsed - spaceSavedByConversionToPatch; 
     566                if(newBlocksUsed > mapStoreInfo->GetBlocksHardLimit()) 
    560567                { 
    561568                        THROW_EXCEPTION(BackupStoreException, AddedFileExceedsStorageLimit) 
     
    608615                        { 
    609616                                // First, check it's not an old version (cheaper comparison) 
    610                                 if((e->GetFlags() & BackupStoreDirectory::Entry::Flags_OldVersion) == 0) 
     617                                if(! e->IsOld()) 
    611618                                { 
    612619                                        // Compare name 
     
    627634                // Then the new entry 
    628635                BackupStoreDirectory::Entry *pnewEntry = dir.AddEntry(rFilename, 
    629                                 ModificationTime, id, blocksUsed, BackupStoreDirectory::Entry::Flags_File, AttributesHash); 
     636                                ModificationTime, id, newObjectBlocksUsed, 
     637                                BackupStoreDirectory::Entry::Flags_File, 
     638                                AttributesHash); 
    630639 
    631640                // Adjust for the patch back stuff? 
     
    648657                         
    649658                        // And adjust blocks used count, for later adjustment 
    650                         blocksUsed += (oldVersionNewBlocksUsed - oldSize); 
     659                        newObjectBlocksUsed += (oldVersionNewBlocksUsed - oldSize); 
    651660                        blocksInOldFiles += (oldVersionNewBlocksUsed - oldSize); 
    652661                } 
     
    688697         
    689698        // Modify the store info 
    690         mpStoreInfo->ChangeBlocksUsed(blocksUsed); 
    691         mpStoreInfo->ChangeBlocksInOldFiles(blocksInOldFiles); 
     699 
     700        if(DiffFromFileID == 0) 
     701        { 
     702                mapStoreInfo->AdjustNumFiles(1); 
     703        } 
     704        else 
     705        { 
     706                mapStoreInfo->AdjustNumOldFiles(1); 
     707        } 
     708         
     709        mapStoreInfo->ChangeBlocksUsed(newObjectBlocksUsed); 
     710        mapStoreInfo->ChangeBlocksInCurrentFiles(newObjectBlocksUsed - 
     711                blocksInOldFiles); 
     712        mapStoreInfo->ChangeBlocksInOldFiles(blocksInOldFiles); 
    692713         
    693714        // Increment reference count on the new directory to one 
     
    696717        // Save the store info -- can cope if this exceptions because infomation 
    697718        // will be rebuilt by housekeeping, and ID allocation can recover. 
    698         SaveStoreInfo(); 
     719        SaveStoreInfo(false); 
    699720         
    700721        // Return the ID to the caller 
     
    715736{ 
    716737        // Essential checks! 
    717         if(mpStoreInfo.get() == 0) 
     738        if(mapStoreInfo.get() == 0) 
    718739        { 
    719740                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    773794                         
    774795                        // Modify the store info, and write 
    775                         mpStoreInfo->ChangeBlocksInDeletedFiles(blocksDel); 
    776                          
    777                         // Maybe postponed save of store info 
    778                         SaveStoreInfo(); 
     796                        // It definitely wasn't an old or deleted version 
     797                        mapStoreInfo->AdjustNumFiles(-1); 
     798                        mapStoreInfo->AdjustNumDeletedFiles(1); 
     799                        mapStoreInfo->ChangeBlocksInDeletedFiles(blocksDel); 
     800                         
     801                        SaveStoreInfo(false); 
    779802                } 
    780803        } 
     
    801824{ 
    802825        // Essential checks! 
    803         if(mpStoreInfo.get() == 0) 
     826        if(mapStoreInfo.get() == 0) 
    804827        { 
    805828                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    856879                         
    857880                        // Modify the store info, and write 
    858                         mpStoreInfo->ChangeBlocksInDeletedFiles(blocksDel); 
     881                        mapStoreInfo->ChangeBlocksInDeletedFiles(blocksDel); 
    859882                         
    860883                        // Maybe postponed save of store info 
     
    903926void BackupStoreContext::SaveDirectory(BackupStoreDirectory &rDir, int64_t ObjectID) 
    904927{ 
    905         if(mpStoreInfo.get() == 0) 
     928        if(mapStoreInfo.get() == 0) 
    906929        { 
    907930                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    931954                        ASSERT(dirSize > 0); 
    932955                        int64_t sizeAdjustment = dirSize - rDir.GetUserInfo1_SizeInBlocks(); 
    933                         mpStoreInfo->ChangeBlocksUsed(sizeAdjustment); 
    934                         mpStoreInfo->ChangeBlocksInDirectories(sizeAdjustment); 
     956                        mapStoreInfo->ChangeBlocksUsed(sizeAdjustment); 
     957                        mapStoreInfo->ChangeBlocksInDirectories(sizeAdjustment); 
    935958                        // Update size stored in directory 
    936959                        rDir.SetUserInfo1_SizeInBlocks(dirSize); 
     
    967990int64_t BackupStoreContext::AddDirectory(int64_t InDirectory, const BackupStoreFilename &rFilename, const StreamableMemBlock &Attributes, int64_t AttributesModTime, bool &rAlreadyExists) 
    968991{ 
    969         if(mpStoreInfo.get() == 0) 
     992        if(mapStoreInfo.get() == 0) 
    970993        { 
    971994                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    10201043                // Make sure the size of the directory is added to the usage counts in the info 
    10211044                ASSERT(dirSize > 0); 
    1022                 mpStoreInfo->ChangeBlocksUsed(dirSize); 
    1023                 mpStoreInfo->ChangeBlocksInDirectories(dirSize); 
     1045                mapStoreInfo->ChangeBlocksUsed(dirSize); 
     1046                mapStoreInfo->ChangeBlocksInDirectories(dirSize); 
    10241047                // Not added to cache, so don't set the size in the directory 
    10251048        } 
     
    10471070        } 
    10481071 
    1049         // Save the store info (may be postponed) 
    1050         SaveStoreInfo(); 
     1072        // Save the store info (may not be postponed) 
     1073        mapStoreInfo->AdjustNumDirectories(1); 
     1074        SaveStoreInfo(false); 
    10511075 
    10521076        // tell caller what the ID was 
     
    10651089{ 
    10661090        // Essential checks! 
    1067         if(mpStoreInfo.get() == 0) 
     1091        if(mapStoreInfo.get() == 0) 
    10681092        { 
    10691093                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    11241148                 
    11251149                // Update blocks deleted count 
    1126                 mpStoreInfo->ChangeBlocksInDeletedFiles(Undelete?(0 - blocksDeleted):(blocksDeleted)); 
    1127                  
    1128                 // Save store info, may be postponed 
    1129                 SaveStoreInfo(); 
     1150                mapStoreInfo->ChangeBlocksInDeletedFiles(Undelete?(0 - blocksDeleted):(blocksDeleted)); 
     1151                mapStoreInfo->AdjustNumDirectories(-1); 
     1152                SaveStoreInfo(false); 
    11301153        } 
    11311154        catch(...) 
     
    12481271void BackupStoreContext::ChangeDirAttributes(int64_t Directory, const StreamableMemBlock &Attributes, int64_t AttributesModTime) 
    12491272{ 
    1250         if(mpStoreInfo.get() == 0) 
     1273        if(mapStoreInfo.get() == 0) 
    12511274        { 
    12521275                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    12851308bool BackupStoreContext::ChangeFileAttributes(const BackupStoreFilename &rFilename, int64_t InDirectory, const StreamableMemBlock &Attributes, int64_t AttributesHash, int64_t &rObjectIDOut) 
    12861309{ 
    1287         if(mpStoreInfo.get() == 0) 
     1310        if(mapStoreInfo.get() == 0) 
    12881311        { 
    12891312                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    13501373bool BackupStoreContext::ObjectExists(int64_t ObjectID, int MustBe) 
    13511374{ 
    1352         if(mpStoreInfo.get() == 0) 
     1375        if(mapStoreInfo.get() == 0) 
    13531376        { 
    13541377                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    13581381        // because the store info may not have got saved in an error condition. Max greater ID is 
    13591382        // STORE_INFO_SAVE_DELAY in this case, *2 to be safe. 
    1360         if(ObjectID <= 0 || ObjectID > (mpStoreInfo->GetLastObjectIDUsed() + (STORE_INFO_SAVE_DELAY * 2))) 
     1383        if(ObjectID <= 0 || ObjectID > (mapStoreInfo->GetLastObjectIDUsed() + (STORE_INFO_SAVE_DELAY * 2))) 
    13611384        { 
    13621385                // Obviously bad object ID 
     
    14211444std::auto_ptr<IOStream> BackupStoreContext::OpenObject(int64_t ObjectID) 
    14221445{ 
    1423         if(mpStoreInfo.get() == 0) 
     1446        if(mapStoreInfo.get() == 0) 
    14241447        { 
    14251448                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    14431466int64_t BackupStoreContext::GetClientStoreMarker() 
    14441467{ 
    1445         if(mpStoreInfo.get() == 0) 
     1468        if(mapStoreInfo.get() == 0) 
    14461469        { 
    14471470                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
    14481471        } 
    14491472         
    1450         return mpStoreInfo->GetClientStoreMarker(); 
     1473        return mapStoreInfo->GetClientStoreMarker(); 
    14511474} 
    14521475 
     
    14621485void BackupStoreContext::GetStoreDiscUsageInfo(int64_t &rBlocksUsed, int64_t &rBlocksSoftLimit, int64_t &rBlocksHardLimit) 
    14631486{ 
    1464         if(mpStoreInfo.get() == 0) 
     1487        if(mapStoreInfo.get() == 0) 
    14651488        { 
    14661489                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
    14671490        } 
    14681491 
    1469         rBlocksUsed = mpStoreInfo->GetBlocksUsed(); 
    1470         rBlocksSoftLimit = mpStoreInfo->GetBlocksSoftLimit(); 
    1471         rBlocksHardLimit = mpStoreInfo->GetBlocksHardLimit(); 
     1492        rBlocksUsed = mapStoreInfo->GetBlocksUsed(); 
     1493        rBlocksSoftLimit = mapStoreInfo->GetBlocksSoftLimit(); 
     1494        rBlocksHardLimit = mapStoreInfo->GetBlocksHardLimit(); 
    14721495} 
    14731496 
     
    14831506bool BackupStoreContext::HardLimitExceeded() 
    14841507{ 
    1485         if(mpStoreInfo.get() == 0) 
     1508        if(mapStoreInfo.get() == 0) 
    14861509        { 
    14871510                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
    14881511        } 
    14891512 
    1490         return mpStoreInfo->GetBlocksUsed() > mpStoreInfo->GetBlocksHardLimit(); 
     1513        return mapStoreInfo->GetBlocksUsed() > mapStoreInfo->GetBlocksHardLimit(); 
    14911514} 
    14921515 
     
    15021525void BackupStoreContext::SetClientStoreMarker(int64_t ClientStoreMarker) 
    15031526{ 
    1504         if(mpStoreInfo.get() == 0) 
     1527        if(mapStoreInfo.get() == 0) 
    15051528        { 
    15061529                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     
    15111534        } 
    15121535         
    1513         mpStoreInfo->SetClientStoreMarker(ClientStoreMarker); 
     1536        mapStoreInfo->SetClientStoreMarker(ClientStoreMarker); 
    15141537        SaveStoreInfo(false /* don't delay saving this */); 
    15151538} 
     
    17711794const BackupStoreInfo &BackupStoreContext::GetBackupStoreInfo() const 
    17721795{ 
    1773         if(mpStoreInfo.get() == 0) 
     1796        if(mapStoreInfo.get() == 0) 
    17741797        { 
    17751798                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
    17761799        } 
    17771800         
    1778         return *(mpStoreInfo.get()); 
    1779 } 
    1780  
    1781  
     1801        return *(mapStoreInfo.get()); 
     1802} 
     1803 
     1804 
  • box/trunk/bin/bbstored/BackupStoreContext.h

    r2535 r2707  
    150150         
    151151        // Store info 
    152         std::auto_ptr<BackupStoreInfo> mpStoreInfo; 
     152        std::auto_ptr<BackupStoreInfo> mapStoreInfo; 
    153153 
    154154        // Refcount database 
Note: See TracChangeset for help on using the changeset viewer.