Documentation
¶
Overview ¶
Package store keeps strata's index in a local DuckDB file.
The index is a rebuildable cache of what the registry holds, with one exception: tag history, which the registry cannot give back. It can be exported to and imported from Parquet so it survives a rebuild.
Index ¶
- Constants
- func CreateTempLike(ctx context.Context, conn *sql.Conn, temp, like string) error
- func Stage(ctx context.Context, conn *sql.Conn, temp, like string, ...) error
- type Batch
- type Store
- func (s *Store) CheckpointRepo(ctx context.Context, run int64, repo string) error
- func (s *Store) Close() error
- func (s *Store) DB() *sql.DB
- func (s *Store) ExportHistory(ctx context.Context, path string) (int64, error)
- func (s *Store) FinishCrawl(ctx context.Context, run int64) error
- func (s *Store) ImportHistory(ctx context.Context, path string) (int64, error)
- func (s *Store) KnownDigests(ctx context.Context, repo string) (map[string]bool, error)
- func (s *Store) KnownImage(ctx context.Context, digest string) (bool, error)
- func (s *Store) MergeRows(ctx context.Context, table, scope string, scopeArgs []any, keys []string, ...) (int, error)
- func (s *Store) Meta(ctx context.Context, key string) (string, error)
- func (s *Store) MissingBases(ctx context.Context, retryAfter time.Time) ([]model.BaseRef, error)
- func (s *Store) Path() string
- func (s *Store) RecordBaseFetch(ctx context.Context, r model.BaseRef, errText string, at time.Time) error
- func (s *Store) SetMeta(ctx context.Context, key, value string) error
- func (s *Store) StartCrawl(ctx context.Context, registry string) (int64, map[string]bool, error)
- func (s *Store) Tags(ctx context.Context, repo string) (map[string]string, error)
- func (s *Store) UncheckedIndexes(ctx context.Context, host string, limit int) ([]UncheckedIndex, error)
- func (s *Store) Write(ctx context.Context, b *Batch) error
- type UncheckedIndex
Constants ¶
const FormatVersion = 1
FormatVersion is the version of strata's table layout. It is recorded in the file's meta table, and Open refuses a file written by a newer strata.
Variables ¶
This section is empty.
Functions ¶
func CreateTempLike ¶ added in v0.2.1
CreateTempLike creates (or replaces) an empty temporary table named temp with the columns and types of table like, declared explicitly.
It does not use CREATE TABLE ... AS SELECT ... LIMIT 0. In DuckDB 2.0, a table created that way inside a transaction and then filled past one row group (122,880 rows) is invisible to semi-joins and EXCEPT until the transaction commits, so a diff against it silently comes out empty. TestCreateTempLikeLarge guards against this.
func Stage ¶ added in v0.2.1
func Stage(ctx context.Context, conn *sql.Conn, temp, like string, rows func(a *duckdb.Appender) error) error
Stage creates a temporary table named temp with like's columns and bulk-loads it through the appender. Callers compare staged rows with stored ones and write the difference.
Types ¶
type Batch ¶
type Batch struct {
Images []*model.Image
Index []model.IndexEntry
Tags []model.Tag
DeleteTags []model.Tag
Events []model.TagEvent
Referrers []model.Referrer
// Pushes are push and pull times reported by the registry's API. They
// change between crawls, so they replace what was stored.
Pushes []model.Push
// BaseRefs are the bases builds say images started from.
BaseRefs []model.BaseRef
// ProvenanceChecked are index digests whose provenance was read, so a
// backfill skips them.
ProvenanceChecked []string
// Run and Done checkpoint repos of a crawl run in the same
// transaction as their data, so a resumed crawl never skips a repo
// whose rows were lost.
Run int64
Done []string
}
Batch is a set of records written together in one transaction.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an open index file.
func Open ¶
Open opens or creates the index at path, creating the schema and checking the format version. An empty path opens a private in-memory index.
func (*Store) CheckpointRepo ¶
CheckpointRepo records that a crawl run finished a repo.
func (*Store) ExportHistory ¶
ExportHistory writes tag history to a Parquet file.
func (*Store) FinishCrawl ¶
FinishCrawl marks a crawl run complete.
func (*Store) ImportHistory ¶
ImportHistory merges tag history from a Parquet file written by ExportHistory, keeping rows already present.
func (*Store) KnownDigests ¶
KnownDigests returns the manifest and index digests already indexed for a repo, so a re-crawl only fetches what is new.
func (*Store) KnownImage ¶
KnownImage reports whether a manifest digest is indexed in any repo.
func (*Store) MergeRows ¶ added in v0.2.1
func (s *Store) MergeRows(ctx context.Context, table, scope string, scopeArgs []any, keys []string, rows [][]any) (int, error)
MergeRows makes the rows of table that match scope equal to rows, in one transaction. It bulk-loads rows into a staging table and writes only the differences: rows to remove, and rows to add or change, matched on the key columns. Rewriting rows that did not change is what makes a delete-and-reload slow on a table with a primary key. It returns how many rows it removed or wrote.
func (*Store) MissingBases ¶ added in v0.3.1
MissingBases returns the bases builds named, by digest, that are not indexed and were not tried since retryAfter.
func (*Store) RecordBaseFetch ¶ added in v0.3.1
func (s *Store) RecordBaseFetch(ctx context.Context, r model.BaseRef, errText string, at time.Time) error
RecordBaseFetch records an attempt to fetch a base by digest; errText is empty when it succeeded.
func (*Store) StartCrawl ¶
StartCrawl returns the crawl run to work on for a registry: the last one if it never finished, so a crash resumes, or a new one. It also returns the repos the run already finished.
func (*Store) UncheckedIndexes ¶ added in v0.3.1
func (s *Store) UncheckedIndexes(ctx context.Context, host string, limit int) ([]UncheckedIndex, error)
UncheckedIndexes returns up to limit indexes in repos under host whose provenance was never read, as for images indexed before strata read provenance.
type UncheckedIndex ¶ added in v0.3.1
UncheckedIndex is a multi-platform index whose provenance was never read, and a repo holding it.