Changeset 2541 for box/trunk/bin
- Timestamp:
- 28/06/2009 20:29:10 (3 years ago)
- Location:
- box/trunk/bin/bbstored
- Files:
-
- 4 edited
-
BBStoreDHousekeeping.cpp (modified) (1 diff)
-
BackupStoreDaemon.h (modified) (3 diffs)
-
HousekeepStoreAccount.cpp (modified) (11 diffs)
-
HousekeepStoreAccount.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbstored/BBStoreDHousekeeping.cpp
r2281 r2541 109 109 110 110 // Do housekeeping on this account 111 HousekeepStoreAccount housekeeping(*i, rootDir, discSet, *this); 111 HousekeepStoreAccount housekeeping(*i, rootDir, 112 discSet, this); 112 113 housekeeping.DoHousekeeping(); 113 114 } -
box/trunk/bin/bbstored/BackupStoreDaemon.h
r2262 r2541 15 15 #include "BackupConstants.h" 16 16 #include "BackupStoreContext.h" 17 #include "HousekeepStoreAccount.h" 17 18 #include "IOStreamGetLine.h" 18 19 19 20 class BackupStoreAccounts; 20 21 class BackupStoreAccountDatabase; 21 class HousekeepStoreAccount;22 22 23 23 // -------------------------------------------------------------------------- … … 30 30 // -------------------------------------------------------------------------- 31 31 class BackupStoreDaemon : public ServerTLS<BOX_PORT_BBSTORED>, 32 HousekeepingInterface 32 HousekeepingInterface, HousekeepingCallback 33 33 { 34 friend class HousekeepStoreAccount;35 36 34 public: 37 35 BackupStoreDaemon(); … … 65 63 // Housekeeping functions 66 64 void HousekeepingProcess(); 67 bool CheckForInterProcessMsg(int AccountNum = 0, int MaximumWaitTime = 0);68 65 69 66 void LogConnectionStats(const char *commonName, const SocketStreamTLS &s); 67 68 public: 69 // HousekeepingInterface implementation 70 virtual bool CheckForInterProcessMsg(int AccountNum = 0, int MaximumWaitTime = 0); 70 71 71 72 private: -
box/trunk/bin/bbstored/HousekeepStoreAccount.cpp
r2481 r2541 40 40 // 41 41 // -------------------------------------------------------------------------- 42 HousekeepStoreAccount::HousekeepStoreAccount(int AccountID, const std::string &rStoreRoot, int StoreDiscSet, BackupStoreDaemon &rDaemon) 42 HousekeepStoreAccount::HousekeepStoreAccount(int AccountID, 43 const std::string &rStoreRoot, int StoreDiscSet, 44 HousekeepingCallback* pHousekeepingCallback) 43 45 : mAccountID(AccountID), 44 46 mStoreRoot(rStoreRoot), 45 47 mStoreDiscSet(StoreDiscSet), 46 m rDaemon(rDaemon),48 mpHousekeepingCallback(pHousekeepingCallback), 47 49 mDeletionSizeTarget(0), 48 50 mPotentialDeletionsTotalSize(0), … … 58 60 mFilesDeleted(0), 59 61 mEmptyDirectoriesDeleted(0), 62 mSuppressRefCountChangeWarnings(false), 60 63 mCountUntilNextInterprocessMsgCheck(POLL_INTERPROCESS_MSG_CHECK_FREQUENCY) 61 64 { … … 82 85 // 83 86 // -------------------------------------------------------------------------- 84 void HousekeepStoreAccount::DoHousekeeping( )87 void HousekeepStoreAccount::DoHousekeeping(bool KeepTryingForever) 85 88 { 86 89 // Attempt to lock the account … … 92 95 0600 /* restrictive file permissions */)) 93 96 { 94 // Couldn't lock the account -- just stop now 95 return; 97 if(KeepTryingForever) 98 { 99 BOX_WARNING("Failed to lock account for housekeeping, " 100 "still trying..."); 101 while(!writeLock.TryAndGetLock(writeLockFilename, 102 0600 /* restrictive file permissions */)) 103 { 104 sleep(1); 105 } 106 } 107 else 108 { 109 // Couldn't lock the account -- just stop now 110 return; 111 } 96 112 } 97 113 … … 106 122 mDeletionSizeTarget = 0; 107 123 } 124 125 // initialise the refcount database 126 mNewRefCounts.clear(); 127 // try to pre-allocate as much memory as we need 128 mNewRefCounts.reserve(info->GetLastObjectIDUsed()); 129 // initialise the refcount of the root entry 130 mNewRefCounts.resize(BACKUPSTORE_ROOT_DIRECTORY_ID + 1, 0); 131 mNewRefCounts[BACKUPSTORE_ROOT_DIRECTORY_ID] = 1; 108 132 109 133 // Scan the directory for potential things to delete … … 208 232 (deleteInterrupted?" and was interrupted":"")); 209 233 } 234 235 // We can only update the refcount database if we successfully 236 // finished our scan of all directories, otherwise we don't actually 237 // know which of the new counts are valid and which aren't 238 // (we might not have seen second references to some objects, etc.) 239 240 BackupStoreAccountDatabase::Entry account(mAccountID, mStoreDiscSet); 241 std::auto_ptr<BackupStoreRefCountDatabase> apReferences; 242 243 // try to load the reference count database 244 try 245 { 246 apReferences = BackupStoreRefCountDatabase::Load(account, 247 false); 248 } 249 catch(BoxException &e) 250 { 251 BOX_WARNING("Reference count database is missing or corrupted " 252 "during housekeeping, creating a new one."); 253 mSuppressRefCountChangeWarnings = true; 254 BackupStoreRefCountDatabase::CreateForRegeneration(account); 255 apReferences = BackupStoreRefCountDatabase::Load(account, 256 false); 257 } 258 259 int64_t LastUsedObjectIdOnDisk = apReferences->GetLastObjectIDUsed(); 260 261 for (int64_t ObjectID = BACKUPSTORE_ROOT_DIRECTORY_ID; 262 ObjectID < mNewRefCounts.size(); ObjectID++) 263 { 264 if (ObjectID > LastUsedObjectIdOnDisk) 265 { 266 if (!mSuppressRefCountChangeWarnings) 267 { 268 BOX_WARNING("Reference count of object " << 269 BOX_FORMAT_OBJECTID(ObjectID) << 270 " not found in database, added" 271 " with " << mNewRefCounts[ObjectID] << 272 " references"); 273 } 274 apReferences->SetRefCount(ObjectID, 275 mNewRefCounts[ObjectID]); 276 LastUsedObjectIdOnDisk = ObjectID; 277 continue; 278 } 279 280 BackupStoreRefCountDatabase::refcount_t OldRefCount = 281 apReferences->GetRefCount(ObjectID); 282 283 if (OldRefCount != mNewRefCounts[ObjectID]) 284 { 285 BOX_WARNING("Reference count of object " << 286 BOX_FORMAT_OBJECTID(ObjectID) << 287 " changed from " << OldRefCount << 288 " to " << mNewRefCounts[ObjectID]); 289 apReferences->SetRefCount(ObjectID, 290 mNewRefCounts[ObjectID]); 291 } 292 } 293 294 // zero excess references in the database 295 for (int64_t ObjectID = mNewRefCounts.size(); 296 ObjectID <= LastUsedObjectIdOnDisk; ObjectID++) 297 { 298 BackupStoreRefCountDatabase::refcount_t OldRefCount = 299 apReferences->GetRefCount(ObjectID); 300 BackupStoreRefCountDatabase::refcount_t NewRefCount = 0; 301 302 if (OldRefCount != NewRefCount) 303 { 304 BOX_WARNING("Reference count of object " << 305 BOX_FORMAT_OBJECTID(ObjectID) << 306 " changed from " << OldRefCount << 307 " to " << NewRefCount << " (not found)"); 308 apReferences->SetRefCount(ObjectID, NewRefCount); 309 } 310 } 311 312 // force file to be saved and closed before releasing the lock below 313 apReferences.reset(); 210 314 211 315 // Make sure the delta's won't cause problems if the counts are … … 280 384 // Check for having to stop 281 385 // Include account ID here as the specified account is locked 282 if(m rDaemon.CheckForInterProcessMsg(mAccountID))386 if(mpHousekeepingCallback && mpHousekeepingCallback->CheckForInterProcessMsg(mAccountID)) 283 387 { 284 388 // Need to abort now … … 360 464 while((en = i.Next(BackupStoreDirectory::Entry::Flags_File)) != 0) 361 465 { 466 // This directory references this object 467 if (mNewRefCounts.size() <= en->GetObjectID()) 468 { 469 mNewRefCounts.resize(en->GetObjectID() + 1, 0); 470 } 471 mNewRefCounts[en->GetObjectID()]++; 472 362 473 // Update recalculated usage sizes 363 474 int16_t enFlags = en->GetFlags(); … … 468 579 while((en = i.Next(BackupStoreDirectory::Entry::Flags_Dir)) != 0) 469 580 { 581 // This parent directory references this child 582 if (mNewRefCounts.size() <= en->GetObjectID()) 583 { 584 mNewRefCounts.resize(en->GetObjectID() + 1, 0); 585 } 586 mNewRefCounts[en->GetObjectID()]++; 587 470 588 // Next level 471 589 ASSERT((en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) == BackupStoreDirectory::Entry::Flags_Dir); … … 552 670 mCountUntilNextInterprocessMsgCheck = POLL_INTERPROCESS_MSG_CHECK_FREQUENCY; 553 671 // Check for having to stop 554 if(m rDaemon.CheckForInterProcessMsg(mAccountID)) // include account ID here as the specified account is now locked672 if(mpHousekeepingCallback && mpHousekeepingCallback->CheckForInterProcessMsg(mAccountID)) // include account ID here as the specified account is now locked 555 673 { 556 674 // Need to abort now … … 809 927 mCountUntilNextInterprocessMsgCheck = POLL_INTERPROCESS_MSG_CHECK_FREQUENCY; 810 928 // Check for having to stop 811 if(m rDaemon.CheckForInterProcessMsg(mAccountID)) // include account ID here as the specified account is now locked929 if(mpHousekeepingCallback && mpHousekeepingCallback->CheckForInterProcessMsg(mAccountID)) // include account ID here as the specified account is now locked 812 930 { 813 931 // Need to abort now -
box/trunk/bin/bbstored/HousekeepStoreAccount.h
r2176 r2541 18 18 class BackupStoreDirectory; 19 19 20 class HousekeepingCallback 21 { 22 public: 23 virtual ~HousekeepingCallback() {} 24 virtual bool CheckForInterProcessMsg(int AccountNum = 0, int MaximumWaitTime = 0) = 0; 25 }; 20 26 21 27 // -------------------------------------------------------------------------- … … 30 36 { 31 37 public: 32 HousekeepStoreAccount(int AccountID, const std::string &rStoreRoot, int StoreDiscSet, BackupStoreDaemon &rDaemon); 38 HousekeepStoreAccount(int AccountID, const std::string &rStoreRoot, 39 int StoreDiscSet, HousekeepingCallback* pHousekeepingCallback); 33 40 ~HousekeepStoreAccount(); 34 41 35 void DoHousekeeping( );42 void DoHousekeeping(bool KeepTryingForever = false); 36 43 37 44 … … 66 73 std::string mStoreRoot; 67 74 int mStoreDiscSet; 68 BackupStoreDaemon &mrDaemon;75 HousekeepingCallback* mpHousekeepingCallback; 69 76 70 77 int64_t mDeletionSizeTarget; … … 92 99 int64_t mFilesDeleted; 93 100 int64_t mEmptyDirectoriesDeleted; 101 102 // New reference count list 103 std::vector<uint32_t> mNewRefCounts; 104 bool mSuppressRefCountChangeWarnings; 94 105 95 106 // Poll frequency
Note: See TracChangeset
for help on using the changeset viewer.
