mongo

package
v1.10.4 Latest Latest
Warning

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

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

README

MongoDB optimization storage

Pass an open Grove MongoDB connection to mongo.New(db) and call Migrate(ctx) before accepting work. You need a deployment that supports snapshot transactions, such as a replica set. Migration performs a real transactional query and refuses a standalone server. Closing the store closes the connection you supplied.

Each update writes an exact-scope fence before reading state. A competing worker receives ErrConflict if it cannot acquire that fence, without entering its callback. The adapter never replays a callback. Transactions explicitly use primary reads, snapshot isolation and majority writes, even when your host uses another default read preference.

If commit acknowledgment fails, the adapter returns ErrUnavailable. That error does not establish whether the commit happened. Your service must reconcile the persisted operation identities before deciding whether another attempt is safe.

Record metadata and body chunks commit together. Bodies use chunks of at most 4 MiB, so a valid encoded record can exceed MongoDB's single-document limit. Replacement checks the previous digest and removes superseded chunks in the same transaction. Reads use one snapshot across the metadata and chunk collections, then verify chunk identities, order, sizes, scope and the reconstructed content digest before applying the shared storage rules.

Migration creates the scope collection before accepting work. Creating it inside the first transaction would let competing transactions use different catalog snapshots, defeating the scope fence. Concurrent migrations are supported; unknown schema versions refuse startup.

The tests start real MongoDB containers and fail if Docker is unavailable. You can select a compatible image with CORTEX_TEST_MONGO_IMAGE. Coverage includes standalone refusal, concurrent startup, independent connections, subprocess lease takeover, a 17 MiB record, corrupt or missing chunks, rollback after a database write failure and retries with record writes forbidden.

One store instance can serve independent scopes concurrently. Migration and close wait for active operations before accessing the connection exclusively. Single-resource getters query the exact record identity and only its body chunks. They read at most the expected chunk count plus one, so extra chunks are detected without loading other records. Metadata and content still come from one snapshot. Lists, current eligibility checks and mutations load the complete exact scope. Bounded database pagination, selective transaction loading, artifact retention and throughput qualification remain open. These storage checks do not qualify the optimizer's runtime or production activation path.

Documentation

Overview

Package mongo persists optimization records in MongoDB snapshot transactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct{ *state.Store }

Store uses the shared optimization rules with MongoDB transaction fencing.

func New

func New(db *grove.DB) *Store

New binds an open Grove MongoDB connection. Migrate verifies transaction support before the host accepts work; standalone servers are unsupported.

Jump to

Keyboard shortcuts

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