Documentation
¶
Overview ¶
Package quota is the storage quota framework (ADR-0292): one decision point, Checker, that every capped storage write asks before it stores, as every PEP asks the one Cedar PDP (internal/auth). Book implements it over the Sources each store kind registers; None admits everything and is every enforcement point's default.
Index ¶
Constants ¶
const Unknown int64 = -1
Unknown is the Bytes of a write whose size is known only once it ran, a SQL Execute: it needs room left under the limit, and once stored on a capped subject it starts a measure.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book is the Checker over the registered Sources. Usage is the last measure plus the bytes settled since and the bytes reserved in flight, so for a write of known size it never counts less than the store holds.
func (*Book) Refresh ¶
Refresh reads every subject's limit and usage again, as Run does each refreshInterval, and drops those unused for idleAfter.
type Checker ¶
type Checker interface {
// Admit reserves r.Bytes, or refuses with fault.InsufficientStorage when the write would pass the limit.
Admit(ctx context.Context, r Request) (Settle, error)
}
Checker is the quota counterpart of auth.Authorizer: Admit before a write, the returned Settle after it.
var None Checker = none{}
None admits every write.
type Request ¶
type Request struct {
Subject Subject
// Bytes is the write's size, or Unknown.
Bytes int64
// Replaces is the size the write overwrites, asked only before a refusal; nil is 0. It is credited to the
// decision, never to the count, since a concurrent delete can make it wrong.
Replaces func(ctx context.Context) (int64, error)
// Deletes marks a write that only deletes: always admitted, never measured for; once stored, the subject's next
// refusal waits on a fresh measure, so the room it made counts at once.
Deletes bool
}
Request is one write a Checker decides.
type Settle ¶
type Settle func(stored bool)
Settle ends an admitted write: stored turns its reservation into settled bytes, false releases it. Call it once.