5 Commits
Author SHA1 Message Date
andrew 4ef10b106a Fix wrong-result bug. Previously it could incorrectly report Commit
CI / pre-commit (push) Successful in 2m12s
CI / test (arm64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 22, https://minio.weaselab.dev/public/aarch64/msan-toolchain-22.1.8.tar.zst, debug-arm64, ubuntu-latest-arm64) (push) Failing after 3m41s
CI / test (amd64, -DCMAKE_BUILD_TYPE=Debug -DMSAN_TOOLCHAIN_PATH=/opt/msan, 21, https://minio.weaselab.dev/public/x86_64/msan-toolchain-21.1.8.tar.zst, debug, ubuntu-latest-amd64) (push) Failing after 3m55s
CI / release (arm64, , ubuntu-latest-arm64) (push) Successful in 3m31s
CI / test (amd64, -DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 21, , 64-bit-versions, ubuntu-latest-amd64) (push) Failing after 3m22s
CI / test (amd64, -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, 21, , gcc, ubuntu-latest-amd64) (push) Failing after 3m19s
CI / test (amd64, -DUSE_SIMD_FALLBACK=ON, 21, , simd-fallback, ubuntu-latest-amd64) (push) Failing after 3m21s
CI / release (amd64, -DMSAN_TOOLCHAIN_PATH=/opt/msan, ubuntu-latest-amd64) (push) Successful in 5m50s
CI / coverage (push) Failing after 3m29s
Blog post forthcoming
2026-10-09 16:34:33 -04:00
andrew 9b6dd51b85 Add a spec for fixupMaxVersion 2026-10-09 16:28:36 -04:00
andrew 647ba5beb1 Remove redundant version update
A write can never lower the logical max version of a key range.
There's no read that didn't pass before that should pass after a write.
2026-10-09 16:19:20 -04:00
andrew 2f9f49c692 Use doxygen pre/post tags and make public api more precise 2026-10-09 15:09:58 -04:00
andrew 6a6e36909f Fix assert memcmp size 2026-10-09 15:05:39 -04:00
2 changed files with 78 additions and 41 deletions

No files matched your search

+7 -5
View File
@@ -2022,7 +2022,6 @@ Node *erase(Node *self, WriteContext *writeContext, bool logical) {
parent48->index[parentIndex] = toRemoveChildrenIndex;
parent48->reverseIndex[toRemoveChildrenIndex] = parentIndex;
}
parent48->childMaxVersion[lastChildrenIndex] = writeContext->zero;
VALGRIND_MAKE_MEM_UNDEFINED(parent48->children + lastChildrenIndex,
sizeof(parent48->children[0]));
VALGRIND_MAKE_MEM_UNDEFINED(parent48->reverseIndex + lastChildrenIndex,
@@ -2903,7 +2902,11 @@ horizontalMax16(InternalVersionT *vs, InternalVersionT) {
return max;
}
// Precondition: `node->entryPresent`, and node is not the root
/** @pre `node` is not the root, `node->entryPresent`, and `writeContext !=
* nullptr`.
* @post `maxVersion(node)` is the max of `writeContext->zero` and the max
* version of all logical keys starting with the search path of `node`.
*/
void fixupMaxVersion(Node *node, WriteContext *writeContext) {
assert(node->parent);
InternalVersionT max;
@@ -2932,8 +2935,7 @@ void fixupMaxVersion(Node *node, WriteContext *writeContext) {
} break;
case Type_Node256: {
auto *self256 = static_cast<Node256 *>(node);
max = std::max(
max, horizontalMax16(self256->childMaxVersion, writeContext->zero));
max = std::max(max, horizontalMax16(self256->maxOfMax, writeContext->zero));
} break;
default: // GCOVR_EXCL_LINE
__builtin_unreachable(); // GCOVR_EXCL_LINE
@@ -4880,7 +4882,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
auto *results2 = new (arena) Result[count];
check::Context context2;
useSequential(reads, results2, count, context2);
assert(memcmp(result, results2, count) == 0);
assert(memcmp(result, results2, count * sizeof(Result)) == 0);
assert(context.readContext == context2.readContext);
#endif
}
+71 -36
View File
@@ -21,7 +21,12 @@ limitations under the License.
#ifdef __cplusplus
namespace weaselab {
/** A data structure for optimistic concurrency control on ranges of
* bitwise-lexicographically-ordered keys. All versions must be >= 0.
* bitwise-lexicographically-ordered keys.
*
* All versions are >= 0. `oldestVersion` is the smallest version a subsequent
* `check` can read and `newestVersion` is the largest version passed to
* `addWrites` or the constructor. `oldestVersion <= newestVersion`, and
* `oldestVersion >= newestVersion - two billion`.
*
* Thread safety:
* - It's safe to operate on two different ConflictSets in two different
@@ -36,8 +41,7 @@ struct __attribute__((__visibility__("default"))) ConflictSet {
/** The result of a check which intersects a write at a version >
readVersion */
Conflict,
/** The result of a check with a readVersion older than the highest call to
`setOldestVersion` */
/** The result of a check with a readVersion older than `oldestVersion` */
TooOld
};
@@ -54,9 +58,6 @@ struct __attribute__((__visibility__("default"))) ConflictSet {
/** `end` having length 0 denotes that this range is the single key {begin}.
* Otherwise this denotes the range [begin, end), and begin must be < end */
Key end;
/** `readVersion` older than the oldestVersion or the version of the
* latest call to `addWrites` minus two billion will result in `TooOld`.
* Must be <= the version of the latest call to `addWrites` */
int64_t readVersion;
};
@@ -68,23 +69,39 @@ struct __attribute__((__visibility__("default"))) ConflictSet {
Key end;
};
/** The result of checking reads[i] is written in results[i] */
/** The result of checking reads[i] is written in results[i].
* @pre `reads` and `results` each hold at least `count` elements; each
* `reads[i]` is a valid `ReadRange` (see its field documentation); each
* `reads[i].readVersion <= newestVersion`.
* @post For every i < count, `results[i]` is `TooOld` if
* `reads[i].readVersion < oldestVersion`; `Conflict` if any write at a
* version greater than `reads[i].readVersion` intersects the range
* `reads[i]`; and `Commit` otherwise. */
void check(const ReadRange *reads, Result *results, int count) const;
/** Reads intersecting writes where readVersion < `writeVersion` will result
* in `Conflict` (or `TooOld`, eventually). `writeVersion` must be greater
* than or equal to all previous write versions. Call `addWrites` with `count`
* zero to only advance the version. */
/** Records writes at `writeVersion`, making them visible to `check`.
* @pre `writes` holds at least `count` elements; every `writes[i]` is a valid
* `WriteRange` (see its field documentation); `count >= 0`; `writeVersion >=
* newestVersion`.
* @post Writes (writes[i], writeVersion) are recorded for every i < count,
* and `newestVersion` becomes `writeVersion`. `oldestVersion` advances as
* needed so that `oldestVersion >= newestVersion - two billion`;
* `oldestVersion <= newestVersion` is preserved. Calling with `count == 0`
* adds no write; `newestVersion` (and possibly `oldestVersion`) still
* advance. */
void addWrites(const WriteRange *writes, int count, int64_t writeVersion);
/** Reads where readVersion < `oldestVersion` will result in `TooOld`. Must be
* greater than or equal to all previous oldest versions. Must be <= the
* version of the latest call to `addWrites` */
/** Reads where readVersion < `oldestVersion` will result in `TooOld`.
* @pre `oldestVersion >= 0` and `oldestVersion <= newestVersion`.
* @post `oldestVersion` becomes the maximum of its previous value and the
* argument; `newestVersion` is unchanged. */
void setOldestVersion(int64_t oldestVersion);
/** Reads where readVersion < oldestVersion will result in `TooOld`. There are
* no writes initially */
explicit ConflictSet(int64_t oldestVersion);
/** Reads where readVersion < `oldestVersion` will result in `TooOld`.
* @pre `version >= 0`.
* @post No writes are recorded, and `oldestVersion == newestVersion ==
* version`. */
explicit ConflictSet(int64_t version);
~ConflictSet();
@@ -146,7 +163,12 @@ private:
#else
/** A data structure for optimistic concurrency control on ranges of
* bitwise-lexicographically-ordered keys. All versions must be >= 0.
* bitwise-lexicographically-ordered keys.
*
* All versions are >= 0. `oldestVersion` is the smallest version a subsequent
* `check` can read and `newestVersion` is the largest version passed to
* `addWrites` or the constructor. `oldestVersion <= newestVersion`, and
* `oldestVersion >= newestVersion - two billion`.
*
* Thread safety:
* - It's safe to operate on two different ConflictSets in two different
@@ -160,11 +182,10 @@ typedef struct ConflictSet ConflictSet;
typedef enum {
/** The result of a check which does not intersect any conflicting writes */
ConflictSet_Commit,
/** The result of a check which intersects a write at a version > readVersion
*/
/** The result of a check which intersects a write at a version >
readVersion */
ConflictSet_Conflict,
/** The result of a check with a readVersion older than the highest call to
`setOldestVersion` */
/** The result of a check with a readVersion older than `oldestVersion` */
ConflictSet_TooOld
} ConflictSet_Result;
@@ -181,9 +202,6 @@ typedef struct {
/** `end` having length 0 denotes that this range is the single key {begin}.
* Otherwise this denotes the range [begin, end), and begin must be < end */
ConflictSet_Key end;
/** `readVersion` older than the oldestVersion or the version of the
* latest call to `addWrites` minus two billion will result in `TooOld`.
* Must be <= the version of the latest call to `addWrites` */
int64_t readVersion;
} ConflictSet_ReadRange;
@@ -195,27 +213,44 @@ typedef struct {
ConflictSet_Key end;
} ConflictSet_WriteRange;
/** The result of checking reads[i] is written in results[i] */
/** The result of checking reads[i] is written in results[i].
* @pre `reads` and `results` each hold at least `count` elements; each
* `reads[i]` is a valid `ConflictSet_ReadRange` (see its field documentation);
* each `reads[i].readVersion <= newestVersion`.
* @post For every i < count, `results[i]` is `ConflictSet_TooOld` if
* `reads[i].readVersion < oldestVersion`; `ConflictSet_Conflict` if any write
* at a version greater than `reads[i].readVersion` intersects the range
* `reads[i]`; and `ConflictSet_Commit` otherwise. */
void ConflictSet_check(const ConflictSet *cs,
const ConflictSet_ReadRange *reads,
ConflictSet_Result *results, int count);
/** Reads intersecting writes where readVersion < `writeVersion` will result
* in `Conflict` (or `TooOld`, eventually). `writeVersion` must be greater
* than or equal to all previous write versions. Call `addWrites` with `count`
* zero to only advance the version. */
/** Records writes at `writeVersion`, making them visible to
* `ConflictSet_check`.
* @pre `writes` holds at least `count` elements; every `writes[i]` is a valid
* `ConflictSet_WriteRange` (see its field documentation); `count >= 0`;
* `writeVersion >= newestVersion`.
* @post Writes (writes[i], writeVersion) are recorded for every i < count,
* and `newestVersion` becomes `writeVersion`. `oldestVersion` advances as
* needed so that `oldestVersion >= newestVersion - two billion`;
* `oldestVersion <= newestVersion` is preserved. Calling with `count == 0`
* adds no write; `newestVersion` (and possibly `oldestVersion`) still
* advance. */
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 or equal to all previous oldest versions. Must be <= the
* version of the latest call to `addWrites` */
/** Reads where readVersion < `oldestVersion` will result in `TooOld`.
* @pre `oldestVersion >= 0` and `oldestVersion <= newestVersion`.
* @post `oldestVersion` becomes the maximum of its previous value and the
* argument; `newestVersion` is unchanged. */
void ConflictSet_setOldestVersion(ConflictSet *cs, int64_t oldestVersion);
/** Reads where readVersion < oldestVersion will result in `TooOld`. There are
* no writes initially */
ConflictSet *ConflictSet_create(int64_t oldestVersion);
/** Reads where readVersion < `oldestVersion` will result in `TooOld`.
* @pre `version >= 0`.
* @post No writes are recorded, and `oldestVersion == newestVersion ==
* version`. */
ConflictSet *ConflictSet_create(int64_t version);
void ConflictSet_destroy(ConflictSet *cs);