-
#include "tensorstore/kvstore/generation.h"
- struct tensorstore::StorageGeneration;
Represents a generation identifier associated with a stored object.
The generation identifier must change each time an object with a given key is updated. Generation identifiers are not comparable across keys: for two different keys, the same generation identifier may correspond to different values.
A
StorageGeneration
should be treated as an opaque identifier, with its length and content specific to the particular storage system.For example:
t=0: Object does not exist, implicitly has generation G0, which may equal
StorageGeneration::NoValue()
.t=1: Value V1 is written, storage system assigns generation G1.
t=2: Value V2 is written, storage system assigns generation G2, which must not equal G1.
t=3: Value V1 is written again, storage system assigns generation G3, which must not equal G1 or G2.
t=4: Object is deleted, implicitly has generation G4, which may equal G0 and/or
StorageGeneration::NoValue()
.
Note: Some storage implementations always use a generation of
StorageGeneration::NoValue()
for not-present objects. Other storage implementations may use other generations to indicate not-present objects. For example, if some sharding scheme is used pack multiple objects together into a “shard”, the generation associated with a not-present object may be the generation of the shard in which the object is missing.Data members¶
- std::string value;
A storage generation is encoded as a variable-length that specifies an optional “base generation” and information about uncommitted modifications made within a transaction.
Conversion operators¶
- explicit operator bool() const;
Indicates whether a generation is specified.
Methods¶
- std::string DebugString() const;
Returns a debug representation of the storage generation.
- static StorageGeneration Unknown();
Returns the special generation value that indicates the StorageGeneration is unspecified.
- static StorageGeneration NoValue();
Returns the special generation value that corresponds to an object not being present.
- static StorageGeneration Invalid();
Returns the invalid generation value guaranteed not to equal any valid generation.
-
static bool EqualOrUnspecified(const StorageGeneration& generation,
const StorageGeneration& if_equal); Checks if
if_equal
is unspecified, or equal togeneration
.
-
static bool
NotEqualOrUnspecified(const StorageGeneration& generation,
const StorageGeneration& if_not_equal); Checks if
if_not_equal
is unspecified, or not equal togeneration
.
- static bool IsUnknown(const StorageGeneration& generation);
Returns
true
ifgeneration
is equal to the specialStorageGeneration::Unknown()
value, i.e. an empty string.
- static bool IsNoValue(const StorageGeneration& generation);
Returns
true
ifgeneration
is equal to the specialNoValue()
generation.
- static bool IsClean(const StorageGeneration& generation);
Returns
true
ifgeneration
represents a “clean” state without any uncommitted modifications within a transaction.
Friend functions¶
-
friend bool
operator==(const StorageGeneration& a, const StorageGeneration& b); -
friend bool
operator==(std::string_view a, const StorageGeneration& b); -
friend bool
operator==(const StorageGeneration& a, std::string_view b); -
friend bool
operator!=(const StorageGeneration& a, const StorageGeneration& b); -
friend bool
operator!=(const StorageGeneration& a, std::string_view b); -
friend bool
operator!=(std::string_view a, const StorageGeneration& b); Checks if two generations are equivalent.
-
friend std::ostream&
operator<<(std::ostream& os, const StorageGeneration& g); Prints a debugging string representation to an
std::ostream
.