Skip to Content
Services

KV

Declare a key-value store, bind its tables to a Function, and read and write keys from the handler.

This page lists the spec and status fields of KVStore, each with its type, its limits and its description. The Platform page explains the concept, and the metadata of every kind is the same.

KVStore

apiVersion: funcd.io/v1alpha1
kind: KVStore
metadata:
  name: counters-kv
  namespace: default
  resourceGroup: rg1
spec:
  quota:
    maxSize: 64Mi
  tables:
    - name: table-counters
      owner:
        kind: Function
        name: counter
apiVersionkind
funcd.io/v1alpha1KVStore

KVStore.spec

FieldType and limitsDescription
quotaobject, KVStore.spec.quotaCaps on the store's total size, on each value and on each key.
tablesarray of KVStore.spec.tables[]The store's tables. A table is a key space that only its owner and the writers that a RolesAssignment names may write. Table names are unique within the store, and a store with no table has nothing a Function can write.

KVStore.spec.quota

FieldType and limitsDescription
maxBytesinteger, at least 0The same cap as a number of bytes. Set maxSize or maxBytes, not both.
maxKeyBytesinteger, 0 to 64000The longest key, in bytes. 0 means 1024 (1 KiB).
maxSizestring, a size: 1 to 15 digits and an optional binary unit, Ki, Mi, Gi or Ti, with or without a B (512Ki, 2GiB)The cap on the total size held, above zero. Set maxSize or maxBytes, not both; neither means no cap. A write that would pass the cap gets 507 in a KV store or a Bucket; a SQL execute call gets 507 once the database holds the cap.
maxValueBytesinteger, 0 to 1048576The largest value a write may store, in bytes. 0 means 1048576 (1 MiB).

KVStore.spec.tables[]

FieldType and limitsDescription
namestring, required, a DNS-1123 labelThe table's name, unique within the store.
ownerobject, KVStore.spec.tables[].ownerThe Function or Job that owns the table, in the store's namespace, named with its kind. The owner writes the table, and so does a principal that a RolesAssignment grants kv::write on the table, its store or its namespace, such as the KV Data Writer role. In a store that a Function or a Job declares, the owner defaults to that workload; in one that a Workflow declares, a Function owner names a step, and the Function that funcd creates for that step is the owner; in a KVStore applied on its own, a table with no owner is written only through such a grant. Every workload, the owner included, reaches the table through an entry of its spec.bindings.kv.

KVStore.spec.tables[].owner

FieldType and limitsDescription
kindstring, required, one of Function, Lake, JobThe workload's kind. A Function, a Lake and a Job may share a name, so the kind says which one it is; each field names the kinds it accepts.
namestring, required, a DNS-1123 labelThe workload's name, in the object's namespace.

KVStore.status

FieldType and limitsDescription
bindingsintegerThe number of Function spec.bindings.kv entries that name the store.
conditionsarray of ConditionThe conditions that explain the phase.
observedGenerationintegerThe generation of the spec that funcd last acted on.
phasestring, one of Pending, Deploying, Ready, Idle, Degraded, Failed, TerminatingWhere the object is in its lifecycle.
tablesintegerThe number of tables the store declares.

Handler API

The methods a handler calls on its context's clients, in each language funcd ships a shim for.

ctx.kv

The key-value tables that the function binds, by alias: read, write and list their keys.

MethodWhat it does
get(binding: string, key: string): Promise<Uint8Array | null>The key's value as bytes, or null when the key does not exist.
getEntry(binding: string, key: string): Promise<KVEntry | null>The key's value with its version, or null when the key does not exist.
getText(binding: string, key: string): Promise<string | null>The key's value decoded as UTF-8 text, or null when the key does not exist.
getJSON<T = unknown>(binding: string, key: string): Promise<T | null>The key's value parsed as JSON, or null when the key does not exist. Write it with put(binding, key, JSON.stringify(value)).
put(binding: string, key: string, value: Uint8Array | string, opts?: PutOptions): Promise<void>Writes the value. opts.ttl, in whole seconds, sets the key's expiry; a put without it leaves the key with none. Only the table's owner and the writers that a RolesAssignment names can write.
putIfAbsent(binding: string, key: string, value: Uint8Array | string, opts?: PutOptions): Promise<string | null>Creates the key: its new version, or null when it exists (an expired key does not).
compareAndSet(binding: string, key: string, value: Uint8Array | string, version: string, opts?: PutOptions): Promise<string | null>Replaces the key while it is at version: its new version, or null when it is not.
del(binding: string, key: string): Promise<void>Deletes the key.
delIf(binding: string, key: string, version: string): Promise<boolean>Deletes the key while it is at version, as a lease holder releases what it holds: true when it did.
list(binding: string, prefix?: string): Promise<string[]>The keys that start with prefix; without a prefix, every key of the table.

