[Box Backup-commit] COMMIT r1309 - box/chris/general/lib/backupclient

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Mar 3 21:29:49 GMT 2007


Author: chris
Date: 2007-03-03 21:29:49 +0000 (Sat, 03 Mar 2007)
New Revision: 1309

Modified:
   box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp
Log:
Use timers for managing diffs (from chris/merge)


Modified: box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp	2007-03-03 21:28:26 UTC (rev 1308)
+++ box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp	2007-03-03 21:29:49 UTC (rev 1309)
@@ -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,11 @@
 	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);
 
-	if (pDiffTimer)
+	if(pDiffTimer && pDiffTimer->IsManaged())
 	{
-		TimeMgmtEpoch      = pDiffTimer->GetTimeMgmtEpoch();
-		MaximumDiffingTime = pDiffTimer->GetMaximumDiffingTime();
-		KeepAliveTime      = pDiffTimer->GetKeepaliveTime();
+		maximumDiffingTime = Timer(pDiffTimer->GetMaximumDiffingTime());
 	}
 	
 	std::map<int64_t, int32_t> goodnessOfFit;
@@ -577,31 +549,20 @@
 			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(pDiffTimer)
+				{
+					pDiffTimer->DoKeepAlive();
+				}
+				
 				// Load in another block of data, and record how big it is
 				int bytesInEndings = rFile.Read(endings, Sizes[s]);
 				int tmp;




More information about the Boxbackup-commit mailing list