Documentation
¶
Overview ¶
Package resultstream provides durable, position-addressed result streams.
Index ¶
- Constants
- Variables
- func BindRetainedBytesGrowthGuard(stream Stream, guard func() bool)
- func WithDelivery(ctx context.Context, delivery *Delivery) context.Context
- type Config
- type DatabaseRegistry
- type Delivery
- type ExpandFunc
- type Observer
- type Page
- type PageSizeExceededError
- type Progressive
- type Registry
- func (r *Registry) BindScope(scope Scope) Scope
- func (r *Registry) Close()
- func (r *Registry) Discard(scope Scope, qid string) error
- func (r *Registry) DiscardDatabase(database string)
- func (r *Registry) ForDatabase(database string) *DatabaseRegistry
- func (r *Registry) MaxPageSize() int
- func (r *Registry) Pull(ctx context.Context, scope Scope, qid string, n int) (*Page, error)
- func (r *Registry) ResolveDatabase(owner, qid, requested string) (string, error)
- func (r *Registry) SetObserver(observer Observer)
- func (r *Registry) Start(ctx context.Context, scope Scope, stream Stream, n int) (*Page, error)
- type RetainedBytesGrowthGuard
- type RetainedBytesReporter
- type Scope
- type Stream
- type ValidityChecker
Constants ¶
const DefaultMaxPageSize = config.DefaultSearchCursorMaxPageSize
DefaultMaxPageSize is the maximum continuation page size unless configured.
Variables ¶
var ( ErrInvalidQID = errors.New("invalid result stream qid") ErrExpiredQID = errors.New("result stream qid expired") ErrGoneQID = errors.New("result stream qid no longer exists") ErrCapacity = errors.New("result stream capacity exceeded") ErrDisabled = errors.New("result stream continuation is disabled") ErrInvalidScope = errors.New("invalid result stream scope") )
Functions ¶
func BindRetainedBytesGrowthGuard ¶
BindRetainedBytesGrowthGuard forwards growth accounting through a decorator.
Types ¶
type Config ¶
type Config struct {
Disabled bool
TTL time.Duration
MaxStreams int64
MaxStreamsPerOwner int64
MaxPageSize int
MaxRetainedBytes int64
MaxRetainedBytesPerOwner int64
}
Config bounds process-local durable result streams.
type DatabaseRegistry ¶
type DatabaseRegistry struct {
*Registry
// contains filtered or unexported fields
}
DatabaseRegistry binds a database-scoped service to its current lifetime. It delegates all accounting and stream termination to the one Registry.
func (*DatabaseRegistry) BindScope ¶
func (r *DatabaseRegistry) BindScope(scope Scope) Scope
type Delivery ¶
type Delivery struct {
// contains filtered or unexported fields
}
Delivery owns pages that have not reached their transport. Fork separates statement batches on one connection; a successful metadata write cannot acknowledge another batch's records. The zero value is ready to use.
func DeliveryFromContext ¶
DeliveryFromContext returns the batch attached to this operation.
func (*Delivery) Delivered ¶
func (d *Delivery) Delivered()
Delivered acknowledges a complete response or statement result.
func (*Delivery) DeliveredWritten ¶
func (d *Delivery) DeliveredWritten()
DeliveredWritten acknowledges only references emitted in a completed response. Fail still retires any produced page omitted by projection/field selection.
func (*Delivery) DiscardEncoded ¶
DiscardEncoded retires references in a complete record selected by DISCARD. The transport uses its canonical encoder, covering every supported value type and references carried inside serialized text without inspecting Go shapes.
func (*Delivery) Fail ¶
func (d *Delivery) Fail()
Fail retires every undelivered page, including publication after failure.
func (*Delivery) Fork ¶
Fork scopes a statement's acknowledgement while retaining connection failure ownership. Empty batches never join the parent's pending set.
func (*Delivery) ObserveWritten ¶
ObserveWritten records qid references in successfully written response bytes. Signed qids use unescaped base64url text. A bounded suffix covers references split across writes without retaining the response body. This does not yet acknowledge delivery: the transport must complete its final flush first.
type ExpandFunc ¶
ExpandFunc returns the complete ranked prefix available at depth. The returned prefix must preserve every previously returned row at its index.
type Page ¶
type Page struct {
Rows [][]any
QID string
Position uint64
Next uint64
// HasMore includes unfinished progressive retrieval. It does not guarantee
// that the next page is nonempty.
HasMore bool
Total *uint64
ExpiresAt time.Time
Metadata map[string]any
}
Page is one stream position. Its rows and nested values are independently mutable by the caller; changes do not affect retained rows or later pulls.
type PageSizeExceededError ¶
type PageSizeExceededError struct {
*localization.LocalizedError
MaxPageSize int
}
PageSizeExceededError distinguishes an oversized page from malformed input. It retains ErrInvalidPageSize identity for existing embedded callers.
func (*PageSizeExceededError) BoltErrorCode ¶
func (e *PageSizeExceededError) BoltErrorCode() string
BoltErrorCode exposes the argument status through the shared status mapper.
func (*PageSizeExceededError) Unwrap ¶
func (e *PageSizeExceededError) Unwrap() error
Unwrap preserves the localized status as well as ErrInvalidPageSize.
type Progressive ¶
type Progressive struct {
// contains filtered or unexported fields
}
Progressive grows a replayable row prefix only when buffered rows cannot satisfy a pull. Expansion work runs without registry locks.
func NewProgressive ¶
func NewProgressive(initial [][]any, exhausted bool, initialDepth int, expand ExpandFunc) (*Progressive, error)
NewProgressive constructs a progressively expandable stream.
func (*Progressive) Close ¶
func (s *Progressive) Close() error
Close releases references retained by the stream.
func (*Progressive) Pull ¶
Pull returns a full ready page immediately. Expansion runs only when the requested page is not yet available; HasMore includes unfinished population.
func (*Progressive) SetRetainedBytesGrowthGuard ¶
func (s *Progressive) SetRetainedBytesGrowthGuard(growthOK func() bool)
SetRetainedBytesGrowthGuard installs admission checked before expansion is published. It is intended for the owning registry.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry owns signed qids and sharded process-local stream entries.
func NewRegistry ¶
NewRegistry constructs a registry with a random signing key and instance ID.
func (*Registry) BindScope ¶
BindScope captures the database lifetime before a producer prepares its first page. DiscardDatabase invalidates this binding and serializes publication.
func (*Registry) Close ¶
func (r *Registry) Close()
Close releases every retained stream and rejects future operations.
func (*Registry) Discard ¶
Discard releases the complete stream addressed by any of its qids. Repeating it after any terminal outcome succeeds; signed scope checks still apply.
func (*Registry) DiscardDatabase ¶
DiscardDatabase releases all cursors belonging to a reset or dropped database. Other databases using the shared registry are unaffected.
func (*Registry) ForDatabase ¶
func (r *Registry) ForDatabase(database string) *DatabaseRegistry
ForDatabase captures the service's database lifetime, including before its first search. A reset/drop therefore also retires unpublished old-service work.
func (*Registry) MaxPageSize ¶
MaxPageSize reports the effective limit enforced by this registry.
func (*Registry) Pull ¶
Pull resolves a signed qid and invokes the stream without holding a registry shard lock.
func (*Registry) ResolveDatabase ¶
ResolveDatabase authenticates a qid's owner and database binding, including after its stream ends. Pull checks liveness; Discard remains idempotent.
func (*Registry) SetObserver ¶
SetObserver replaces the optional lifecycle observer.
type RetainedBytesGrowthGuard ¶
type RetainedBytesGrowthGuard interface {
SetRetainedBytesGrowthGuard(func() bool)
}
RetainedBytesGrowthGuard allows a registry to approve retained growth before an expanding stream publishes its new replayable population.
type RetainedBytesReporter ¶
type RetainedBytesReporter interface {
RetainedBytes() int64
}
RetainedBytesReporter optionally reports memory retained for future pulls.
type Stream ¶
type Stream interface {
Pull(ctx context.Context, position uint64, n int) (*Page, error)
Close() error
}
Stream returns deterministic pages for explicit positions. Implementations must permit concurrent and repeated Pull calls.
type ValidityChecker ¶
type ValidityChecker interface {
CheckValid() error
}
ValidityChecker lets the registry retire invalidated, abandoned streams during periodic cleanup or before rejecting a new admission for capacity.