[Box Backup-commit] COMMIT r3382 - box/trunk/bin/bbackupd

subversion at boxbackup.org subversion at boxbackup.org
Thu Sep 4 02:36:23 BST 2014


Author: chris
Date: 2014-09-04 02:36:23 +0100 (Thu, 04 Sep 2014)
New Revision: 3382

Modified:
   box/trunk/bin/bbackupd/BackupClientContext.cpp
   box/trunk/bin/bbackupd/BackupDaemon.cpp
   box/trunk/bin/bbackupd/BackupDaemon.h
Log:
Allow access to BackupDaemon's BackupClientContext for tests.

The std::auto_ptr is now returned unclosed. If the caller of RunSyncNow()
does nothing with the return value, then it will be released, closing the
connection. However the caller can save the std::auto_ptr locally and
poke around in it if necessary. This interface is designed for tests only!

Merged back changes from the test refactor branch to reduce diffs.

Fix failure to record client store marker, after BackupClientContext refactor.

This caused the daemon not to abort safely if the CSM changed under our feet,
meaning that our cached data is invalid.

Fix for earlier patch to allow tests to access the BackupClientContext after
backup completes, because a new CSM wasn't generated in time for bbackupd to
record it, because the connection wasn't closed yet.

Modified: box/trunk/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientContext.cpp	2014-09-04 01:36:21 UTC (rev 3381)
+++ box/trunk/bin/bbackupd/BackupClientContext.cpp	2014-09-04 01:36:23 UTC (rev 3382)
@@ -212,6 +212,17 @@
 					"same account?");
 			}
 		}
+		else // mClientStoreMarker == ClientStoreMarker_NotKnown
+		{
+			// Yes, choose one, the current time will do
+			box_time_t marker = GetCurrentBoxTime();
+			
+			// Set it on the store
+			mapConnection->QuerySetClientStoreMarker(marker);
+			
+			// Record it so that it can be picked up later.
+			mClientStoreMarker = marker;
+		}
 
 		// Log success
 		BOX_INFO("Connection made, login successful");
@@ -250,19 +261,6 @@
 	{
 		try
 		{
-			// Need to set a client store marker?
-			if(mClientStoreMarker == ClientStoreMarker_NotKnown)
-			{
-				// Yes, choose one, the current time will do
-				box_time_t marker = GetCurrentBoxTime();
-				
-				// Set it on the store
-				mapConnection->QuerySetClientStoreMarker(marker);
-				
-				// Record it so that it can be picked up later.
-				mClientStoreMarker = marker;
-			}
-		
 			// Quit nicely
 			mapConnection->QueryFinished();
 		}

Modified: box/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-09-04 01:36:21 UTC (rev 3381)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-09-04 01:36:23 UTC (rev 3382)
@@ -697,7 +697,7 @@
 	DeleteAllIDMaps();
 }
 
-void BackupDaemon::RunSyncNowWithExceptionHandling()
+std::auto_ptr<BackupClientContext> BackupDaemon::RunSyncNowWithExceptionHandling()
 {
 	bool errorOccurred = false;
 	int errorCode = 0, errorSubCode = 0;
@@ -759,7 +759,7 @@
 				<< "/" << errorSubCode 
 				<< ") due to signal");
 			OnBackupFinish();
-			return;
+			return mapClientContext; // releases mapClientContext
 		}
 
 		NotifySysadmin(SysadminNotifier::BackupError);
@@ -811,6 +811,7 @@
 	mDoSyncForcedByPreviousSyncError = errorOccurred && !isBerkelyDbFailure;
 
 	OnBackupFinish();
+	return mapClientContext; // releases mapClientContext
 }
 
 void BackupDaemon::ResetCachedState()
@@ -823,8 +824,34 @@
 	DeleteAllIDMaps();
 }
 
