[Box Backup-commit] COMMIT r1184 - in box/chris/merge: bin/bbackupd lib/backupclient

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Tue Nov 28 20:34:58 GMT 2006


Author: chris
Date: 2006-11-28 20:34:57 +0000 (Tue, 28 Nov 2006)
New Revision: 1184

Modified:
   box/chris/merge/bin/bbackupd/BackupClientContext.cpp
   box/chris/merge/bin/bbackupd/BackupClientContext.h
   box/chris/merge/lib/backupclient/BackupStoreFile.h
   box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp
Log:
Replace old-style setitimers for KeepAliveTime and MaximumDiffingTime 
with new Timer objects. (refs #3, refs #9)


Modified: box/chris/merge/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/chris/merge/bin/bbackupd/BackupClientContext.cpp	2006-11-28 20:30:36 UTC (rev 1183)
+++ box/chris/merge/bin/bbackupd/BackupClientContext.cpp	2006-11-28 20:34:57 UTC (rev 1184)
@@ -67,8 +67,7 @@
 	  mStorageLimitExceeded(false),
 	  mpExcludeFiles(0),
 	  mpExcludeDirs(0),
-	  mbIsManaged(false),
-	  mTimeMgmtEpoch(0)
+	  mbIsManaged(false)
 {
 }
 
@@ -142,7 +141,7 @@
 			ASSERT(mpExtendedLogFileHandle == NULL);
 			
 			mpExtendedLogFileHandle = fopen(
-				mExtendedLogFile.c_str(), "w");
+				mExtendedLogFile.c_str(), "a+");
 
 			if (!mpExtendedLogFileHandle)
 			{
@@ -338,8 +337,8 @@
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    
-//		Purpose: 
+//		Name:    BackupClientContext::PerformDeletions()
+//		Purpose: Perform any pending file deletions.
 //		Created: 10/11/03
 //
 // --------------------------------------------------------------------------
@@ -496,7 +495,6 @@
 	return true;
 }
 
-
 // maximum time to spend diffing
 static int sMaximumDiffTime = 600;
 // maximum time of SSL inactivity (keep-alive interval)
@@ -517,19 +515,6 @@
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    static TimerSigHandler(int)
-//		Purpose: Signal handler
-//		Created: 19/3/04
-//
-// --------------------------------------------------------------------------
-static void TimerSigHandler(int iUnused)
-{
-	BackupStoreFile::DiffTimerExpired();	
-}
-
-// --------------------------------------------------------------------------
-//
-// Function
 //		Name:    BackupClientContext::ManageDiffProcess()
 //		Purpose: Initiates a file diff control timer
 //		Created: 04/19/2005
@@ -537,59 +522,8 @@
 // --------------------------------------------------------------------------
 void BackupClientContext::ManageDiffProcess()
 {
-	if (mbIsManaged || !mpConnection)
-		return;
-
-	ASSERT(mTimeMgmtEpoch == 0);
-
-#ifdef PLATFORM_CYGWIN
-	::signal(SIGALRM, TimerSigHandler);
-#elif defined WIN32
-	// no support for SIGVTALRM
-	SetTimerHandler(TimerSigHandler);
-#else
-	::signal(SIGVTALRM, TimerSigHandler);
-#endif // PLATFORM_CYGWIN
-
-	struct itimerval timeout;
-	memset(&timeout, 0, sizeof(timeout));
-
-	//
-	//
-	//
-	if (sMaximumDiffTime <= 0 && sKeepAliveTime <= 0)
-	{
-		TRACE0("Diff control not requested - letting things run wild\n");
-		return;
-	}
-	else if (sMaximumDiffTime > 0 && sKeepAliveTime > 0)
-	{
-		timeout.it_value.tv_sec = sKeepAliveTime < sMaximumDiffTime ? sKeepAliveTime : sMaximumDiffTime;
-		timeout.it_interval.tv_sec = sKeepAliveTime < sMaximumDiffTime ? sKeepAliveTime : sMaximumDiffTime;
-	}
-	else
-	{
-		timeout.it_value.tv_sec = sKeepAliveTime > 0 ? sKeepAliveTime : sMaximumDiffTime;
-		timeout.it_interval.tv_sec = sKeepAliveTime > 0 ? sKeepAliveTime : sMaximumDiffTime;
-	}
-
-	// avoid race
-	mTimeMgmtEpoch = time(NULL);
-
-#ifdef PLATFORM_CYGWIN
-	if(::setitimer(ITIMER_REAL, &timeout, NULL) != 0)
-#else
-	if(::setitimer(ITIMER_VIRTUAL, &timeout, NULL) != 0)
-#endif // PLATFORM_CYGWIN
-	{
-		mTimeMgmtEpoch = 0;
-
-		TRACE0("WARNING: couldn't set file diff control timeout\n");
-		THROW_EXCEPTION(BackupStoreException, Internal)
-	}
-
+	ASSERT(!mbIsManaged);
 	mbIsManaged = true;
-	TRACE0("Initiated timer for file diff control\n");
 }
 
 // --------------------------------------------------------------------------
