diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-04-09 22:15:57 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-04-09 22:15:57 +0000 |
commit | dc4ba0969146c6c4a82b1dace6bd9b11b818bcc9 (patch) | |
tree | f29918fdcab9a801685ebe6a6a7b5446c9cc69ba /bin | |
parent | 06af9253bc5df053dbe2208cbc724853294020a3 (diff) |
Poll command socket regularly during file uploads.
Makes the daemon responsive to polling and commands, even during a file
upload operation.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/bbackupd/BackupClientDirectoryRecord.cpp | 12 | ||||
-rw-r--r-- | bin/bbackupd/BackupClientDirectoryRecord.h | 5 | ||||
-rw-r--r-- | bin/bbackupd/BackupDaemon.cpp | 53 | ||||
-rw-r--r-- | bin/bbackupd/BackupDaemon.h | 16 | ||||
-rw-r--r-- | bin/bbackupquery/BackupQueries.h | 2 |
5 files changed, 79 insertions, 9 deletions
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp index f2f1f455..4a7eb5a5 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.cpp +++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp @@ -1707,7 +1707,8 @@ int64_t BackupClientDirectoryRecord::UploadFile( connection.GetTimeout(), &rContext, // DiffTimer implementation 0 /* not interested in the modification time */, - &isCompletelyDifferent); + &isCompletelyDifferent, + rParams.mpBackgroundTask); if(isCompletelyDifferent) { @@ -1727,7 +1728,8 @@ int64_t BackupClientDirectoryRecord::UploadFile( apStreamToUpload = BackupStoreFile::EncodeFile( rFilename, mObjectID, /* containing directory */ rStoreFilename, NULL, &rParams, - &(rParams.mrRunStatusProvider)); + &(rParams.mrRunStatusProvider), + rParams.mpBackgroundTask); } rContext.SetNiceMode(true); @@ -1842,7 +1844,8 @@ BackupClientDirectoryRecord::SyncParams::SyncParams( RunStatusProvider &rRunStatusProvider, SysadminNotifier &rSysadminNotifier, ProgressNotifier &rProgressNotifier, - BackupClientContext &rContext) + BackupClientContext &rContext, + BackgroundTask *pBackgroundTask) : mSyncPeriodStart(0), mSyncPeriodEnd(0), mMaxUploadWait(0), @@ -1856,7 +1859,8 @@ BackupClientDirectoryRecord::SyncParams::SyncParams( mReadErrorsOnFilesystemObjects(false), mMaxUploadRate(0), mUploadAfterThisTimeInTheFuture(99999999999999999LL), - mHaveLoggedWarningAboutFutureFileTimes(false) + mHaveLoggedWarningAboutFutureFileTimes(false), + mpBackgroundTask(pBackgroundTask) { } diff --git a/bin/bbackupd/BackupClientDirectoryRecord.h b/bin/bbackupd/BackupClientDirectoryRecord.h index 79eed587..ec0ec86b 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.h +++ b/bin/bbackupd/BackupClientDirectoryRecord.h @@ -14,6 +14,7 @@ #include <map> #include <memory> +#include "BackgroundTask.h" #include "BackupClientFileAttributes.h" #include "BackupDaemonInterface.h" #include "BackupStoreDirectory.h" @@ -76,7 +77,8 @@ public: RunStatusProvider &rRunStatusProvider, SysadminNotifier &rSysadminNotifier, ProgressNotifier &rProgressNotifier, - BackupClientContext &rContext); + BackupClientContext &rContext, + BackgroundTask *pBackgroundTask); ~SyncParams(); private: // No copying @@ -91,6 +93,7 @@ public: box_time_t mMaxFileTimeInFuture; int32_t mFileTrackingSizeThreshold; int32_t mDiffingUploadSizeThreshold; + BackgroundTask *mpBackgroundTask; RunStatusProvider &mrRunStatusProvider; SysadminNotifier &mrSysadminNotifier; ProgressNotifier &mrProgressNotifier; diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index dc494100..a31ae7cd 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -202,7 +202,8 @@ BackupDaemon::BackupDaemon() mpProgressNotifier(this), mpLocationResolver(this), mpRunStatusProvider(this), - mpSysadminNotifier(this) + mpSysadminNotifier(this), + mapCommandSocketPollTimer(NULL) #ifdef WIN32 , mInstallService(false), mRemoveService(false), @@ -442,6 +443,9 @@ void BackupDaemon::Run() // initialise global timer mechanism Timers::Init(); + mapCommandSocketPollTimer.reset(new Timer(COMMAND_SOCKET_POLL_INTERVAL, + "CommandSocketPollTimer")); + #ifndef WIN32 // Ignore SIGPIPE so that if a command connection is broken, // the daemon doesn't terminate. @@ -926,7 +930,7 @@ void BackupDaemon::RunSyncNow() // Set up the sync parameters BackupClientDirectoryRecord::SyncParams params(*mpRunStatusProvider, - *mpSysadminNotifier, *mpProgressNotifier, clientContext); + *mpSysadminNotifier, *mpProgressNotifier, clientContext, this); params.mSyncPeriodStart = syncPeriodStart; params.mSyncPeriodEnd = syncPeriodEndExtended; // use potentially extended end time @@ -1844,6 +1848,51 @@ int BackupDaemon::ParseSyncAllowScriptOutput(const std::string& script, // -------------------------------------------------------------------------- // // Function +// Name: BackupDaemon::RunBackgroundTask() +// Purpose: Checks for connections or commands on the command +// socket and handles them with minimal delay. Polled +// during lengthy operations such as file uploads. +// Created: 07/04/14 +// +// -------------------------------------------------------------------------- +bool BackupDaemon::RunBackgroundTask(State state, uint64_t progress, + uint64_t maximum) +{ + BOX_TRACE("BackupDaemon::RunBackgroundTask: state = " << state << + ", progress = " << progress << "/" << maximum); + + if(mapCommandSocketPollTimer->HasExpired()) + { + mapCommandSocketPollTimer->Reset(COMMAND_SOCKET_POLL_INTERVAL); + } + else + { + // Do no more work right now + return true; + } + + if(mapCommandSocketInfo.get()) + { + BOX_TRACE("BackupDaemon::RunBackgroundTask: polling command socket"); + + bool sync_flag_out, sync_is_forced_out; + + WaitOnCommandSocket(0, // RequiredDelay + sync_flag_out, sync_is_forced_out); + + if(sync_flag_out) + { + BOX_WARNING("Ignoring request to sync while " + "already syncing."); + } + } + + return true; +} + +// -------------------------------------------------------------------------- +// +// Function // Name: BackupDaemon::WaitOnCommandSocket(box_time_t, bool &, bool &) // Purpose: Waits on a the command socket for a time of UP TO the required time // but may be much less, and handles a command if necessary. diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h index 1d3c991e..5a811f7e 100644 --- a/bin/bbackupd/BackupDaemon.h +++ b/bin/bbackupd/BackupDaemon.h @@ -25,6 +25,7 @@ #include "TLSContext.h" #include "autogen_BackupProtocol.h" +#include "autogen_BackupStoreException.h" #ifdef WIN32 #include "WinNamedPipeListener.h" @@ -38,6 +39,8 @@ # include <VsBackup.h> #endif +#define COMMAND_SOCKET_POLL_INTERVAL 1000 + class BackupClientDirectoryRecord; class BackupClientContext; class Configuration; @@ -55,7 +58,7 @@ class Archive; // // -------------------------------------------------------------------------- class BackupDaemon : public Daemon, ProgressNotifier, LocationResolver, -RunStatusProvider, SysadminNotifier +RunStatusProvider, SysadminNotifier, BackgroundTask { public: BackupDaemon(); @@ -232,12 +235,15 @@ public: void SetLocationResolver (LocationResolver* p) { mpLocationResolver = p; } void SetRunStatusProvider(RunStatusProvider* p) { mpRunStatusProvider = p; } void SetSysadminNotifier (SysadminNotifier* p) { mpSysadminNotifier = p; } + virtual bool RunBackgroundTask(State state, uint64_t progress, + uint64_t maximum); private: ProgressNotifier* mpProgressNotifier; LocationResolver* mpLocationResolver; RunStatusProvider* mpRunStatusProvider; SysadminNotifier* mpSysadminNotifier; + std::auto_ptr<Timer> mapCommandSocketPollTimer; /* ProgressNotifier implementation */ public: @@ -250,7 +256,13 @@ public: if (mLogAllFileAccess) { BOX_INFO("Scanning directory: " << rLocalPath); - } + } + + if (!RunBackgroundTask(BackgroundTask::Scanning_Dirs, 0, 0)) + { + THROW_EXCEPTION(BackupStoreException, + CancelledByBackgroundTask); + } } virtual void NotifyDirStatFailed( const BackupClientDirectoryRecord* pDirRecord, diff --git a/bin/bbackupquery/BackupQueries.h b/bin/bbackupquery/BackupQueries.h index 82fc7bed..bad1a39c 100644 --- a/bin/bbackupquery/BackupQueries.h +++ b/bin/bbackupquery/BackupQueries.h @@ -272,6 +272,7 @@ public: virtual void NotifyDirComparing(const std::string& rLocalPath, const std::string& rRemotePath) { + BOX_INFO("Comparing directory: " << rLocalPath); } virtual void NotifyDirCompared( @@ -303,6 +304,7 @@ public: virtual void NotifyFileComparing(const std::string& rLocalPath, const std::string& rRemotePath) { + BOX_TRACE("Comparing file: " << rLocalPath); } virtual void NotifyFileCompared(const std::string& rLocalPath, |