Changeset 2707 for box/trunk/bin
- Timestamp:
- 27/08/2010 10:23:52 (21 months ago)
- Location:
- box/trunk/bin/bbstored
- Files:
-
- 2 edited
-
BackupStoreContext.cpp (modified) (40 diffs)
-
BackupStoreContext.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbstored/BackupStoreContext.cpp
r2535 r2707 96 96 { 97 97 // 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(); 101 102 } 102 103 } … … 112 113 void BackupStoreContext::ReceivedFinishCommand() 113 114 { 114 if(!mReadOnly && m pStoreInfo.get())115 if(!mReadOnly && mapStoreInfo.get()) 115 116 { 116 117 // Save the store info, not delayed … … 176 177 void BackupStoreContext::LoadStoreInfo() 177 178 { 178 if(m pStoreInfo.get() != 0)179 if(mapStoreInfo.get() != 0) 179 180 { 180 181 THROW_EXCEPTION(BackupStoreException, StoreInfoAlreadyLoaded) … … 191 192 192 193 // Keep the pointer to it 193 m pStoreInfo = i;194 mapStoreInfo = i; 194 195 195 196 BackupStoreAccountDatabase::Entry account(mClientID, mStoreDiscSet); … … 222 223 void BackupStoreContext::SaveStoreInfo(bool AllowDelay) 223 224 { 224 if(m pStoreInfo.get() == 0)225 if(mapStoreInfo.get() == 0) 225 226 { 226 227 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 242 243 243 244 // Want to save now 244 m pStoreInfo->Save();245 mapStoreInfo->Save(); 245 246 246 247 // Set count for next delay … … 370 371 int64_t BackupStoreContext::AllocateObjectID() 371 372 { 372 if(m pStoreInfo.get() == 0)373 if(mapStoreInfo.get() == 0) 373 374 { 374 375 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 384 385 { 385 386 // Attempt to allocate an ID from the store 386 int64_t id = m pStoreInfo->AllocateObjectID();387 int64_t id = mapStoreInfo->AllocateObjectID(); 387 388 388 389 // Generate filename … … 426 427 bool MarkFileWithSameNameAsOldVersions) 427 428 { 428 if(m pStoreInfo.get() == 0)429 if(mapStoreInfo.get() == 0) 429 430 { 430 431 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 453 454 std::string fn; 454 455 MakeObjectFilename(id, fn, true /* make sure the directory it's in exists */); 455 int64_t blocksUsed = 0;456 int64_t newObjectBlocksUsed = 0; 456 457 RaidFileWrite *ppreviousVerStoreFile = 0; 457 458 bool reversedDiffIsCompletelyDifferent = false; … … 461 462 RaidFileWrite storeFile(mStoreDiscSet, fn); 462 463 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; 464 467 465 468 // Diff or full file? … … 541 544 542 545 // And make a space adjustment for the size calculation 543 spaceAdjustFromDiff = from->GetDiscUsageInBlocks() - oldVersionNewBlocksUsed; 546 spaceSavedByConversionToPatch = 547 from->GetDiscUsageInBlocks() - 548 oldVersionNewBlocksUsed; 544 549 545 550 // Everything cleans up here... … … 554 559 555 560 // Get the blocks used 556 blocksUsed = storeFile.GetDiscUsageInBlocks();561 newObjectBlocksUsed = storeFile.GetDiscUsageInBlocks(); 557 562 558 563 // 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()) 560 567 { 561 568 THROW_EXCEPTION(BackupStoreException, AddedFileExceedsStorageLimit) … … 608 615 { 609 616 // First, check it's not an old version (cheaper comparison) 610 if( (e->GetFlags() & BackupStoreDirectory::Entry::Flags_OldVersion) == 0)617 if(! e->IsOld()) 611 618 { 612 619 // Compare name … … 627 634 // Then the new entry 628 635 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); 630 639 631 640 // Adjust for the patch back stuff? … … 648 657 649 658 // And adjust blocks used count, for later adjustment 650 blocksUsed += (oldVersionNewBlocksUsed - oldSize);659 newObjectBlocksUsed += (oldVersionNewBlocksUsed - oldSize); 651 660 blocksInOldFiles += (oldVersionNewBlocksUsed - oldSize); 652 661 } … … 688 697 689 698 // 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); 692 713 693 714 // Increment reference count on the new directory to one … … 696 717 // Save the store info -- can cope if this exceptions because infomation 697 718 // will be rebuilt by housekeeping, and ID allocation can recover. 698 SaveStoreInfo( );719 SaveStoreInfo(false); 699 720 700 721 // Return the ID to the caller … … 715 736 { 716 737 // Essential checks! 717 if(m pStoreInfo.get() == 0)738 if(mapStoreInfo.get() == 0) 718 739 { 719 740 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 773 794 774 795 // 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); 779 802 } 780 803 } … … 801 824 { 802 825 // Essential checks! 803 if(m pStoreInfo.get() == 0)826 if(mapStoreInfo.get() == 0) 804 827 { 805 828 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 856 879 857 880 // Modify the store info, and write 858 m pStoreInfo->ChangeBlocksInDeletedFiles(blocksDel);881 mapStoreInfo->ChangeBlocksInDeletedFiles(blocksDel); 859 882 860 883 // Maybe postponed save of store info … … 903 926 void BackupStoreContext::SaveDirectory(BackupStoreDirectory &rDir, int64_t ObjectID) 904 927 { 905 if(m pStoreInfo.get() == 0)928 if(mapStoreInfo.get() == 0) 906 929 { 907 930 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 931 954 ASSERT(dirSize > 0); 932 955 int64_t sizeAdjustment = dirSize - rDir.GetUserInfo1_SizeInBlocks(); 933 m pStoreInfo->ChangeBlocksUsed(sizeAdjustment);934 m pStoreInfo->ChangeBlocksInDirectories(sizeAdjustment);956 mapStoreInfo->ChangeBlocksUsed(sizeAdjustment); 957 mapStoreInfo->ChangeBlocksInDirectories(sizeAdjustment); 935 958 // Update size stored in directory 936 959 rDir.SetUserInfo1_SizeInBlocks(dirSize); … … 967 990 int64_t BackupStoreContext::AddDirectory(int64_t InDirectory, const BackupStoreFilename &rFilename, const StreamableMemBlock &Attributes, int64_t AttributesModTime, bool &rAlreadyExists) 968 991 { 969 if(m pStoreInfo.get() == 0)992 if(mapStoreInfo.get() == 0) 970 993 { 971 994 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1020 1043 // Make sure the size of the directory is added to the usage counts in the info 1021 1044 ASSERT(dirSize > 0); 1022 m pStoreInfo->ChangeBlocksUsed(dirSize);1023 m pStoreInfo->ChangeBlocksInDirectories(dirSize);1045 mapStoreInfo->ChangeBlocksUsed(dirSize); 1046 mapStoreInfo->ChangeBlocksInDirectories(dirSize); 1024 1047 // Not added to cache, so don't set the size in the directory 1025 1048 } … … 1047 1070 } 1048 1071 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); 1051 1075 1052 1076 // tell caller what the ID was … … 1065 1089 { 1066 1090 // Essential checks! 1067 if(m pStoreInfo.get() == 0)1091 if(mapStoreInfo.get() == 0) 1068 1092 { 1069 1093 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1124 1148 1125 1149 // 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); 1130 1153 } 1131 1154 catch(...) … … 1248 1271 void BackupStoreContext::ChangeDirAttributes(int64_t Directory, const StreamableMemBlock &Attributes, int64_t AttributesModTime) 1249 1272 { 1250 if(m pStoreInfo.get() == 0)1273 if(mapStoreInfo.get() == 0) 1251 1274 { 1252 1275 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1285 1308 bool BackupStoreContext::ChangeFileAttributes(const BackupStoreFilename &rFilename, int64_t InDirectory, const StreamableMemBlock &Attributes, int64_t AttributesHash, int64_t &rObjectIDOut) 1286 1309 { 1287 if(m pStoreInfo.get() == 0)1310 if(mapStoreInfo.get() == 0) 1288 1311 { 1289 1312 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1350 1373 bool BackupStoreContext::ObjectExists(int64_t ObjectID, int MustBe) 1351 1374 { 1352 if(m pStoreInfo.get() == 0)1375 if(mapStoreInfo.get() == 0) 1353 1376 { 1354 1377 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1358 1381 // because the store info may not have got saved in an error condition. Max greater ID is 1359 1382 // STORE_INFO_SAVE_DELAY in this case, *2 to be safe. 1360 if(ObjectID <= 0 || ObjectID > (m pStoreInfo->GetLastObjectIDUsed() + (STORE_INFO_SAVE_DELAY * 2)))1383 if(ObjectID <= 0 || ObjectID > (mapStoreInfo->GetLastObjectIDUsed() + (STORE_INFO_SAVE_DELAY * 2))) 1361 1384 { 1362 1385 // Obviously bad object ID … … 1421 1444 std::auto_ptr<IOStream> BackupStoreContext::OpenObject(int64_t ObjectID) 1422 1445 { 1423 if(m pStoreInfo.get() == 0)1446 if(mapStoreInfo.get() == 0) 1424 1447 { 1425 1448 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1443 1466 int64_t BackupStoreContext::GetClientStoreMarker() 1444 1467 { 1445 if(m pStoreInfo.get() == 0)1468 if(mapStoreInfo.get() == 0) 1446 1469 { 1447 1470 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 1448 1471 } 1449 1472 1450 return m pStoreInfo->GetClientStoreMarker();1473 return mapStoreInfo->GetClientStoreMarker(); 1451 1474 } 1452 1475 … … 1462 1485 void BackupStoreContext::GetStoreDiscUsageInfo(int64_t &rBlocksUsed, int64_t &rBlocksSoftLimit, int64_t &rBlocksHardLimit) 1463 1486 { 1464 if(m pStoreInfo.get() == 0)1487 if(mapStoreInfo.get() == 0) 1465 1488 { 1466 1489 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 1467 1490 } 1468 1491 1469 rBlocksUsed = m pStoreInfo->GetBlocksUsed();1470 rBlocksSoftLimit = m pStoreInfo->GetBlocksSoftLimit();1471 rBlocksHardLimit = m pStoreInfo->GetBlocksHardLimit();1492 rBlocksUsed = mapStoreInfo->GetBlocksUsed(); 1493 rBlocksSoftLimit = mapStoreInfo->GetBlocksSoftLimit(); 1494 rBlocksHardLimit = mapStoreInfo->GetBlocksHardLimit(); 1472 1495 } 1473 1496 … … 1483 1506 bool BackupStoreContext::HardLimitExceeded() 1484 1507 { 1485 if(m pStoreInfo.get() == 0)1508 if(mapStoreInfo.get() == 0) 1486 1509 { 1487 1510 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 1488 1511 } 1489 1512 1490 return m pStoreInfo->GetBlocksUsed() > mpStoreInfo->GetBlocksHardLimit();1513 return mapStoreInfo->GetBlocksUsed() > mapStoreInfo->GetBlocksHardLimit(); 1491 1514 } 1492 1515 … … 1502 1525 void BackupStoreContext::SetClientStoreMarker(int64_t ClientStoreMarker) 1503 1526 { 1504 if(m pStoreInfo.get() == 0)1527 if(mapStoreInfo.get() == 0) 1505 1528 { 1506 1529 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) … … 1511 1534 } 1512 1535 1513 m pStoreInfo->SetClientStoreMarker(ClientStoreMarker);1536 mapStoreInfo->SetClientStoreMarker(ClientStoreMarker); 1514 1537 SaveStoreInfo(false /* don't delay saving this */); 1515 1538 } … … 1771 1794 const BackupStoreInfo &BackupStoreContext::GetBackupStoreInfo() const 1772 1795 { 1773 if(m pStoreInfo.get() == 0)1796 if(mapStoreInfo.get() == 0) 1774 1797 { 1775 1798 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 1776 1799 } 1777 1800 1778 return *(m pStoreInfo.get());1779 } 1780 1781 1801 return *(mapStoreInfo.get()); 1802 } 1803 1804 -
box/trunk/bin/bbstored/BackupStoreContext.h
r2535 r2707 150 150 151 151 // Store info 152 std::auto_ptr<BackupStoreInfo> m pStoreInfo;152 std::auto_ptr<BackupStoreInfo> mapStoreInfo; 153 153 154 154 // Refcount database
Note: See TracChangeset
for help on using the changeset viewer.
