Add ConflictSet.h
This commit is contained in:
60
ConflictSet.h
Normal file
60
ConflictSet.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct ConflictSet {
|
||||
enum Result {
|
||||
/// The result of a check which does not intersect any conflicting writes
|
||||
Commit,
|
||||
/// 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`
|
||||
TooOld,
|
||||
};
|
||||
/// Bytes ordered lexicographically
|
||||
struct Key {
|
||||
const uint8_t *p;
|
||||
int len;
|
||||
};
|
||||
/// Denotes a set of keys to be checked for conflicts
|
||||
struct ReadRange {
|
||||
Key begin;
|
||||
/// `end` having length 0 denotes that this range is the single key {begin}.
|
||||
/// Otherwise this denotes the range [begin, end)
|
||||
Key end;
|
||||
int64_t readVersion;
|
||||
};
|
||||
/// Denotes a set of keys to be considered written at `writeVersion`
|
||||
struct WriteRange {
|
||||
Key begin;
|
||||
/// `end` having length 0 denotes that this range is the single key {begin}.
|
||||
/// Otherwise this denotes the range [begin, end)
|
||||
Key end;
|
||||
int64_t writeVersion;
|
||||
};
|
||||
/// `reads` must be sorted ascending, and must not have adjacent or
|
||||
/// overlapping ranges. The result of checking reads[i] is written in
|
||||
/// results[i].
|
||||
void check(const ReadRange *reads, Result *results, int count) const;
|
||||
/// `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)
|
||||
void addWrites(const WriteRange *writes, int count);
|
||||
/// Reads where readVersion < oldestVersion will result in `TooOld`
|
||||
void setOldestVersion(int64_t oldestVersion);
|
||||
|
||||
/// Reads where readVersion < oldestVersion will result in `TooOld`. There are
|
||||
/// no writes initially.
|
||||
explicit ConflictSet(int64_t oldestVersion);
|
||||
~ConflictSet();
|
||||
|
||||
ConflictSet(ConflictSet &&) noexcept;
|
||||
ConflictSet &operator=(ConflictSet &&) noexcept;
|
||||
ConflictSet(const ConflictSet &) = delete;
|
||||
ConflictSet &operator=(const ConflictSet &) = delete;
|
||||
|
||||
private:
|
||||
struct Impl *impl;
|
||||
};
|
Reference in New Issue
Block a user