resultstream

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resultstream provides durable, position-addressed result streams.

Index

Constants

View Source
const DefaultMaxPageSize = 500

DefaultMaxPageSize is the maximum continuation page size unless configured.

Variables

View Source
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")
)
View Source
var (
	ErrClosed          = errors.New("result stream is closed")
	ErrInvalidPageSize = errors.New("invalid result stream page size")
	ErrInvalidPosition = errors.New("invalid result stream position")
	ErrInvalidated     = errors.New("result stream was invalidated by a data or policy change")
)

Functions

func BindRetainedBytesGrowthGuard

func BindRetainedBytesGrowthGuard(stream Stream, guard func() bool)

BindRetainedBytesGrowthGuard forwards growth accounting through a decorator.

func WithDelivery

func WithDelivery(ctx context.Context, delivery *Delivery) context.Context

WithDelivery attaches transport delivery ownership to stream operations.

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

func (*DatabaseRegistry) Start

func (r *DatabaseRegistry) Start(ctx context.Context, scope Scope, stream Stream, n int) (*Page, error)

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

func DeliveryFromContext(ctx context.Context) *Delivery

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

func (d *Delivery) DiscardEncoded(data []byte)

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

func (d *Delivery) Fork() *Delivery

Fork scopes a statement's acknowledgement while retaining connection failure ownership. Empty batches never join the parent's pending set.

func (*Delivery) ObserveWritten

func (d *Delivery) ObserveWritten(data []byte) bool

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.

func (*Delivery) Pending

func (d *Delivery) Pending() bool

Pending reports whether this response still owns undelivered pages.

type ExpandFunc

type ExpandFunc func(ctx context.Context, depth int) (rows [][]any, exhausted bool, err error)

ExpandFunc returns the complete ranked prefix available at depth. The returned prefix must preserve every previously returned row at its index.

type Observer

type Observer interface {
	CursorEvent(outcome string)
	CursorUsage(active, retainedBytes int64)
}

Observer receives bounded cursor lifecycle and aggregate usage signals.

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 an immutable view of one stream position. Rows must be treated as read-only by adapters.

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

func (s *Progressive) Pull(ctx context.Context, position uint64, n int) (*Page, error)

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

func NewRegistry(config Config) (*Registry, error)

NewRegistry constructs a registry with a random signing key and instance ID.

func (*Registry) BindScope

func (r *Registry) BindScope(scope Scope) Scope

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

func (r *Registry) Discard(scope Scope, qid string) error

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

func (r *Registry) DiscardDatabase(database string)

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

func (r *Registry) MaxPageSize() int

MaxPageSize reports the effective limit enforced by this registry.

func (*Registry) Pull

func (r *Registry) Pull(ctx context.Context, scope Scope, qid string, n int) (*Page, error)

Pull resolves a signed qid and invokes the stream without holding a registry shard lock.

func (*Registry) ResolveDatabase

func (r *Registry) ResolveDatabase(owner, qid, requested string) (string, error)

ResolveDatabase authenticates a qid's owner and database binding, including after its stream ends. Pull checks liveness; Discard remains idempotent.

func (*Registry) SetObserver

func (r *Registry) SetObserver(observer Observer)

SetObserver replaces the optional lifecycle observer.

func (*Registry) Start

func (r *Registry) Start(ctx context.Context, scope Scope, stream Stream, n int) (*Page, error)

Start returns the first page and publishes the stream only when more rows are available.

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 Scope

type Scope struct {
	Owner    string
	Database string
	// contains filtered or unexported fields
}

Scope binds a stream to one authenticated owner and canonical database.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL