dbinfo

package
v0.70.2 Latest Latest
Warning

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

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

Documentation

Overview

Package dbinfo records, in a small JSON sidecar file beside a dingo data directory, which metadata plugin produced the database it belongs to.

The metadata store itself is the single source of truth for every persisted node setting, including which plugin owns the data -- specifically the metadata_plugin gate in node_settings_gate (see database/nodesettings). This sidecar exists only so the configuration layer can identify the right plugin to open *before* it has opened anything: resolving a metadata provider runs its own migrations as a side effect of merely starting it, so opening the wrong provider would silently create a brand new, empty database beside the real one instead of ever reaching the gate table that would have caught the mismatch.

A database that predates this sidecar, or one that has otherwise lost it, has no way to signal that up front, so its absence is never an error -- it just means the caller falls back to opening its configured plugin directly, the same as it always has.

Index

Constants

View Source
const CurrentFormatVersion = 1

CurrentFormatVersion is the only FormatVersion this build writes and accepts on Read.

View Source
const FileName = "dingo.dbinfo"

FileName is the sidecar's fixed name within a data directory.

Variables

View Source
var ErrIncompleteSidecar = errors.New(
	"dbinfo: sidecar is missing its metadata plugin",
)

ErrIncompleteSidecar marks a sidecar whose FormatVersion this build recognises but whose MetadataPlugin is missing, JSON null, or the empty string. Read returns it (wrapped with the sidecar's path) instead of a zero Info and a nil error, because a zero Info is exactly what Read returns for a sidecar that is simply absent -- and the caller, internal/settingsresolve's checkMetadataPluginSidecar, treats "absent" as "nothing to check, proceed." A sidecar file that exists but never got a plugin name written into it (interrupted Write, hand-edited, or a future writer bug) must not be indistinguishable from that, since proceeding resolves whatever metadata plugin is configured and runs its migrations as a side effect -- silently creating a fresh, empty database beside the real one if the configured plugin is wrong. Callers that want the old "advisory, ignore it" behavior for this case specifically should not get it; see checkMetadataPluginSidecar's errors.Is handling.

Functions

func Path

func Path(dataDir string) string

Path returns the sidecar's path within dataDir.

func Write

func Write(dataDir string, info Info) error

Write persists info to the sidecar file in dataDir via a temp-file-then- rename, fsyncing the directory afterward (internal/fsyncdir) so the new file's directory entry is durable across a crash and not just its own content -- matching database/lifecycle/manifest.go's WriteManifest.

Write does not stamp or validate info.FormatVersion; callers pass CurrentFormatVersion themselves.

Types

type Info

type Info struct {
	FormatVersion  int    `json:"formatVersion"`
	MetadataPlugin string `json:"metadataPlugin"`
}

Info is the sidecar's entire content. It deliberately carries nothing beyond a format version and the metadata plugin name -- no credentials, connection string, or hostname -- since a data directory may be backed up, copied, or inspected without any expectation that this file holds anything sensitive.

func Read

func Read(dataDir string) (Info, error)

Read reads and validates the sidecar at dataDir. A missing file returns a zero Info and a nil error: the sidecar is advisory, and a database that predates it (or has otherwise lost it) must still open normally. An unrecognised FormatVersion is an error, since this build has no way to know what a newer or unknown format actually means. A sidecar whose FormatVersion this build does recognise but whose MetadataPlugin is missing, JSON null, or empty returns ErrIncompleteSidecar (wrapped with path) rather than a zero Info and a nil error -- see ErrIncompleteSidecar's doc comment for why that distinction matters.

Jump to

Keyboard shortcuts

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