Help us shape the future of Go! Take the 2026 Go Developer Survey

tablereconcile

package
v1.151.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package tablereconcile compares a connection's scratch schema with the table registrations on it and repairs what the platform can prove is its own (#2136).

A table can exist with no registration (a registration that failed after the coordinator made its table, a restore, a statement run by hand), a registration can name a table that is gone, and a table can read somewhere its registration does not say. Nothing else lists those three, and the first could not be removed through the platform at all: unregistering takes a registration id, and an orphan has none.

What is repaired is only what the platform can prove is its own: an orphan whose location is the directory of a file the platform stores, and a registration whose table is gone. Everything else is reported and left. A managed table (one with no external location, such as a managed script's working table) is never a registration's and is neither reported nor repaired (#2141).

Index

Constants

View Source
const (
	ActionDrop   = "drop"
	ActionForget = "forget"
)

The repair actions.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auditor

type Auditor interface {
	AuditStatement(ctx context.Context, s tableregister.Statement)
}

Auditor records a repair. tableregister.Registrar satisfies it.

type Deps

type Deps struct {
	Engine Engine
	Store  Store
	Audit  Auditor
	// Locate reads a stored file by kind and id. Nil leaves only the
	// managed-resources layout to prove an orphan by.
	Locate tableregister.Locator
	// ResourceBucket is the managed-resources bucket: a location under its
	// resources/ prefix is a managed resource's directory whether or not the
	// resource still exists.
	ResourceBucket string
}

Deps is what a Reconciler acts through.

type Drifted

type Drifted struct {
	Registration tableregister.Registration `json:"registration"`
	Location     string                     `json:"location"`
}

Drifted is a registration whose table reads somewhere else.

type Engine

type Engine interface {
	ScratchTarget(connection string) (trino.ScratchConfig, bool)
	ListTables(ctx context.Context, connection, catalog, schema string) ([]trino.SchemaTable, bool, error)
	TableLocation(ctx context.Context, connection, catalog, schema, table string) (location string, found bool, err error)
	TableExists(ctx context.Context, connection, catalog, schema, table string) (bool, error)
	Exec(ctx context.Context, connection, sql string) error
}

Engine is what a reconcile asks the query engine. The Trino toolkit satisfies it.

type Missing

type Missing struct {
	Registration tableregister.Registration `json:"registration"`
	// Provable is false for a webhook source's table, which is removed with
	// the source and never by a repair.
	Provable bool `json:"provable"`
}

Missing is a registration whose table is gone.

type Orphan

type Orphan struct {
	Table    string `json:"table"`
	Location string `json:"location"`
	// Source is the stored file the location belongs to, when it is one.
	Source *SourceRef `json:"source,omitempty"`
	// Provable is whether the platform can show the table is its own, which
	// is what a repair requires.
	Provable bool `json:"provable"`
}

Orphan is a table with no registration.

type Reconciler

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

Reconciler compares a connection's scratch schema with the registrations on it and repairs what can be proved.

func New

func New(deps Deps) *Reconciler

New builds a Reconciler, or nil when the engine or the store is missing.

func (*Reconciler) Reconcile

func (c *Reconciler) Reconcile(ctx context.Context, connection string) (*Reconciliation, error)

Reconcile compares the scratch schema of a connection with the registrations on it.

func (*Reconciler) Repair

func (c *Reconciler) Repair(
	ctx context.Context, caller tableregister.Caller, connection string, items []RepairItem,
) ([]RepairOutcome, error)

Repair carries out the repairs asked for on a connection, each proved again at the moment it is made, and reports what each did. A repair that cannot be proved is reported, never made.

type Reconciliation

type Reconciliation struct {
	Connection string    `json:"connection"`
	Catalog    string    `json:"catalog"`
	Schema     string    `json:"schema"`
	Orphans    []Orphan  `json:"orphans"`
	Missing    []Missing `json:"missing"`
	Drifted    []Drifted `json:"drifted"`
	// Truncated is whether the schema held more tables than one listing
	// returns, so the orphans are a partial list and none is reported
	// missing.
	Truncated bool `json:"truncated"`
}

Reconciliation is a connection's scratch schema against its registrations.

type RepairItem

type RepairItem struct {
	Action         string `json:"action" enums:"drop,forget"`
	Table          string `json:"table,omitempty"`
	RegistrationID string `json:"registration_id,omitempty"`
}

RepairItem is one repair an administrator asks for: "drop" an orphan table by name, or "forget" a registration whose table is gone by id.

type RepairOutcome

type RepairOutcome struct {
	RepairItem
	// Done is whether it was carried out; Reason says why when it was not.
	Done   bool   `json:"done"`
	Reason string `json:"reason,omitempty"`
}

RepairOutcome is what one repair did.

type SourceRef

type SourceRef struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
	// Exists is whether the platform still holds the file.
	Exists bool `json:"exists"`
}

SourceRef names the stored file a location belongs to.

type Store

type Store interface {
	List(ctx context.Context, f tableregister.Filter) ([]tableregister.Registration, int, error)
	ByName(ctx context.Context, connection, catalog, schema, table string) (*tableregister.Registration, error)
	Get(ctx context.Context, id string) (*tableregister.Registration, error)
	Delete(ctx context.Context, id string) error
}

Store is the half of the registration store a reconcile reads and writes. tableregister.Store satisfies it.

Jump to

Keyboard shortcuts

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