schemasync

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schemasync is a runner that synchronize database schemas.

Index

Constants

View Source
const (
	MaximumOutstanding = 100
)

Variables

View Source
var ErrDatabaseHidden = errors.New("the target no longer has this database; it has been hidden")

ErrDatabaseHidden reports that a database the caller asked to sync has been soft-deleted because the target no longer has it. The checker must not retry or escalate it — the row is history now — and the API maps it to NotFound.

View Source
var ErrOperationAbandoned = errors.New("the sync operation ended before reporting its result")

ErrOperationAbandoned is the cause recorded when a caller stops speaking for an operation that has not reported everything: a handler that returns between registering the operation and reporting its last result, or an operation whose databases never report before the deadline. The message is user-visible, so it explains itself.

Functions

This section is empty.

Types

type LineageQueue added in v0.1.2

type LineageQueue interface {
	QueueAnalysis(metaGUID string, metaType storepb.MetaType)
}

LineageQueue is the lineage analysis queue a schema sync feeds. The package depends on this narrow interface instead of the concrete analyzer in a sibling runner package; *lineageanalyzer.Analyzer satisfies it as is.

type LineageRevalidator

type LineageRevalidator interface {
	Trigger()
}

LineageRevalidator is signalled when a schema sync has added or changed metadata. Ingested lineage that named a relation the registry did not have is re-checked then, as soon as the relation appears, instead of at the next maintenance pass.

type Notifier

type Notifier interface {
	Send(ctx context.Context, message *storepb.Notification) error
	SendToWorkspaceAdmins(ctx context.Context, message *storepb.Notification) error
}

Notifier delivers the messages a sync operation produces. *notification.Service is the production implementation; the interface keeps the runner testable without a database.

type SyncOperation

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

SyncOperation is one user-visible sync operation: the instance metadata step plus every database that step queued.

The API registers it, the checker reports each database's outcome, and exactly one caller finishes it and writes the message. It is process state, like the queue it tracks: a restart loses the operations in flight, and so does it lose the syncs themselves.

type Syncer

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

Syncer is the schema syncer.

func NewSyncer

func NewSyncer(stores *store.Store, dbFactory *dbfactory.DBFactory, stateCfg *state.State, lineageQueue LineageQueue, lineageRevalidator LineageRevalidator, notifier Notifier) *Syncer

NewSyncer creates a schema syncer. notifier reports the outcome of a sync operation to the user who asked for it, and a background failure to the workspace administrators; a nil notifier leaves the runner silent, which is what its own tests want.

func (*Syncer) AbandonOperation added in v0.1.2

func (s *Syncer) AbandonOperation(ctx context.Context, operation *SyncOperation, cause error)

AbandonOperation reports that the caller stopped before it finished speaking for the operation, and seals the operation with that cause so it reaches the user now instead of expiring two hours later as a zero-count INFO success.

It is a no-op on the normal path: once the instance step has reported and the operation is sealed, its databases are simply still being synced and completing them is not an abandonment. Calling it twice (or after the operation finished) does nothing.

func (*Syncer) EnqueueDatabases

func (s *Syncer) EnqueueDatabases(ctx context.Context, operation *SyncOperation, databases []*store.DatabaseMessage)

EnqueueDatabases queues the databases this operation covers and seals it: no database may be added afterwards, so an operation whose databases all report finishes here. An empty list is how a caller says "the instance step was all there was".

A sealed operation is never mutated: it either finished already or is waiting for databases it was told about. A database that cannot be synced is not registered either, or the operation would wait for a result that can never come.

func (*Syncer) FailOperation added in v0.1.2

func (s *Syncer) FailOperation(ctx context.Context, operation *SyncOperation, cause error)

FailOperation seals an operation that cannot wait for databases and records why. A full sync uses it when the database list itself cannot be read: without this the operation would be sealed with an empty pending set and report success with zero databases, which is indistinguishable from "there was nothing to sync".

func (*Syncer) FinishOperation

func (s *Syncer) FinishOperation(ctx context.Context, operation *SyncOperation)

FinishOperation seals an operation that has no databases to wait for, because the instance step was the whole of it.

func (*Syncer) GetInstanceMeta

func (s *Syncer) GetInstanceMeta(ctx context.Context, instance *store.InstanceMessage) (*db.InstanceMetadata, error)

GetInstanceMeta gets the instance metadata.

func (*Syncer) Name added in v0.1.2

func (*Syncer) Name() string

Name identifies the runner in the server's lifecycle logs.

func (*Syncer) QueueLineageAnalysis

func (s *Syncer) QueueLineageAnalysis(metaGUID string, metaType storepb.MetaType)

func (*Syncer) RecordInstanceResult

func (s *Syncer) RecordInstanceResult(ctx context.Context, operation *SyncOperation, err error)

RecordInstanceResult records the instance metadata step's outcome.

func (*Syncer) Run

func (s *Syncer) Run(ctx context.Context)

Run starts the schema syncer. It blocks until ctx is cancelled.

func (*Syncer) StartOperation

func (s *Syncer) StartOperation(trigger storepb.SyncTrigger, initiatorID int, instance *store.InstanceMessage) *SyncOperation

StartOperation registers one sync operation for the caller.

func (*Syncer) SyncAllDatabases

func (s *Syncer) SyncAllDatabases(ctx context.Context, operation *SyncOperation, instance *store.InstanceMessage)

SyncAllDatabases queues every database of an instance for the operation that asked for it, and seals the operation: a list it could not read leaves the operation reporting the instance step alone instead of waiting for databases that were never queued.

func (*Syncer) SyncDatabaseForUser

func (s *Syncer) SyncDatabaseForUser(ctx context.Context, database *store.DatabaseMessage, initiatorID int) error

SyncDatabaseForUser syncs one database and reports the outcome to the user who asked for it. It returns the sync error so the caller can still answer the request with it; the message is the durable record of the outcome, which is what the caller has nothing else to leave behind.

func (*Syncer) SyncDatabaseSchema

func (s *Syncer) SyncDatabaseSchema(ctx context.Context, database *store.DatabaseMessage) (err error)

SyncDatabaseSchema will sync the schema for a database.

Two callers can ask for the same database at once (the periodic checker and the API both call this function), so the sync is serialized per database: a caller that arrives while one is running waits for it and reuses its result.

func (*Syncer) SyncInstance

func (s *Syncer) SyncInstance(ctx context.Context, instance *store.InstanceMessage) (updatedInstance *store.InstanceMessage, databases []*storepb.DatabaseSchemaMetadata, newDatabases []*store.DatabaseMessage, err error)

SyncInstance syncs the schema for all databases in an instance.

The API and the periodic scan can ask for the same instance at once, so the enumeration is serialized per instance exactly as a database sync is: a caller that arrives while one is running waits for it and reuses its result. Two concurrent enumerations would otherwise create the same database rows and write the same deleted flags against each other's reads.

Jump to

Keyboard shortcuts

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