#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.

bool IsValid() const;

Check if the generation is valid, i.e. not derived from Invalid().

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 StorageGenerationgeneration,
                               
const StorageGenerationif_equal);

Checks if if_equal is unspecified, or equal to generation.

static bool
NotEqualOrUnspecified(const StorageGenerationgeneration,
                      
const StorageGenerationif_not_equal);

Checks if if_not_equal is unspecified, or not equal to generation.

static bool IsUnknown(const StorageGenerationgeneration);

Returns true if generation is equal to the special StorageGeneration::Unknown() value, i.e. an empty string.

static bool IsNoValue(const StorageGenerationgeneration);

Returns true if generation is equal to the special NoValue() generation.

static bool IsClean(const StorageGenerationgeneration);

Returns true if generation represents a “clean” state without any uncommitted modifications within a transaction.

Friend functions

friend bool
operator==(const StorageGenerationaconst StorageGenerationb);
friend bool
operator==(std::string_view aconst StorageGenerationb);
friend bool
operator==(const StorageGenerationastd::string_view b);
friend bool
operator!=(const StorageGenerationaconst StorageGenerationb);
friend bool
operator!=(const StorageGenerationastd::string_view b);
friend bool
operator!=(std::string_view aconst StorageGenerationb);

Checks if two generations are equivalent.

friend std::ostream&
operator<<(std::ostreamosconst StorageGenerationg);

Prints a debugging string representation to an std::ostream.