memory

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package memory provides an in-memory implementation of the Weave composite store. Suitable for testing and development.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is an in-memory implementation of the composite Weave store. Every data method scopes to the context tenant: another tenant's row is missing, exactly like an unknown ID.

func New

func New() *Store

New creates a new in-memory store.

func (*Store) Close

func (s *Store) Close() error

Close is a no-op for the in-memory store.

func (*Store) CompleteDocument

func (s *Store) CompleteDocument(ctx context.Context, docID id.DocumentID, chunkCount int) error

CompleteDocument moves a processing document to ready under the store mutex.

func (*Store) CountChunks

func (s *Store) CountChunks(ctx context.Context, filter *chunk.CountFilter) (int64, error)

CountChunks returns the count of chunks matching the filter.

func (*Store) CountCollections

func (s *Store) CountCollections(ctx context.Context, filter *collection.CountFilter) (int64, error)

CountCollections returns the count of collections matching the filter.

func (*Store) CountDocuments

func (s *Store) CountDocuments(ctx context.Context, filter *document.CountFilter) (int64, error)

CountDocuments returns the count of documents matching the filter.

func (*Store) CountStalledUntenanted

func (s *Store) CountStalledUntenanted(_ context.Context, before time.Time) (int64, error)

CountStalledUntenanted counts the stalled rows with an empty tenant.

func (*Store) CreateChunkBatch

func (s *Store) CreateChunkBatch(ctx context.Context, chunks []*chunk.Chunk) error

CreateChunkBatch persists a batch of chunks. Every chunk must belong to the context tenant and to a document of that tenant, with the document's collection, and its ID must be new. Any chunk that fails refuses the whole batch before anything is written, as the SQL backends' single INSERT does.

func (*Store) CreateCollection

func (s *Store) CreateCollection(ctx context.Context, col *collection.Collection) error

CreateCollection persists a new collection.

func (*Store) CreateDocument

func (s *Store) CreateDocument(ctx context.Context, doc *document.Document) error

CreateDocument persists a new document. Its collection must belong to the context tenant, else ErrCollectionNotFound.

func (*Store) DeleteChunksByCollection

func (s *Store) DeleteChunksByCollection(ctx context.Context, colID id.CollectionID) error

DeleteChunksByCollection removes all chunks for a collection.

func (*Store) DeleteChunksByDocument

func (s *Store) DeleteChunksByDocument(ctx context.Context, docID id.DocumentID) error

DeleteChunksByDocument removes all chunks for a document.

func (*Store) DeleteCollection

func (s *Store) DeleteCollection(ctx context.Context, colID id.CollectionID) error

DeleteCollection removes a collection by ID with cascading deletes.

func (*Store) DeleteDocument

func (s *Store) DeleteDocument(ctx context.Context, docID id.DocumentID) error

DeleteDocument removes a document by ID with cascading chunk deletes.

func (*Store) DeleteDocumentsByCollection

func (s *Store) DeleteDocumentsByCollection(ctx context.Context, colID id.CollectionID) error

DeleteDocumentsByCollection removes all documents in a collection.

func (*Store) FailDocument

func (s *Store) FailDocument(ctx context.Context, docID id.DocumentID, errText string, staleBefore time.Time) error

FailDocument marks a pending or processing document failed under the store mutex.

func (*Store) GetChunk

func (s *Store) GetChunk(ctx context.Context, chunkID id.ChunkID) (*chunk.Chunk, error)

GetChunk retrieves a chunk by ID.

func (*Store) GetCollection

func (s *Store) GetCollection(ctx context.Context, colID id.CollectionID) (*collection.Collection, error)

GetCollection retrieves a collection by ID.

func (*Store) GetCollectionByName

func (s *Store) GetCollectionByName(ctx context.Context, tenantID, name string) (*collection.Collection, error)

GetCollectionByName retrieves a collection by tenant and name. tenantID must equal the context tenant.

func (*Store) GetDocument

func (s *Store) GetDocument(ctx context.Context, docID id.DocumentID) (*document.Document, error)

GetDocument retrieves a document by ID.

func (*Store) ListChunks

func (s *Store) ListChunks(ctx context.Context, filter *chunk.ListFilter) ([]*chunk.Chunk, error)

ListChunks returns chunks matching the filter, ordered by document then index.

func (*Store) ListChunksByDocument

func (s *Store) ListChunksByDocument(ctx context.Context, docID id.DocumentID) ([]*chunk.Chunk, error)

ListChunksByDocument returns all chunks for a document, ordered by index.

func (*Store) ListCollections

func (s *Store) ListCollections(ctx context.Context, filter *collection.ListFilter) ([]*collection.Collection, error)

ListCollections returns collections matching the given filter.

func (*Store) ListDocuments

func (s *Store) ListDocuments(ctx context.Context, filter *document.ListFilter) ([]*document.Document, error)

ListDocuments returns documents matching the given filter.

func (*Store) ListStalledDocuments

func (s *Store) ListStalledDocuments(_ context.Context, before time.Time, limit int) ([]*document.Document, error)

ListStalledDocuments lists, across tenants, the pending, processing and superseded documents last updated before before, oldest first.

func (*Store) Migrate

func (s *Store) Migrate(_ context.Context) error

Migrate is a no-op for the in-memory store.

func (*Store) Ping

func (s *Store) Ping(_ context.Context) error

Ping is a no-op for the in-memory store.

func (*Store) ReplaceSourceDocument

func (s *Store) ReplaceSourceDocument(ctx context.Context, doc *document.Document, chunks []*chunk.Chunk) ([]id.DocumentID, error)

ReplaceSourceDocument supersedes the source's ready and failed documents, swaps their chunks for chunks and makes doc ready, all under the store mutex. Everything is checked before the first change, so a refused call leaves the store as it was.

func (*Store) TouchDocument

func (s *Store) TouchDocument(ctx context.Context, docID id.DocumentID, staleBefore time.Time) error

TouchDocument records an ingest's heartbeat under the store mutex, so of several claims of one stalled document only the first finds it stalled.

func (*Store) UpdateCollection

func (s *Store) UpdateCollection(ctx context.Context, col *collection.Collection) error

UpdateCollection persists changes to an existing collection.

func (*Store) UpdateDocument

func (s *Store) UpdateDocument(ctx context.Context, doc *document.Document) error

UpdateDocument persists changes to an existing document.

Jump to

Keyboard shortcuts

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