Each method here that calls funcd can also fail with the status 500 and the problem type urn:funcd:problem:internal, when funcd meets an error that it did not expect; funcd logs its cause.

When funcd refuses a call, the method fails with an error that holds funcd's status and problem type. This table gives them for each method, with when each happens and what to do.

MethodStatusProblem typeWhenWhat to do
get403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
get403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
get403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
get403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
get403urn:funcd:problem:forbiddenA Policy forbids the Function to read the table.Change or remove the Policy that forbids kv::read on the table.
get413urn:funcd:problem:payload-too-largeThe key is longer than the longest key that any store can hold.Use a shorter key.
get503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
getEntry403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
getEntry403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
getEntry403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
getEntry403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
getEntry403urn:funcd:problem:forbiddenA Policy forbids the Function to read the table.Change or remove the Policy that forbids kv::read on the table.
getEntry413urn:funcd:problem:payload-too-largeThe key is longer than the longest key that any store can hold.Use a shorter key.
getEntry503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
getText403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
getText403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
getText403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
getText403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
getText403urn:funcd:problem:forbiddenA Policy forbids the Function to read the table.Change or remove the Policy that forbids kv::read on the table.
getText413urn:funcd:problem:payload-too-largeThe key is longer than the longest key that any store can hold.Use a shorter key.
getText503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
getJSON403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
getJSON403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
getJSON403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
getJSON403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
getJSON403urn:funcd:problem:forbiddenA Policy forbids the Function to read the table.Change or remove the Policy that forbids kv::read on the table.
getJSON413urn:funcd:problem:payload-too-largeThe key is longer than the longest key that any store can hold.Use a shorter key.
getJSON503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
put400urn:funcd:problem:invalidThe ttl is not a whole number of seconds from 1 to 9223372036.Send a ttl in that range.
put403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
put403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
put403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
put403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
put403urn:funcd:problem:forbiddenThe Function does not own the table, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the table's owner, or grant the Function kv::write with a RolesAssignment, such as the KV Data Writer role.
put413urn:funcd:problem:payload-too-largeThe request's body is larger than the local API takes for the call.Send a smaller body.
put413urn:funcd:problem:payload-too-largeThe value is larger than the store's spec.quota.maxValueBytes.Write a smaller value, or raise the store's spec.quota.maxValueBytes.
put413urn:funcd:problem:payload-too-largeThe key is longer than the store's spec.quota.maxKeyBytes.Use a shorter key, or raise the store's spec.quota.maxKeyBytes.
put503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
put503urn:funcd:problem:unavailablefuncd could not read the store's quota or measure what the store holds.Retry the write.
put507urn:funcd:problem:insufficient-storagefuncd's data filesystem is below storage.minFreeSize, or the write would take it there.Free space on the data filesystem, then retry; reads and deletes still work.
put507urn:funcd:problem:insufficient-storageThe write would take what a store or a prefix of a Bucket holds past its quota; the detail names which one.Delete data to make room, or raise that quota: the store's spec.quota, or the quota of the prefix in its Bucket's spec.prefixes.
putIfAbsent400urn:funcd:problem:invalidThe ttl is not a whole number of seconds from 1 to 9223372036.Send a ttl in that range.
putIfAbsent403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
putIfAbsent403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
putIfAbsent403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
putIfAbsent403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
putIfAbsent403urn:funcd:problem:forbiddenThe Function does not own the table, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the table's owner, or grant the Function kv::write with a RolesAssignment, such as the KV Data Writer role.
putIfAbsent413urn:funcd:problem:payload-too-largeThe request's body is larger than the local API takes for the call.Send a smaller body.
putIfAbsent413urn:funcd:problem:payload-too-largeThe value is larger than the store's spec.quota.maxValueBytes.Write a smaller value, or raise the store's spec.quota.maxValueBytes.
putIfAbsent413urn:funcd:problem:payload-too-largeThe key is longer than the store's spec.quota.maxKeyBytes.Use a shorter key, or raise the store's spec.quota.maxKeyBytes.
putIfAbsent503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
putIfAbsent503urn:funcd:problem:unavailablefuncd could not read the store's quota or measure what the store holds.Retry the write.
putIfAbsent507urn:funcd:problem:insufficient-storagefuncd's data filesystem is below storage.minFreeSize, or the write would take it there.Free space on the data filesystem, then retry; reads and deletes still work.
putIfAbsent507urn:funcd:problem:insufficient-storageThe write would take what a store or a prefix of a Bucket holds past its quota; the detail names which one.Delete data to make room, or raise that quota: the store's spec.quota, or the quota of the prefix in its Bucket's spec.prefixes.
compareAndSet400urn:funcd:problem:invalidThe version is empty or holds a space, a quote or a control character, so If-Match is not one strong entity-tag.Pass the version that a read or a write of the key returned.
compareAndSet400urn:funcd:problem:invalidThe ttl is not a whole number of seconds from 1 to 9223372036.Send a ttl in that range.
compareAndSet403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
compareAndSet403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
compareAndSet403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
compareAndSet403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
compareAndSet403urn:funcd:problem:forbiddenThe Function does not own the table, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the table's owner, or grant the Function kv::write with a RolesAssignment, such as the KV Data Writer role.
compareAndSet413urn:funcd:problem:payload-too-largeThe request's body is larger than the local API takes for the call.Send a smaller body.
compareAndSet413urn:funcd:problem:payload-too-largeThe value is larger than the store's spec.quota.maxValueBytes.Write a smaller value, or raise the store's spec.quota.maxValueBytes.
compareAndSet413urn:funcd:problem:payload-too-largeThe key is longer than the store's spec.quota.maxKeyBytes.Use a shorter key, or raise the store's spec.quota.maxKeyBytes.
compareAndSet503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
compareAndSet503urn:funcd:problem:unavailablefuncd could not read the store's quota or measure what the store holds.Retry the write.
compareAndSet507urn:funcd:problem:insufficient-storagefuncd's data filesystem is below storage.minFreeSize, or the write would take it there.Free space on the data filesystem, then retry; reads and deletes still work.
compareAndSet507urn:funcd:problem:insufficient-storageThe write would take what a store or a prefix of a Bucket holds past its quota; the detail names which one.Delete data to make room, or raise that quota: the store's spec.quota, or the quota of the prefix in its Bucket's spec.prefixes.
del403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
del403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
del403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
del403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
del403urn:funcd:problem:forbiddenThe Function does not own the table, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the table's owner, or grant the Function kv::write with a RolesAssignment, such as the KV Data Writer role.
del413urn:funcd:problem:payload-too-largeThe key is longer than the longest key that any store can hold.Use a shorter key.
delIf400urn:funcd:problem:invalidThe version is empty or holds a space, a quote or a control character, so If-Match is not one strong entity-tag.Pass the version that a read or a write of the key returned.
delIf403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
delIf403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
delIf403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
delIf403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
delIf403urn:funcd:problem:forbiddenThe Function does not own the table, no RolesAssignment makes it a writer, or a Policy forbids the write.Write from the table's owner, or grant the Function kv::write with a RolesAssignment, such as the KV Data Writer role.
delIf413urn:funcd:problem:payload-too-largeThe key is longer than the longest key that any store can hold.Use a shorter key.
delIf503urn:funcd:problem:unavailableThe KV driver that funcd runs with offers no versioned reads or conditional writes.Run funcd with a KV driver that offers them, as its memory and Badger drivers do.
list403urn:funcd:problem:forbiddenThe calling Function no longer exists, so it binds no table.Call from a Function that exists; a deleted Function's worker stops.
list403urn:funcd:problem:forbiddenThe Function's spec.bindings.kv has no entry for the alias.Add the binding to spec.bindings.kv, or call an alias that the Function binds.
list403urn:funcd:problem:forbiddenThe binding names a KVStore that does not exist.Create the KVStore, or bind one that exists.
list403urn:funcd:problem:forbiddenThe binding names a table that its KVStore does not declare.Add the table to the KVStore's spec.tables, or bind a table that it declares.
list403urn:funcd:problem:forbiddenA Policy forbids the Function to read the table.Change or remove the Policy that forbids kv::read on the table.

HTTP API

The table lists each described operation of these kinds, with its method and path. The operation's page in the API reference gives its parameters, its body, its authentication and every answer, with when it happens and what to do.

MethodPathOperation
GET/apis/funcd.io/v1alpha1/namespaces/{namespace}/kvstoresList the KVStores of a namespace
POST/apis/funcd.io/v1alpha1/namespaces/{namespace}/kvstoresCreate a KVStore
GET/apis/funcd.io/v1alpha1/namespaces/{namespace}/kvstores/{name}Read a KVStore
PUT/apis/funcd.io/v1alpha1/namespaces/{namespace}/kvstores/{name}Replace a KVStore
DELETE/apis/funcd.io/v1alpha1/namespaces/{namespace}/kvstores/{name}Delete a KVStore
POST/apis/funcd.io/v1alpha1/namespaces/{namespace}/kvstores/{name}/handoverHand a kept KVStore over to a Workflow

On this page