IKeySubspace

Namespace: FoundationDB.Client · interface

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

Represents a sub-partition of the global key space.

Remarks

A subspace is the logical equivalent of a key prefix that is implicitly prepended to all keys generated from it. A "vanilla" data subspace does not imply any encoding scheme by default, but can be wrapped into a more complex subspace which includes Key Codec.

Example

In pseudocode, and given a 'MySubspaceImpl' that implement :

subspace = new MySubspaceImpl({ABC})
subspace.ConcatKey({123}) => {ABC123}
subspace.ExtractKey({ABC123}) => {123}
subspace.ExtractKey({DEF123}) => ERROR

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.

Contains

bool Contains(ReadOnlySpan<byte> absoluteKey)

Test if a key is inside the range of keys logically contained by this subspace

  • absoluteKey — Key to test

Returns: True if the key can exist inside the current subspace.

Please note that this method does not test if the key actually exists in the database, only if the key is not outside the range of keys defined by the subspace.

ExtractKey

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 if the key is exactly equal to the subspace prefix). If the key is outside the subspace, returns Nil

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 if the key is exactly equal to the subspace prefix). If the key is outside the subspace, returns Nil

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 prefix of this subspace

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)