document

package
v1.0.36 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package document provides bounded, document-level routing for MoveRGA sequences. It deliberately does not define another replication wire format: applications authenticate and authorize a document ID before selecting the corresponding, separately negotiated MoveRGA stream.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilManager        = errors.New("document: nil manager")
	ErrInvalidDocumentID = errors.New("document: invalid document ID")
	ErrDocumentExists    = errors.New("document: document already exists")
	ErrDocumentNotFound  = errors.New("document: document not found")
	ErrResourceLimit     = errors.New("document: resource limit exceeded")
)

Functions

This section is empty.

Types

type DocManager

type DocManager[T any] struct {
	// contains filtered or unexported fields
}

DocManager owns a fixed, explicitly created set of MoveRGA documents. It never creates a document while applying a remote delta: otherwise a peer could turn arbitrary document IDs into unbounded retained state.

The manager lock only protects the registry. Each returned MoveRGA has its own lock, so operations on different documents do not serialize globally.

func NewDocManager

func NewDocManager[T any](codec list.ElementCodec[T], options Options) (*DocManager[T], error)

NewDocManager creates an empty document registry. It validates the shared codec and per-document options up front, so an invalid manager cannot become partially populated before its first CreateDocument call fails.

func (*DocManager[T]) ApplyDelta

func (m *DocManager[T]) ApplyDelta(id string, delta list.MoveDelta) error

ApplyDelta routes one already-decoded MoveRGA delta to an existing document. Transport-facing callers must decode with list.UnmarshalMoveDeltaWithLimits and complete authentication/authorization before calling this method.

func (*DocManager[T]) CreateDocument

func (m *DocManager[T]) CreateDocument(id, replicaID string) (*list.MoveRGA[T], error)

CreateDocument creates a locally authorized document with its own HLC replica ID. Call it on every replica before accepting deltas for that document. Reusing one logical replica ID after a restart requires restoring the document's clock together with its complete snapshot.

func (*DocManager[T]) Delete

func (m *DocManager[T]) Delete(id string, offset, count int) (list.MoveDelta, error)

Delete routes a local deletion to an existing document.

func (*DocManager[T]) Document

func (m *DocManager[T]) Document(id string) (*list.MoveRGA[T], bool)

Document returns a document only when it was explicitly created. The returned CRDT remains independently concurrency-safe.

func (*DocManager[T]) DocumentIDs

func (m *DocManager[T]) DocumentIDs() []string

DocumentIDs returns a sorted copy so callers can enumerate a stable view without gaining access to the manager's map.

func (*DocManager[T]) Insert

func (m *DocManager[T]) Insert(id string, offset int, values []T) (list.MoveDelta, error)

Insert routes a local insertion to an existing document.

func (*DocManager[T]) Len

func (m *DocManager[T]) Len() int

Len reports the number of locally opened documents.

func (*DocManager[T]) Move

func (m *DocManager[T]) Move(id string, from, count, to int) (list.MoveDelta, error)

Move routes a local identity-preserving range move to an existing document. The destination offset is interpreted after the selected range is removed.

type Options

type Options struct {
	MaxDocuments       int
	MaxDocumentIDBytes int
	ListOptions        list.Options
}

Options bounds manager-owned document metadata. ListOptions applies to each individual document; it is intentionally not a shared global element budget. A replication service should choose both limits from its authenticated tenant and group policy rather than treating this manager as an authorization layer.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns conservative manager limits suitable for a single process. Production services should set limits appropriate to a tenant.

Jump to

Keyboard shortcuts

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