[Box Backup-commit] COMMIT r3390 - box/trunk/lib/raidfile

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


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

Modified:
   box/trunk/lib/raidfile/RaidFileUtil.cpp
Log:
Handle raidfile versioning better on low time accuracy systems.

We simulate a 1 second accuracy clock in DEBUG mode on all systems, to help
catch corner cases in tests. This now applies to both RAID and non-RAID files.

We always add file size to the version number to help detect changes,
especially in such cases. In RELEASE builds, we use as much accuracy from the
clock as we can get, as well as file size.

Modified: box/trunk/lib/raidfile/RaidFileUtil.cpp
===================================================================
--- box/trunk/lib/raidfile/RaidFileUtil.cpp	2014-09-04 01:36:41 UTC (rev 3389)
+++ box/trunk/lib/raidfile/RaidFileUtil.cpp	2014-09-04 01:36:43 UTC (rev 3390)
@@ -18,7 +18,27 @@
 
 #include "MemLeakFindOn.h"
 
+int64_t adjust_timestamp(int64_t timestamp, size_t file_size)
+{
+#ifndef BOX_RELEASE_BUILD
+	// Remove the microseconds part of the timestamp,
+	// to simulate filesystem with 1-second timestamp
+	// resolution, e.g. MacOS X HFS, old Linuxes.
+	// Otherwise it's easy to write tests that rely
+	// on more accurate timestamps, and pass on
+	// platforms that have them, and fail on others.
+	timestamp -= (timestamp % MICRO_SEC_IN_SEC);
+#endif
 
+	// The resolution of timestamps may be very
+	// low, e.g. 1 second. So add the size to it
+	// to give a bit more chance of it changing.
+	// TODO: Make this better.
+	timestamp += file_size;
+
+	return timestamp;
+}
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -63,16 +83,7 @@
 					*pRevisionID = FileModificationTime(st);
 				#endif
 
-#ifdef BOX_RELEASE_BUILD
-				// The resolution of timestamps may be very
-				// low, e.g. 1 second. So add the size to it
-				// to give a bit more chance of it changing.
-				// TODO: Make this better.
-				// Disabled in debug mode, to simulate
-				// filesystem with 1-second timestamp
-				// resolution, e.g. MacOS X HFS, Linux.
-				(*pRevisionID) += st.st_size;
-#endif
+				*pRevisionID = adjust_timestamp(*pRevisionID, st.st_size);
 			}
 			
 			// return non-raid file
@@ -116,16 +127,8 @@
 	}
 	if(pRevisionID != 0)
 	{
+		revisionID = adjust_timestamp(revisionID, revisionIDplus);
 		(*pRevisionID) = revisionID;
-#ifdef BOX_RELEASE_BUILD
-		// The resolution of timestamps may be very low, e.g.
-		// 1 second. So add the size to it to give a bit more
-		// chance of it changing.
-		// TODO: Make this better.
-		// Disabled in debug mode, to simulate filesystem with
-		// 1-second timestamp resolution, e.g. MacOS X HFS, Linux.
-		(*pRevisionID) += revisionIDplus;
-#endif
 	}
 	
 	// Return a status based on how many parts are available




More information about the Boxbackup-commit mailing list