From aa5dbb2887c1e27a3917001f2ec6f39766964aee Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Mon, 22 Apr 2024 14:15:44 -0700 Subject: [PATCH] Explicitly allow writeVersion to be non-decreasing Instead of strictly increasing. --- Internal.h | 8 ++++---- include/ConflictSet.h | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Internal.h b/Internal.h index ec86698..5094dff 100644 --- a/Internal.h +++ b/Internal.h @@ -523,7 +523,7 @@ template struct TestDriver { explicit TestDriver(const uint8_t *data, size_t size) : arbitrary({data, size}) {} - int64_t writeVersion = 0; + int64_t writeVersion = 1000; int64_t oldestVersion = 0; ConflictSetImpl cs{oldestVersion}; ReferenceImpl refImpl{oldestVersion}; @@ -545,7 +545,7 @@ template struct TestDriver { { int numPointWrites = arbitrary.bounded(100); int numRangeWrites = arbitrary.bounded(100); - int64_t v = ++writeVersion; + int64_t v = (writeVersion += arbitrary.bounded(10)); auto *writes = new (arena) ConflictSet::WriteRange[numPointWrites + numRangeWrites]; auto keys = set(arena); @@ -605,8 +605,8 @@ template struct TestDriver { refImpl.addWrites(writes, numPointWrites + numRangeWrites, v); - oldestVersion = std::max(writeVersion - arbitrary.bounded(10), - oldestVersion); + oldestVersion = + std::min(writeVersion - 10, oldestVersion + arbitrary.bounded(10)); cs.setOldestVersion(oldestVersion); refImpl.setOldestVersion(oldestVersion); } diff --git a/include/ConflictSet.h b/include/ConflictSet.h index 93379c3..64e7490 100644 --- a/include/ConflictSet.h +++ b/include/ConflictSet.h @@ -71,12 +71,12 @@ struct __attribute__((__visibility__("default"))) ConflictSet { /** `writes` must be sorted ascending, and must not have adjacent or * overlapping ranges. Reads intersecting writes where readVersion < * `writeVersion` will result in `Conflict` (or `TooOld`, eventually). - * `writeVersion` must be greater than every write version in all previous - * calls to `addWrites` */ + * `writeVersion` must be greater than or equal to all previous write + * versions. */ void addWrites(const WriteRange *writes, int count, int64_t writeVersion); /** Reads where readVersion < oldestVersion will result in `TooOld`. Must be - * greater than any previous oldestVersion */ + * greater than or equal to all previous oldest versions. */ void setOldestVersion(int64_t oldestVersion); /** Reads where readVersion < oldestVersion will result in `TooOld`. There are @@ -160,14 +160,14 @@ void ConflictSet_check(const ConflictSet *cs, /** `writes` must be sorted ascending, and must not have adjacent or * overlapping ranges. Reads intersecting writes where readVersion < * `writeVersion` will result in `Conflict` (or `TooOld`, eventually). - * `writeVersion` must be greater than all write versions in all previous - * calls to `addWrites` */ + * `writeVersion` must be greater than or equal to all previous write versions. + */ void ConflictSet_addWrites(ConflictSet *cs, const ConflictSet_WriteRange *writes, int count, int64_t writeVersion); /** Reads where readVersion < oldestVersion will result in `TooOld`. Must be - * greater than any previous oldestVersion */ + * greater than or equal to all previous oldest versions. */ void ConflictSet_setOldestVersion(ConflictSet *cs, int64_t oldestVersion); /** Reads where readVersion < oldestVersion will result in `TooOld`. There are