Skip to content

kv: per-namespace item quota (max_items), per-tenant under isolation - #59

Merged
mkorbi merged 1 commit into
feat/tenant-isolationfrom
feat/tenant-quota
Jul 28, 2026
Merged

kv: per-namespace item quota (max_items), per-tenant under isolation#59
mkorbi merged 1 commit into
feat/tenant-isolationfrom
feat/tenant-quota

Conversation

@mkorbi

@mkorbi mkorbi commented Jul 25, 2026

Copy link
Copy Markdown
Member

Stacked on #58 (tenant isolation).

Opt-in max_items cap on kv namespaces, enforced in the driver against the tenant-qualified storage namespace — so with tenant_isolation on it becomes a per-tenant quota. A Put adding a new key past the cap → ResourceExhausted; overwrites always allowed; Delete frees a slot. Never evicts.

  • memory + postgres drivers enforce atomically on new-key writes (pg counts inside the write tx → soft ceiling under concurrency)
  • config.NamespaceConfig.max_items (kv-only, validated); service maps ErrQuotaExceeded → ResourceExhausted
  • kvtest Quota conformance case (both drivers; verified on real Postgres) + service-level single/per-tenant tests
  • docs

🤖 Generated with Claude Code

Add an opt-in live-key cap to kv namespaces. A Put that would add a NEW
key past the cap is rejected with ResourceExhausted; overwriting an
existing key is always allowed and Delete frees a slot. Unlike the
in-memory cache-tier `capacity` policy, this never evicts — it refuses
the write.

The cap is enforced in the driver against the stored (tenant-qualified)
namespace, so with tenant_isolation on it becomes a per-tenant quota:
each tenant gets its own allowance over a shared namespace name.

- kv.PutOptions.MaxItems + kv.ErrQuotaExceeded sentinel
- memory + postgres drivers enforce atomically on new-key writes
  (postgres counts live rows inside the write tx; soft ceiling under
  concurrency)
- config.NamespaceConfig.max_items (kv-only, >= 0) with validation
- kv service maps ErrQuotaExceeded -> ResourceExhausted, plumbs a
  per-namespace quota map; server.Deps.KVQuotas built in main from config
- kvtest conformance Quota case (runs on both drivers; verified on real
  Postgres) + service-level single-tenant and per-tenant quota tests
- docs: kv block max_items section + config reference + example.yaml

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mkorbi
mkorbi merged commit 38178d2 into feat/tenant-isolation Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant