From afbf1bc7b1277ebfd02a7e70e93a5e27a32e47da Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 12 Jan 2011 00:13:11 +0000 Subject: Rate limit file uploads using the configured MaxUploadRate, if any. --- bin/bbackupd/BackupClientDirectoryRecord.cpp | 78 +++++++++++++++++++--------- bin/bbackupd/BackupClientDirectoryRecord.h | 1 + bin/bbackupd/BackupDaemon.cpp | 6 +++ 3 files changed, 60 insertions(+), 25 deletions(-) (limited to 'bin/bbackupd') diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp index f870365c..db6f18d3 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.cpp +++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp @@ -18,21 +18,22 @@ #include #include "autogen_BackupProtocolClient.h" -#include "BackupClientDirectoryRecord.h" +#include "Archive.h" #include "BackupClientContext.h" +#include "BackupClientDirectoryRecord.h" +#include "BackupClientInodeToIDMap.h" +#include "BackupDaemon.h" +#include "BackupStoreException.h" +#include "BackupStoreFile.h" #include "BackupStoreFileEncodeStream.h" -#include "IOStream.h" -#include "MemBlockStream.h" #include "CommonException.h" #include "CollectInBufferStream.h" -#include "BackupStoreFile.h" -#include "BackupClientInodeToIDMap.h" #include "FileModificationTime.h" -#include "BackupDaemon.h" -#include "BackupStoreException.h" -#include "Archive.h" -#include "PathUtils.h" +#include "IOStream.h" #include "Logging.h" +#include "MemBlockStream.h" +#include "PathUtils.h" +#include "RateLimitingStream.h" #include "ReadLoggingStream.h" #include "MemLeakFindOn.h" @@ -1573,11 +1574,24 @@ int64_t BackupClientDirectoryRecord::UploadFile( rContext.UnManageDiffProcess(); + RateLimitingStream rateLimit(*patchStream, + rParams.mMaxUploadRate); + IOStream* pStreamToUpload; + + if(rParams.mMaxUploadRate > 0) + { + pStreamToUpload = &rateLimit; + } + else + { + pStreamToUpload = patchStream.get(); + } + // // Upload the patch to the store // std::auto_ptr stored(connection.QueryStoreFile(mObjectID, ModificationTime, - AttributesHash, isCompletelyDifferent?(0):(diffFromID), rStoreFilename, *patchStream)); + AttributesHash, isCompletelyDifferent?(0):(diffFromID), rStoreFilename, *pStreamToUpload)); // Get object ID from the result objID = stored->GetObjectID(); @@ -1602,14 +1616,27 @@ int64_t BackupClientDirectoryRecord::UploadFile( mObjectID, rStoreFilename, NULL, &rParams, &(rParams.mrRunStatusProvider))); - + + RateLimitingStream rateLimit(*upload, + rParams.mMaxUploadRate); + IOStream* pStreamToUpload; + + if(rParams.mMaxUploadRate > 0) + { + pStreamToUpload = &rateLimit; + } + else + { + pStreamToUpload = upload.get(); + } + // Send to store std::auto_ptr stored( connection.QueryStoreFile( mObjectID, ModificationTime, AttributesHash, 0 /* no diff from file ID */, - rStoreFilename, *upload)); + rStoreFilename, *pStreamToUpload)); // Get object ID from the result objID = stored->GetObjectID(); @@ -1696,19 +1723,20 @@ BackupClientDirectoryRecord::SyncParams::SyncParams( SysadminNotifier &rSysadminNotifier, ProgressNotifier &rProgressNotifier, BackupClientContext &rContext) - : mSyncPeriodStart(0), - mSyncPeriodEnd(0), - mMaxUploadWait(0), - mMaxFileTimeInFuture(99999999999999999LL), - mFileTrackingSizeThreshold(16*1024), - mDiffingUploadSizeThreshold(16*1024), - mrRunStatusProvider(rRunStatusProvider), - mrSysadminNotifier(rSysadminNotifier), - mrProgressNotifier(rProgressNotifier), - mrContext(rContext), - mReadErrorsOnFilesystemObjects(false), - mUploadAfterThisTimeInTheFuture(99999999999999999LL), - mHaveLoggedWarningAboutFutureFileTimes(false) +: mSyncPeriodStart(0), + mSyncPeriodEnd(0), + mMaxUploadWait(0), + mMaxFileTimeInFuture(99999999999999999LL), + mFileTrackingSizeThreshold(16*1024), + mDiffingUploadSizeThreshold(16*1024), + mrRunStatusProvider(rRunStatusProvider), + mrSysadminNotifier(rSysadminNotifier), + mrProgressNotifier(rProgressNotifier), + mrContext(rContext), + mReadErrorsOnFilesystemObjects(false), + mMaxUploadRate(0), + mUploadAfterThisTimeInTheFuture(99999999999999999LL), + mHaveLoggedWarningAboutFutureFileTimes(false) { } diff --git a/bin/bbackupd/BackupClientDirectoryRecord.h b/bin/bbackupd/BackupClientDirectoryRecord.h index fce3fc04..1a03ff41 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.h +++ b/bin/bbackupd/BackupClientDirectoryRecord.h @@ -86,6 +86,7 @@ public: ProgressNotifier &mrProgressNotifier; BackupClientContext &mrContext; bool mReadErrorsOnFilesystemObjects; + int64_t mMaxUploadRate; // Member variables modified by syncing process box_time_t mUploadAfterThisTimeInTheFuture; diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index ed3861ae..ca7cdcc9 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -830,6 +830,12 @@ void BackupDaemon::RunSyncNow() conf.GetKeyValueInt("DiffingUploadSizeThreshold"); params.mMaxFileTimeInFuture = SecondsToBoxTime(conf.GetKeyValueInt("MaxFileTimeInFuture")); + + if(conf.KeyExists("MaxUploadRate")) + { + params.mMaxUploadRate = conf.GetKeyValueInt("MaxUploadRate"); + } + mDeleteRedundantLocationsAfter = conf.GetKeyValueInt("DeleteRedundantLocationsAfter"); mStorageLimitExceeded = false; -- cgit v1.2.3