-void BackupDaemon::RunSyncNow()
+std::auto_ptr<BackupClientContext> BackupDaemon::GetNewContext
+(
+	LocationResolver &rResolver,
+	TLSContext &rTLSContext,
+	const std::string &rHostname,
+	int32_t Port,
+	uint32_t AccountNumber,
+	bool ExtendedLogging,
+	bool ExtendedLogToFile,
+	std::string ExtendedLogFile,
+	ProgressNotifier &rProgressNotifier,
+	bool TcpNiceMode
+)
 {
+	std::auto_ptr<BackupClientContext> context(new BackupClientContext(
+		rResolver, rTLSContext, rHostname, Port, AccountNumber,
+		ExtendedLogging, ExtendedLogToFile, ExtendedLogFile,
+		rProgressNotifier, TcpNiceMode));
+	return context;
+}
+
+// Returns the BackupClientContext so that tests can use it to hold the
+// connection open and prevent housekeeping from running. Otherwise don't use
+// it, let it be destroyed and close the connection.
+std::auto_ptr<BackupClientContext> BackupDaemon::RunSyncNow()
+{
+	Timers::AssertInitialised();
+
 	// Delete the serialised store object file,
 	// so that we don't try to reload it after a
 	// partially completed backup
@@ -870,8 +897,7 @@
 
 	// Then create a client context object (don't
 	// just connect, as this may be unnecessary)
-	BackupClientContext clientContext
-	(
+	mapClientContext = GetNewContext(
 		*mpLocationResolver,
 		mTlsContext,
 		conf.GetKeyValue("StoreHostname"),
@@ -929,7 +955,10 @@
 	// Check logic
 	ASSERT(syncPeriodEnd > syncPeriodStart);
 	// Paranoid check on sync times
-	if(syncPeriodStart >= syncPeriodEnd) return;
+	if(syncPeriodStart >= syncPeriodEnd)
+	{
+		return mapClientContext; // releases mapClientContext
+	}
 	
 	// Adjust syncPeriodEnd to emulate snapshot behaviour properly
 	box_time_t syncPeriodEndExtended = syncPeriodEnd;
@@ -950,7 +979,7 @@
 
 	// Set up the sync parameters
 	BackupClientDirectoryRecord::SyncParams params(*mpRunStatusProvider,
-		*mpSysadminNotifier, *mpProgressNotifier, clientContext, this);
+		*mpSysadminNotifier, *mpProgressNotifier, *mapClientContext, this);
 	params.mSyncPeriodStart = syncPeriodStart;
 	params.mSyncPeriodEnd = syncPeriodEndExtended;
 	// use potentially extended end time
@@ -993,11 +1022,11 @@
 		keepAliveTime = conf.GetKeyValueInt("KeepAliveTime");
 	}
 
-	clientContext.SetMaximumDiffingTime(maximumDiffingTime);
-	clientContext.SetKeepAliveTime(keepAliveTime);
-	
+	mapClientContext->SetMaximumDiffingTime(maximumDiffingTime);
+	mapClientContext->SetKeepAliveTime(keepAliveTime);
+
 	// Set store marker
-	clientContext.SetClientStoreMarker(mClientStoreMarker);
+	mapClientContext->SetClientStoreMarker(mClientStoreMarker);
 
 	// Set up the locations, if necessary -- need to do it here so we have
 	// a (potential) connection to use.
@@ -1008,16 +1037,16 @@
 
 		// Make sure all the directory records
 		// are set up
-		SetupLocations(clientContext, locations);
+		SetupLocations(*mapClientContext, locations);
 	}
 
-	mpProgressNotifier->NotifyIDMapsSetup(clientContext);
+	mpProgressNotifier->NotifyIDMapsSetup(*mapClientContext);
 
 	// Get some ID maps going
 	SetupIDMapsForSync();
 
 	// Delete any unused directories?
-	DeleteUnusedRootDirEntries(clientContext);
+	DeleteUnusedRootDirEntries(*mapClientContext);
 
 #ifdef ENABLE_VSS
 	CreateVssBackupComponents();
