From a04e81b3ffd179ab6272f5873ea0a9bcd93525f6 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Tue, 2 Jul 2024 12:45:35 -0700 Subject: [PATCH] Add version window constants --- ConflictSet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index b74a8fb..b29735c 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -78,13 +78,18 @@ constexpr void removeKey(struct Node *) {} // ==================== BEGIN IMPLEMENTATION ==================== +constexpr int64_t kNominalVersionWindow = 2e9; +constexpr int64_t kMaxCorrectVersionWindow = + std::numeric_limits::max(); +static_assert(kNominalVersionWindow <= kMaxCorrectVersionWindow); + struct InternalVersionT { constexpr InternalVersionT() = default; constexpr explicit InternalVersionT(int64_t value) : value(value) {} constexpr int64_t toInt64() const { return value; } // GCOVR_EXCL_LINE constexpr auto operator<=>(const InternalVersionT &rhs) const { // Maintains ordering after overflow, as long as the full-precision versions - // are within ~2e9 of eachother. + // are within `kMaxCorrectVersionWindow` of eachother. return int32_t(value - rhs.value) <=> 0; } constexpr bool operator==(const InternalVersionT &) const = default; @@ -2834,7 +2839,8 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl { auto end = std::span(r.end.p, r.end.len); result[i] = InternalVersionT(reads[i].readVersion) < oldestVersion || - reads[i].readVersion < newestVersionFullPrecision - 2e9 + reads[i].readVersion < + newestVersionFullPrecision - kNominalVersionWindow ? TooOld : (end.size() > 0 ? checkRangeRead(root, begin, end, @@ -2950,7 +2956,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl { InternalVersionT oldestVersion; // TODO this doesn't fully mitigate the 32-bit precision issue, since we still // need to make sure we clean up versions in the tree before they fall out of - // the 2e9 window. + // the `kMaxCorrectVersionWindow` window. int64_t oldestVersionFullPrecision; int64_t newestVersionFullPrecision; int64_t totalBytes = 0;