kv: per-namespace item quota (max_items), per-tenant under isolation - #59
Merged
Conversation
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>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #58 (tenant isolation).
Opt-in
max_itemscap on kv namespaces, enforced in the driver against the tenant-qualified storage namespace — so withtenant_isolationon it becomes a per-tenant quota. APutadding a new key past the cap →ResourceExhausted; overwrites always allowed;Deletefrees a slot. Never evicts.config.NamespaceConfig.max_items(kv-only, validated); service mapsErrQuotaExceeded → ResourceExhaustedQuotaconformance case (both drivers; verified on real Postgres) + service-level single/per-tenant tests🤖 Generated with Claude Code