mem_store

package
v0.0.0-...-c6fdc5f Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package index provides the in-memory index implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexKey

func IndexKey(pattern, templateID string) string

IndexKey generates the index map key from pattern and templateID.

Types

type Database

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

Database represents an isolated index namespace for a database. It contains multiple indexes keyed by (pattern|templateID).

func NewDatabase

func NewDatabase(name string) *Database

NewDatabase creates a new database index container.

func (*Database) Clear

func (d *Database) Clear()

Clear removes all indexes from the database.

func (*Database) DeleteIndex

func (d *Database) DeleteIndex(pattern, templateID string)

DeleteIndex removes an index from the database.

func (*Database) GetIndex

func (d *Database) GetIndex(pattern, templateID string) *Index

GetIndex returns an index by its key, or nil if not found.

func (*Database) GetOrCreateIndex

func (d *Database) GetOrCreateIndex(pattern, templateID, rawPattern string) *Index

GetOrCreateIndex returns an existing index or creates a new one.

func (*Database) IndexCount

func (d *Database) IndexCount() int

IndexCount returns the number of indexes in the database.

func (*Database) ListIndexes

func (d *Database) ListIndexes() []store.IndexInfo

ListIndexes returns metadata for all indexes in the database.

type DocRef

type DocRef struct {
	ID       string // Document ID within the collection
	OrderKey []byte // Encoded sort key
}

DocRef represents a document reference with its OrderKey.

type Index

type Index struct {
	Pattern    string // Normalized pattern (e.g., "users/*/chats")
	TemplateID string // Template identity (name or fields signature)
	RawPattern string // Original pattern (e.g., "users/{uid}/chats")
	// contains filtered or unexported fields
}

Index represents an index for a specific (pattern, templateID) pair. It maintains a btree for ordered iteration and a ByID map for O(1) lookups.

func NewIndex

func NewIndex(pattern, templateID, rawPattern string) *Index

NewIndex creates a new index.

func (*Index) Clear

func (idx *Index) Clear()

Clear removes all documents from the index.

func (*Index) Delete

func (idx *Index) Delete(id string)

Delete removes a document from the index.

func (*Index) Get

func (idx *Index) Get(id string) []byte

Get returns the OrderKey for a document by ID. Returns nil if the document is not indexed.

func (*Index) IsHealthy

func (idx *Index) IsHealthy() bool

IsHealthy returns true if the index is in healthy state.

func (*Index) Len

func (idx *Index) Len() int

Len returns the number of documents in the index.

func (*Index) Search

func (idx *Index) Search(opts SearchOptions) []DocRef

Search returns documents within the specified bounds. Results are returned in OrderKey order.

func (*Index) SetState

func (idx *Index) SetState(state State)

SetState sets the state of the index.

func (*Index) State

func (idx *Index) State() State

State returns the current state of the index.

func (*Index) Upsert

func (idx *Index) Upsert(id string, orderKey []byte)

Upsert inserts or updates a document in the index. If the document already exists, it removes the old entry first.

type SearchOptions

type SearchOptions struct {
	Lower      []byte // Lower bound (inclusive)
	Upper      []byte // Upper bound (exclusive, nil means no upper bound)
	StartAfter []byte // Cursor for pagination (exclusive)
	Limit      int    // Max results to return
}

SearchOptions configures a search operation.

type State

type State int

State represents the current state of an index.

const (
	StateHealthy    State = iota // Index is up-to-date and serving queries
	StateRebuilding              // Index is being rebuilt, queries fall back
	StateFailed                  // Index failed, needs manual intervention
)

func (State) String

func (s State) String() string

String returns the state name.

type Store

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

Store implements store.Store interface using in-memory data structures.

func New

func New() *Store

New creates a new in-memory Store.

func (*Store) ApplyDocumentProjection

func (s *Store) ApplyDocumentProjection(replacements []store.Projection, progress string) error

func (*Store) Close

func (s *Store) Close() error

Close is a no-op for memory store.

func (*Store) Delete

func (s *Store) Delete(db, pattern, tmplID, docID string, progress string) error

Delete removes a document from the index.

func (*Store) DeleteDatabase

func (s *Store) DeleteDatabase(db string) error

DeleteDatabase removes all indexes for a database.

func (*Store) DeleteIndex

func (s *Store) DeleteIndex(db, pattern, tmplID string) error

DeleteIndex removes all data for an index.

func (*Store) DeleteQueryIndex

func (s *Store) DeleteQueryIndex(ref store.QueryIndexRef) error

func (*Store) Flush

func (s *Store) Flush() error

Flush is a no-op for memory store.

func (*Store) Get

func (s *Store) Get(db, pattern, tmplID, docID string) ([]byte, bool)

Get returns the OrderKey for a document by ID.

func (*Store) GetState

func (s *Store) GetState(db, pattern, tmplID string) (store.IndexState, error)

GetState returns the state of an index.

func (*Store) IsDatabaseRetired

func (s *Store) IsDatabaseRetired(db string) (bool, error)

func (*Store) ListBootstrapCatalogs

func (s *Store) ListBootstrapCatalogs() ([]store.BootstrapCatalog, error)

func (*Store) ListDatabases

func (s *Store) ListDatabases() ([]string, error)

ListDatabases returns all database names.

func (*Store) ListIndexes

func (s *Store) ListIndexes(db string) ([]store.IndexInfo, error)

ListIndexes returns metadata for all indexes in a database.

func (*Store) ListQueryIndexes

func (s *Store) ListQueryIndexes() ([]store.QueryIndexRef, error)

func (*Store) LoadProgress

func (s *Store) LoadProgress() (string, error)

LoadProgress loads the event processing progress.

func (*Store) PublishBootstrapCatalog

func (s *Store) PublishBootstrapCatalog(catalog store.BootstrapCatalog) error

func (*Store) PublishBootstrapCatalogs

func (s *Store) PublishBootstrapCatalogs(catalogs []store.BootstrapCatalog, progress string) error

func (*Store) PublishGeneration

func (s *Store) PublishGeneration(ref store.QueryIndexRef, progress string) error

func (*Store) ReadBootstrapCatalog

func (s *Store) ReadBootstrapCatalog(database string) (store.BootstrapCatalog, bool, error)

func (*Store) ReadGeneration

func (s *Store) ReadGeneration(db, collection, fingerprint string) (store.Generation, bool, error)

func (*Store) ReadView

func (s *Store) ReadView(ctx context.Context, ref store.QueryIndexRef, budget store.ReadBudget) (store.ReadView, error)

func (*Store) Search

func (s *Store) Search(db, pattern, tmplID string, opts store.SearchOptions) ([]store.DocRef, error)

Search returns documents within the specified bounds.

func (*Store) SetFailure

func (s *Store) SetFailure(ref store.QueryIndexRef, failure string) error

func (*Store) SetState

func (s *Store) SetState(db, pattern, tmplID string, state store.IndexState) error

SetState sets the state of an index.

func (*Store) Upsert

func (s *Store) Upsert(db, pattern, tmplID, docID string, orderKey []byte, progress string) error

Upsert inserts or updates a document in the index.

Jump to

Keyboard shortcuts

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