summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2011-01-12 00:13:11 +0000
committerChris Wilson <chris+github@qwirx.com>2011-01-12 00:13:11 +0000
commitafbf1bc7b1277ebfd02a7e70e93a5e27a32e47da (patch)
tree85a1787f89aadd8a54533dd2a7763d5fac7a202e /bin
parent8ee2327add953c8282807c988dcaef7a2d03a7f1 (diff)
Rate limit file uploads using the configured MaxUploadRate, if any.
Diffstat (limited to 'bin')
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.cpp78
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.h1
-rw-r--r--bin/bbackupd/BackupDaemon.cpp6
3 files changed, 60 insertions, 25 deletions
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 <string.h>
#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<BackupProtocolClientSuccess> 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<BackupProtocolClientSuccess> 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;