schemareindex

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package schemareindex runs the automatic reindex that follows an index schema change, as a paced background job rather than a startup step.

Reindexing used to run inline during coordinator startup under the shared maintenance deadline. A store large enough to exceed that deadline could never converge: the new schema hash is only recorded after a complete pass, and each restart began the scan again from the first entity, so the same prefix was reindexed forever and the tail was never reached. Running here instead, with a cursor persisted between bounded passes, means progress accumulates until the scan genuinely finishes — and it converges without needing a restart at all, which a cursor alone would not give us.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// IdleInterval is how long to wait between checks when the store already
	// matches the current index schema and there is nothing to do.
	IdleInterval time.Duration
	// ActiveInterval is how long to wait between passes while a reindex is in
	// flight. Much shorter than IdleInterval so a pending reindex drains at a
	// reasonable clip instead of one pass per idle check.
	ActiveInterval time.Duration
	// MaxEntitiesPerPass caps how many entities one pass processes before it
	// checkpoints and yields. Zero means unbounded, which defeats the purpose
	// here; the controller substitutes the default.
	MaxEntitiesPerPass int
	// BatchPause is slept periodically during a pass to rate-limit write
	// pressure. Zero disables pacing.
	BatchPause time.Duration
	// PassTimeout bounds a single pass. A pass cut short still checkpoints its
	// cursor, so the next one picks up where it stopped.
	PassTimeout time.Duration
}

Config tunes the background reindex. Defaults are gentle: this is convergence insurance running behind a correct write path, not a foreground repair, so it trades wall-clock for staying out of the way.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default (gentle) configuration.

type Controller

type Controller struct {
	Log   *slog.Logger
	Store *entity.EtcdStore
	// CurrentHash returns the index schema hash of the running binary,
	// injected rather than called directly because the schema registry sits
	// above the entity package.
	CurrentHash func() string
	Config      Config
	// contains filtered or unexported fields
}

Controller reindexes the entity store in the background whenever the running index schema differs from the one the store was last reindexed against. It works directly against the EtcdStore rather than the entity-access client, since it operates below the index it is repairing.

The coordinator is a singleton, so there is no second writer racing the cursor or the hash; the state here needs no locking beyond etcd itself.

func (*Controller) Start

func (c *Controller) Start(ctx context.Context)

Start begins the background reindex loop.

func (*Controller) Stop

func (c *Controller) Stop()

Stop gracefully stops the controller.

Jump to

Keyboard shortcuts

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