diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-09-04 01:36:43 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-09-04 01:36:43 +0000 |
commit | 1c1b1953406707e0d8acf5d33ddc2a51d1ee5155 (patch) | |
tree | 0c143a3eb7745c4b4ea233186d3ba0a8da3de235 | |
parent | e8a4a86e0043e6f6d12e6e29ef5b5e0268fb44a6 (diff) |
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.
-rw-r--r-- | lib/raidfile/RaidFileUtil.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp index e826e7d0..33438371 100644 --- a/lib/raidfile/RaidFileUtil.cpp +++ b/lib/raidfile/RaidFileUtil.cpp @@ -18,6 +18,26 @@ #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; +} // -------------------------------------------------------------------------- // @@ -63,16 +83,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, *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 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, } 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 |