@@ -602,26 +536,8 @@
 // --------------------------------------------------------------------------
 void BackupClientContext::UnManageDiffProcess()
 {
-	if (!mbIsManaged /* don't test for active connection, just do it */)
-		return;
-
-	struct itimerval timeout;
-	memset(&timeout, 0, sizeof(timeout));
-
-#ifdef PLATFORM_CYGWIN
-	if(::setitimer(ITIMER_REAL, &timeout, NULL) != 0)
-#else
-	if(::setitimer(ITIMER_VIRTUAL, &timeout, NULL) != 0)
-#endif // PLATFORM_CYGWIN
-	{
-		TRACE0("WARNING: couldn't clear file diff control timeout\n");
-		THROW_EXCEPTION(BackupStoreException, Internal)
-	}
-
+	// ASSERT(mbIsManaged);
 	mbIsManaged = false;
-	mTimeMgmtEpoch = 0;
-
-	TRACE0("Suspended timer for file diff control\n");
 }
 
 // --------------------------------------------------------------------------
@@ -643,26 +559,12 @@
 	mpConnection->QueryGetIsAlive();
 }
 
-// --------------------------------------------------------------------------
-//
-// Function
-//		Name:    BackupClientContext::GetTimeMgmtEpoch()
-//		Purpose: Returns the unix time when the diff was started, or zero
-//				 if the diff process is unmanaged.
-//		Created: 04/19/2005
-//
-// --------------------------------------------------------------------------
-time_t BackupClientContext::GetTimeMgmtEpoch() 
-{
-	return mTimeMgmtEpoch;
-}
-
 int BackupClientContext::GetMaximumDiffingTime() 
 {
 	return sMaximumDiffTime;
 }
 
-int BackupClientContext::GetKeepaliveTime() 
+int BackupClientContext::GetKeepAliveTime() 
 {
 	return sKeepAliveTime;
 }

Modified: box/chris/merge/bin/bbackupd/BackupClientContext.h
===================================================================
--- box/chris/merge/bin/bbackupd/BackupClientContext.h	2006-11-28 20:30:36 UTC (rev 1183)
+++ box/chris/merge/bin/bbackupd/BackupClientContext.h	2006-11-28 20:34:57 UTC (rev 1184)
@@ -193,9 +193,9 @@
 	//
 	// --------------------------------------------------------------------------
 	virtual void   DoKeepAlive();
-	virtual time_t GetTimeMgmtEpoch();
 	virtual int    GetMaximumDiffingTime();
-	virtual int    GetKeepaliveTime();
+	virtual int    GetKeepAliveTime();
+	virtual bool   IsManaged() { return mbIsManaged; }
 	
 private:
 	BackupDaemon &mrDaemon;
@@ -217,9 +217,6 @@
 	ExcludeList *mpExcludeDirs;
 
 	bool mbIsManaged;
-	// unix time when diff was started
-	time_t mTimeMgmtEpoch;
 };
 
-
 #endif // BACKUPCLIENTCONTEXT__H

Modified: box/chris/merge/lib/backupclient/BackupStoreFile.h
===================================================================
--- box/chris/merge/lib/backupclient/BackupStoreFile.h	2006-11-28 20:30:36 UTC (rev 1183)
+++ box/chris/merge/lib/backupclient/BackupStoreFile.h	2006-11-28 20:34:57 UTC (rev 1184)
@@ -51,16 +51,16 @@
 	virtual ~DiffTimer();
 public:
 	virtual void   DoKeepAlive() = 0;
-	virtual time_t GetTimeMgmtEpoch() = 0;
 	virtual int    GetMaximumDiffingTime() = 0;
-	virtual int    GetKeepaliveTime() = 0;
+	virtual int    GetKeepAliveTime() = 0;
+	virtual bool   IsManaged() = 0;
 };
 
 // --------------------------------------------------------------------------
 //
 // Class
 //		Name:    BackupStoreFile
-//		Purpose: Class to hold together utils for maniplating files.
+//		Purpose: Class to hold together utils for manipulating files.
 //		Created: 2003/08/28
 //
 // --------------------------------------------------------------------------

