db

package
v0.0.0-...-c9cfaf6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 20 Imported by: 1

Documentation

Overview

Package db provides a database storage layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeFilter

type ChangeFilter struct {
	MinEffectSize             float64
	MaxRankByEffectSize       int
	MaxRankByAbsPercentChange int
}

ChangeFilter specifies thresholds for change listings.

type CommitModule

type CommitModule struct {
	CommitSHA  string
	CommitTime time.Time
	ModuleUUID uuid.UUID
}

CommitModule represents a commit module pair.

type CommitModuleError

type CommitModuleError struct {
	ModuleUUID  uuid.UUID
	CommitSHA   string
	NumErrors   int
	LastAttempt time.Time
}

CommitModuleError represents a commit module pair that has no completed tasks and at least one error.

type DB

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

DB provides database access.

func New

func New(ctx context.Context, d *sql.DB) (*DB, error)

New builds a database layer backed by the given postgres connection.

func Open

func Open(ctx context.Context, conn string) (*DB, error)

Open postgres database connection with the given connection string.

func (*DB) BuildChangesRanked

func (d *DB) BuildChangesRanked(ctx context.Context) error

BuildChangesRanked derives the ranked changes table from the changes table.

func (*DB) BuildCommitPositions

func (d *DB) BuildCommitPositions(ctx context.Context) error

BuildCommitPositions creates the commit positions table. The table is completely rebuilt from the source tables.

func (*DB) Close

func (d *DB) Close() error

Close database connection.

func (*DB) CreateTask

func (d *DB) CreateTask(ctx context.Context, worker string, s entity.TaskSpec) (*entity.Task, error)

CreateTask creates a new task.

func (*DB) FindBenchmarkByUUID

func (d *DB) FindBenchmarkByUUID(ctx context.Context, id uuid.UUID) (*entity.Benchmark, error)

FindBenchmarkByUUID looks up the given benchmark in the database.

func (*DB) FindCommitBySHA

func (d *DB) FindCommitBySHA(ctx context.Context, sha string) (*entity.Commit, error)

FindCommitBySHA looks up the given commit in the database.

func (*DB) FindCommitIndexBySHA

func (d *DB) FindCommitIndexBySHA(ctx context.Context, sha string) (int, error)

FindCommitIndexBySHA looks up the commit index for a SHA.

func (*DB) FindDataFileByUUID

func (d *DB) FindDataFileByUUID(ctx context.Context, id uuid.UUID) (*entity.DataFile, error)

FindDataFileByUUID looks up the given data file in the database.

func (*DB) FindModuleByUUID

func (d *DB) FindModuleByUUID(ctx context.Context, id uuid.UUID) (*entity.Module, error)

FindModuleByUUID looks up the given module in the database.

func (*DB) FindPackageByUUID

func (d *DB) FindPackageByUUID(ctx context.Context, id uuid.UUID) (*entity.Package, error)

FindPackageByUUID looks up the given package in the database.

func (*DB) FindPropertiesByUUID

func (d *DB) FindPropertiesByUUID(ctx context.Context, id uuid.UUID) (entity.Properties, error)

FindPropertiesByUUID looks up the given properties in the database.

func (*DB) FindResultByUUID

func (d *DB) FindResultByUUID(ctx context.Context, id uuid.UUID) (*entity.Result, error)

FindResultByUUID looks up a result in the database given the ID.

func (*DB) FindTaskByUUID

func (d *DB) FindTaskByUUID(ctx context.Context, id uuid.UUID) (*entity.Task, error)

FindTaskByUUID looks up the given task in the database.

func (*DB) ListBenchmarkPoints

func (d *DB) ListBenchmarkPoints(ctx context.Context, b *entity.Benchmark, r entity.CommitIndexRange) (entity.Points, error)

ListBenchmarkPoints returns timeseries points for the given benchmark and commit index range.

func (*DB) ListBenchmarkResults