@@ -1030,12 +1059,12 @@
 	{
 		// Set current and new ID map pointers
 		// in the context
-		clientContext.SetIDMaps(mCurrentIDMaps[(*i)->mIDMapIndex],
+		mapClientContext->SetIDMaps(mCurrentIDMaps[(*i)->mIDMapIndex],
 			mNewIDMaps[(*i)->mIDMapIndex]);
 	
 		// Set exclude lists (context doesn't
 		// take ownership)
-		clientContext.SetExcludeLists(
+		mapClientContext->SetExcludeLists(
 			(*i)->mapExcludeFiles.get(),
 			(*i)->mapExcludeDirs.get());
 
@@ -1053,24 +1082,21 @@
 			locationPath, std::string("/") + (*i)->mName, **i);
 
 		// Unset exclude lists (just in case)
-		clientContext.SetExcludeLists(0, 0);
+		mapClientContext->SetExcludeLists(0, 0);
 	}
 
 	// Perform any deletions required -- these are
 	// delayed until the end to allow renaming to 
 	// happen neatly.
-	clientContext.PerformDeletions();
+	mapClientContext->PerformDeletions();
 
-	// Close any open connection
-	clientContext.CloseAnyOpenConnection();
-
 #ifdef ENABLE_VSS
 	CleanupVssBackupComponents();
 #endif
 
 	// Get the new store marker
-	mClientStoreMarker = clientContext.GetClientStoreMarker();
-	mStorageLimitExceeded = clientContext.StorageLimitExceeded();
+	mClientStoreMarker = mapClientContext->GetClientStoreMarker();
+	mStorageLimitExceeded = mapClientContext->StorageLimitExceeded();
 	mReadErrorsOnFilesystemObjects |=
 		params.mReadErrorsOnFilesystemObjects;
 
@@ -1102,6 +1128,8 @@
 		SerializeStoreObjectInfo(mLastSyncTime, mNextSyncTime);
 
 	// --------------------------------------------------------------------------------------------
+
+	return mapClientContext; // releases mapClientContext
 }
 
 #ifdef ENABLE_VSS

Modified: box/trunk/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.h	2014-09-04 01:36:21 UTC (rev 3381)
+++ box/trunk/bin/bbackupd/BackupDaemon.h	2014-09-04 01:36:23 UTC (rev 3382)
@@ -57,8 +57,8 @@
 //		Created: 2003/10/08
 //
 // --------------------------------------------------------------------------
-class BackupDaemon : public Daemon, ProgressNotifier, LocationResolver,
-RunStatusProvider, SysadminNotifier, BackgroundTask
+class BackupDaemon : public Daemon, public ProgressNotifier, public LocationResolver,
+public RunStatusProvider, public SysadminNotifier, public BackgroundTask
 {
 public:
 	BackupDaemon();
@@ -118,8 +118,8 @@
 
 public:
 	void InitCrypto();
-	void RunSyncNowWithExceptionHandling();
-	void RunSyncNow();
+	std::auto_ptr<BackupClientContext> RunSyncNowWithExceptionHandling();
+	std::auto_ptr<BackupClientContext> RunSyncNow();
 	void ResetCachedState();
 	void OnBackupStart();
 	void OnBackupFinish();
@@ -127,6 +127,21 @@
 	// This does NOT constitute an API!
 	void TouchFileInWorkingDir(const char *Filename);
 
+protected:
+	virtual std::auto_ptr<BackupClientContext> GetNewContext
+	(
+		LocationResolver &rResolver,
+		TLSContext &rTLSContext,
+		const std::string &rHostname,
+		int32_t Port,
+		uint32_t AccountNumber,
+		bool ExtendedLogging,
+		bool ExtendedLogToFile,
+		std::string ExtendedLogFile,
+		ProgressNotifier &rProgressNotifier,
+		bool TcpNiceMode
+	);
+
 private:
 	void DeleteAllLocations();
 	void SetupLocations(BackupClientContext &rClientContext, const Configuration &rLocationsConf);
@@ -244,6 +259,7 @@
 	RunStatusProvider* mpRunStatusProvider;
 	SysadminNotifier* mpSysadminNotifier;
 	std::auto_ptr<Timer> mapCommandSocketPollTimer;
+	std::auto_ptr<BackupClientContext> mapClientContext;
 
 	/* ProgressNotifier implementation */
 public:




More information about the Boxbackup-commit mailing list