Modified: box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp
===================================================================
--- box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp	2006-11-28 20:30:36 UTC (rev 1183)
+++ box/chris/merge/lib/backupclient/BackupStoreFileDiff.cpp	2006-11-28 20:34:57 UTC (rev 1184)
@@ -29,6 +29,7 @@
 #include "RollingChecksum.h"
 #include "MD5Digest.h"
 #include "CommonException.h"
+#include "Timer.h"
 
 #include "MemLeakFindOn.h"
 
@@ -52,34 +53,9 @@
 BlocksAvailableEntry *pIndex, std::map<int64_t, int64_t> &rFoundBlocks);
 static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksAvailableEntry *pIndex, int64_t NumBlocks, std::map<int64_t, int64_t> &rFoundBlocks, int64_t SizeOfInputFile);
 
-// sDiffTimerExpired flags when the diff timer has expired. When true, the 
-// diff routine should check the wall clock as soon as possible, to determine 
-// whether it's time for a keepalive to be sent, or whether the diff has been 
-// running for too long and should be terminated.
-static bool sDiffTimerExpired = false;
-
-
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    BackupStoreFile::DiffTimerExpired()
-//		Purpose: Notifies BackupStoreFile object that the diff operation
-//				 timer has expired, which may mean that a keepalive should
-//				 be sent, or the diff should be terminated. Called from an
-//				 external timer, so it should not do more than set a flag.
-//
-//		Created: 19/1/06
-//
-// --------------------------------------------------------------------------
-void BackupStoreFile::DiffTimerExpired()
-{
-	sDiffTimerExpired = true;
-}
-
-
-// --------------------------------------------------------------------------
-//
-// Function
 //		Name:    BackupStoreFile::MoveStreamPositionToBlockIndex(IOStream &)
 //		Purpose: Move the file pointer in this stream to just before the block index.
 //				 Assumes that the stream is at the beginning, seekable, and
@@ -483,15 +459,13 @@
 	BlocksAvailableEntry *pIndex, int64_t NumBlocks, 
 	int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES], DiffTimer *pDiffTimer)
 {
-	time_t TimeMgmtEpoch   = 0;
-	int MaximumDiffingTime = 0;
-	int KeepAliveTime      = 0;
+	Timer maximumDiffingTime(0);
+	Timer keepAliveTime(0);
 
-	if (pDiffTimer)
+	if (pDiffTimer && pDiffTimer->IsManaged())
 	{
-		TimeMgmtEpoch      = pDiffTimer->GetTimeMgmtEpoch();
-		MaximumDiffingTime = pDiffTimer->GetMaximumDiffingTime();
-		KeepAliveTime      = pDiffTimer->GetKeepaliveTime();
+		maximumDiffingTime = Timer(pDiffTimer->GetMaximumDiffingTime());
+		keepAliveTime      = Timer(pDiffTimer->GetKeepAliveTime());
 	}
 	
 	std::map<int64_t, int32_t> goodnessOfFit;
@@ -577,30 +551,24 @@
 			int rollOverInitialBytes = 0;
 			while(true)
 			{
-				if(sDiffTimerExpired)
+				if(maximumDiffingTime.HasExpired())
 				{
-					ASSERT(TimeMgmtEpoch > 0);
 					ASSERT(pDiffTimer != NULL);
-					
-					time_t tTotalRunIntvl = time(NULL) - TimeMgmtEpoch;
-					
-					if(MaximumDiffingTime > 0 && 
-						tTotalRunIntvl >= MaximumDiffingTime)
-					{
-						TRACE0("MaximumDiffingTime reached - "
-							"suspending file diff\n");
-						abortSearch = true;
-						break;
-					}
-					else if(KeepAliveTime > 0)
-					{
-						TRACE0("KeepAliveTime reached - "
-							"initiating keep-alive\n");
-						pDiffTimer->DoKeepAlive();
-					}
-
-					sDiffTimerExpired = false;
+					TRACE0("MaximumDiffingTime reached - "
+						"suspending file diff\n");
+					abortSearch = true;
+					break;
 				}
+				
+				if(keepAliveTime.HasExpired())
+				{
+					ASSERT(pDiffTimer != NULL);
+					TRACE0("KeepAliveTime reached - "
+						"initiating keep-alive\n");
+					pDiffTimer->DoKeepAlive();
+					keepAliveTime = Timer(
+						pDiffTimer->GetKeepAliveTime());
+				}
 
 				// Load in another block of data, and record how big it is
 				int bytesInEndings = rFile.Read(endings, Sizes[s]);




More information about the Boxbackup-commit mailing list