func (d *DB) ListBenchmarkResults(ctx context.Context, b *entity.Benchmark) ([]*entity.Result, error)

ListBenchmarkResults returns all results for the given benchmark.

func (*DB) ListChangeSummaries

func (d *DB) ListChangeSummaries(ctx context.Context, r entity.CommitIndexRange, filter ChangeFilter) ([]*entity.ChangeSummary, error)

ListChangeSummaries returns changes with associated metadata.

func (*DB) ListChangeSummariesForCommitIndex

func (d *DB) ListChangeSummariesForCommitIndex(ctx context.Context, idx int, filter ChangeFilter) ([]*entity.ChangeSummary, error)

ListChangeSummariesForCommitIndex returns changes at a specific commit.

func (*DB) ListCommitModuleErrors

func (d *DB) ListCommitModuleErrors(ctx context.Context, worker string, maxErrors int, lastAttempt time.Time, n int) ([]CommitModuleError, error)

ListCommitModuleErrors returns up to n commit module pairs that have errored on the given worker with no successful execution. The search is limited to pairs with at most maxErrors errors and last attempt before the given timestamp. This is intended for identifying tasks that should be retried.

func (*DB) ListCommitModulesWithoutCompleteTasks

func (d *DB) ListCommitModulesWithoutCompleteTasks(ctx context.Context, worker string, n int) ([]CommitModule, error)

ListCommitModulesWithoutCompleteTasks searches for n recent commit module pairs without completed tasks for the given worker.

func (*DB) ListModulePackages

func (d *DB) ListModulePackages(ctx context.Context, m *entity.Module) ([]*entity.Package, error)

ListModulePackages returns all packages in the given module.

func (*DB) ListModules

func (d *DB) ListModules(ctx context.Context) ([]*entity.Module, error)

ListModules returns all modules.

func (*DB) ListPackageBenchmarks

func (d *DB) ListPackageBenchmarks(ctx context.Context, p *entity.Package) ([]*entity.Benchmark, error)

ListPackageBenchmarks returns all benchmarks in the given package.

func (*DB) ListTasksWithStatus

func (d *DB) ListTasksWithStatus(ctx context.Context, statuses []entity.TaskStatus) ([]*entity.Task, error)

ListTasksWithStatus returns tasks in the given states.

func (*DB) ListTracePoints

func (d *DB) ListTracePoints(ctx context.Context, r entity.CommitIndexRange) ([]trace.Point, error)

ListTracePoints returns trace points for the given commit range.

func (*DB) ListWorkerTasksPending

func (d *DB) ListWorkerTasksPending(ctx context.Context, worker string) ([]*entity.Task, error)

ListWorkerTasksPending returns tasks assigned to a worker in a pending state.

func (*DB) ListWorkerTasksWithStatus

func (d *DB) ListWorkerTasksWithStatus(ctx context.Context, worker string, statuses []entity.TaskStatus) ([]*entity.Task, error)

ListWorkerTasksWithStatus returns tasks assigned to a worker in the given states.

func (*DB) MostRecentCommit

func (d *DB) MostRecentCommit(ctx context.Context) (*entity.Commit, error)

MostRecentCommit returns the most recent commit by commit time.

func (*DB) MostRecentCommitIndex

func (d *DB) MostRecentCommitIndex(ctx context.Context) (int, error)

MostRecentCommitIndex returns the most recent commit index.

func (*DB) MostRecentCommitWithRef

func (d *DB) MostRecentCommitWithRef(ctx context.Context, ref string) (*entity.Commit, error)

MostRecentCommitWithRef returns the most recent commit by commit time having the supplied ref.

func (*DB) RecordTaskDataUpload

func (d *DB) RecordTaskDataUpload(ctx context.Context, id uuid.UUID, f *entity.DataFile) error

RecordTaskDataUpload inserts the given datafile and associates it with the supplied task ID.

func (*DB) ReplaceChanges

