KeySubspace

Namespace: FoundationDB.Client · class

Implements: IKeySubspace, ISpanEncodable, IEquatable<IKeySubspace>, IComparable<IKeySubspace>, ISpanFormattable, IFormattable

Adds a prefix on every key, to group them inside a common subspace

Constructors

KeySubspace

KeySubspace(Slice prefix, ISubspaceContext context)

Properties

Context

ISubspaceContext Context { get; }

The context from which this subspace came from

The context is usually the directory or global subspace of the database. It can also be the context for keys created outside any context The context is used to track the origin of a subspace, and optionally revoke access to it once the context becomes invalid (ex: cached context no longer being valid)

Methods

BoundCheck

Slice BoundCheck(Slice key, bool allowSystemKeys)

Check that a key fits inside this subspace, and return '' or '\xFF' if it is outside the bounds

  • key — Key that needs to be checked
  • allowSystemKeys — If true, allow keys that starts with \xFF even if this subspace is not the Empty subspace or System subspace itself.

Returns: The key unchanged if it is contained in the namespace, Empty if it was before the subspace, or FdbKey.MaxValue if it was after.

ReadOnlySpan<byte> BoundCheck(ReadOnlySpan<byte> key, bool allowSystemKeys)

Check that a key fits inside this subspace, and return '' or '\xFF' if it is outside the bounds

  • key — Key that needs to be checked
  • allowSystemKeys — If true, allow keys that starts with \xFF even if this subspace is not the Empty subspace or System subspace itself.

Returns: The key unchanged if it is contained in the namespace, Empty if it was before the subspace, or FdbKey.MaxValue if it was after.

CompareTo

int CompareTo(IKeySubspace other)

Compare this subspace with another subspace

Contains

bool Contains(ReadOnlySpan<byte> absoluteKey)

Tests whether the specified absoluteKey starts with this subspace prefix, indicating that the Subspace logically contains absoluteKey.

  • absoluteKey — The key to be tested

The key is not contained by any Subspace, so subspace.Contains(Slice.Nil) will always return false

CopyUnsafe

static IKeySubspace CopyUnsafe(IKeySubspace subspace)

Create an unsafe copy of a directory by discarding its context

  • subspace — Subspace that lives in a temporary context (ex: transaction context)

Returns: Subspace with the same key prefix, and disconnected from the original context.

THIS IS VERY DANGEROUS! Any change to the original subspace may cause the prefix stored in the copy to become obsolete, and MAY introduce data corruption!

DumpKey

string DumpKey(Slice key, bool absolute = false)

Return a user-friendly representation of a key from this subspace

  • key — Key that is contained in this subspace

Returns: Printable version of this key, minus the subspace prefix

Equals

bool Equals(IKeySubspace other)

Test if both subspaces have the same prefix

bool Equals(object obj)

Test if an object is a subspace with the same prefix

ExtractKey

Slice ExtractKey(Slice absoluteKey, bool boundCheck = false)

Remove the subspace prefix from a binary key, and only return the tail, or Nil if the key does not fit inside the namespace

  • absoluteKey — Complete key that contains the current subspace prefix, and a binary suffix
  • boundCheck — If true, verify that absoluteKey is inside the bounds of the subspace

Returns: Binary suffix of the key (or Empty is the key is exactly equal to the subspace prefix). If the key is outside the subspace, returns Nil

ReadOnlySpan<byte> ExtractKey(ReadOnlySpan<byte> absoluteKey, bool boundCheck = false)

Remove the subspace prefix from a binary key, and only return the tail, or Nil if the key does not fit inside the namespace

  • absoluteKey — Complete key that contains the current subspace prefix, and a binary suffix
  • boundCheck — If true, verify that absoluteKey is inside the bounds of the subspace

Returns: Binary suffix of the key (or Empty is the key is exactly equal to the subspace prefix). If the key is outside the subspace, returns Nil

FromKey

static IKeySubspace FromKey(Slice prefix, ISubspaceContext context = null)

Initializes a new generic subspace with the given prefix.

GetHashCode

int GetHashCode()

Compute a hashcode based on the prefix of this subspace

GetPath

FdbPath GetPath()

Returns the path of the subspace, if there is one.

Returns: Path of the subspace, or Empty if this subspace is not part of the Directory Layer

GetPrefix

Slice GetPrefix()

Returns the raw prefix of this subspace

Will throw if the prefix is not publicly visible, as is the case for Directory Partitions

PrettyPrint

string PrettyPrint(Slice packedKey)

Return a human-friendly string representation of a key, as encoded by this subspace

  • packedKey — Key that was generated from this subspace

ToRange

FdbSubspaceKeyRange ToRange(bool inclusive = false)

Return a range that will match all the keys in this subspace, including the prefix itself

Returns: Return the range: Key <= x <= Increment(Key)

ToString

string ToString()

Printable representation of this subspace

string ToString(string format, IFormatProvider provider = null)

TryAppend

bool TryAppend(Span<byte> destination, out int bytesWritten, ReadOnlySpan<byte> relativeKey)

Manually append a binary suffix to the subspace prefix

Appending a binary literal that does not comply with the subspace key encoding may produce a result that cannot be decoded!

TryFormat

bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider)

Fields

Empty

static readonly IKeySubspace Empty

Root keyspace of the database (with no prefix)