func (d *DB) ReplaceChanges(ctx context.Context, r entity.CommitIndexRange, cs []*entity.Change) error

ReplaceChanges transactionally deletes changes in a range and inserts supplied changes.

func (*DB) SetLogger

func (d *DB) SetLogger(l *zap.Logger)

SetLogger configures a logger.

func (*DB) StoreBenchmark

func (d *DB) StoreBenchmark(ctx context.Context, b *entity.Benchmark) error

StoreBenchmark writes benchmark to the database.

func (*DB) StoreChangesBatch

func (d *DB) StoreChangesBatch(ctx context.Context, cs []*entity.Change) error

StoreChangesBatch writes the given changes to the database in a single batch. Does not write any dependent objects.

func (*DB) StoreCommit

func (d *DB) StoreCommit(ctx context.Context, c *entity.Commit) error

StoreCommit writes commit to the database.

func (*DB) StoreCommitPosition

func (d *DB) StoreCommitPosition(ctx context.Context, p *entity.CommitPosition) error

StoreCommitPosition writes a commit position to the database. This should be rarely needed outside of testing; prefer BuildCommitPositions.

func (*DB) StoreCommitRef

func (d *DB) StoreCommitRef(ctx context.Context, r *entity.CommitRef) error

StoreCommitRef writes a commit ref pair to the database.

func (*DB) StoreCommitRefs

func (d *DB) StoreCommitRefs(ctx context.Context, rs []*entity.CommitRef) error

StoreCommitRefs writes the given commit refs to the database.

func (*DB) StoreCommits

func (d *DB) StoreCommits(ctx context.Context, cs []*entity.Commit) error

StoreCommits writes the given commits to the database in a single batch.

func (*DB) StoreDataFile

func (d *DB) StoreDataFile(ctx context.Context, f *entity.DataFile) error

StoreDataFile writes the data file to the database.

func (*DB) StoreModule

func (d *DB) StoreModule(ctx context.Context, m *entity.Module) error

StoreModule writes module to the database.

func (*DB) StorePackage

func (d *DB) StorePackage(ctx context.Context, p *entity.Package) error

StorePackage writes package to the database.

func (*DB) StoreProperties

func (d *DB) StoreProperties(ctx context.Context, p entity.Properties) error

StoreProperties writes properties to the database.

func (*DB) StoreResult

func (d *DB) StoreResult(ctx context.Context, r *entity.Result) error

StoreResult writes a result to the database.

func (*DB) StoreResults

func (d *DB) StoreResults(ctx context.Context, rs []*entity.Result) error

StoreResults writes results to the database.

func (*DB) TimeoutStaleTasks

func (d *DB) TimeoutStaleTasks(ctx context.Context, until time.Time) error

TimeoutStaleTasks marks stale all pending tasks with last update before until.

func (*DB) Trace

func (d *DB) Trace(ctx context.Context, id trace.ID, r entity.CommitIndexRange) (*trace.Trace, error)

Trace returns a specific trace between the given commit range.

func (*DB) TransitionTaskStatus

func (d *DB) TransitionTaskStatus(ctx context.Context, id uuid.UUID, from []entity.TaskStatus, to entity.TaskStatus) error

TransitionTaskStatus performs the given task status transition.

func (*DB) TransitionTaskStatusesBefore

func (d *DB) TransitionTaskStatusesBefore(ctx context.Context, from []entity.TaskStatus, to entity.TaskStatus, until time.Time) error

TransitionTaskStatusesBefore applies a task status transition to all tasks that were last updated before the until timestamp.

func (*DB) TruncateAll

func (d *DB) TruncateAll(ctx context.Context) error

TruncateAll deletes all data from the database.

Directories

Path Synopsis
Package dbtest provides helpers for testing the database storage layer.
Package dbtest provides helpers for testing the database storage layer.
internal
db

Jump to

Keyboard shortcuts

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