Documentation
¶
Index ¶
- Variables
- func NewBoltDatabase(path string) types.PackageDatabase
- func NewInMemoryDatabase(singleton bool) types.PackageDatabase
- func NewInMemoryDatabaseNoIndex() types.PackageDatabase
- func SortPackages(packages []*types.Package)
- type BoltDatabase
- func (db *BoltDatabase) Clean() error
- func (db *BoltDatabase) Clone(to types.PackageDatabase) error
- func (db *BoltDatabase) Copy() (types.PackageDatabase, error)
- func (db *BoltDatabase) Create(id string, v []byte) (string, error)
- func (db *BoltDatabase) CreatePackage(p *types.Package) (string, error)
- func (db *BoltDatabase) FindPackage(tofind *types.Package) (*types.Package, error)
- func (db *BoltDatabase) FindPackageByFile(pattern string) (types.Packages, error)
- func (db *BoltDatabase) FindPackageCandidate(p *types.Package) (*types.Package, error)
- func (db *BoltDatabase) FindPackageLabel(labelKey string) (types.Packages, error)
- func (db *BoltDatabase) FindPackageLabelMatch(pattern string) (types.Packages, error)
- func (db *BoltDatabase) FindPackageMatch(pattern string) (types.Packages, error)
- func (db *BoltDatabase) FindPackageVersions(p *types.Package) (types.Packages, error)
- func (db *BoltDatabase) FindPackages(p *types.Package) (types.Packages, error)
- func (db *BoltDatabase) Get(s string) (string, error)
- func (db *BoltDatabase) GetAllPackages(packages chan *types.Package) error
- func (db *BoltDatabase) GetPackage(ID string) (*types.Package, error)
- func (db *BoltDatabase) GetPackageFiles(p *types.Package) ([]string, error)
- func (db *BoltDatabase) GetPackages() []string
- func (db *BoltDatabase) GetRevdeps(p *types.Package) (types.Packages, error)
- func (db *BoltDatabase) RemovePackage(p *types.Package) error
- func (db *BoltDatabase) RemovePackageFiles(p *types.Package) error
- func (db *BoltDatabase) Retrieve(ID string) ([]byte, error)
- func (db *BoltDatabase) Set(k, v string) error
- func (db *BoltDatabase) SetPackageFiles(p *types.PackageFile) error
- func (db *BoltDatabase) UpdatePackage(p *types.Package) error
- func (db *BoltDatabase) World() types.Packages
- type InMemoryDatabase
- func (db *InMemoryDatabase) Clean() error
- func (db *InMemoryDatabase) Clone(to types.PackageDatabase) error
- func (db *InMemoryDatabase) Copy() (types.PackageDatabase, error)
- func (db *InMemoryDatabase) Create(id string, v []byte) (string, error)
- func (db *InMemoryDatabase) CreatePackage(p *types.Package) (string, error)
- func (db *InMemoryDatabase) FindPackage(p *types.Package) (*types.Package, error)
- func (db *InMemoryDatabase) FindPackageByFile(pattern string) (types.Packages, error)
- func (db *InMemoryDatabase) FindPackageCandidate(p *types.Package) (*types.Package, error)
- func (db *InMemoryDatabase) FindPackageLabel(labelKey string) (types.Packages, error)
- func (db *InMemoryDatabase) FindPackageLabelMatch(pattern string) (types.Packages, error)
- func (db *InMemoryDatabase) FindPackageMatch(pattern string) (types.Packages, error)
- func (db *InMemoryDatabase) FindPackageVersions(p *types.Package) (types.Packages, error)
- func (db *InMemoryDatabase) FindPackages(p *types.Package) (types.Packages, error)
- func (db *InMemoryDatabase) Get(s string) (string, error)
- func (db *InMemoryDatabase) GetAllPackages(packages chan *types.Package) error
- func (db *InMemoryDatabase) GetPackage(ID string) (*types.Package, error)
- func (db *InMemoryDatabase) GetPackageFiles(p *types.Package) ([]string, error)
- func (db *InMemoryDatabase) GetPackages() []string
- func (db *InMemoryDatabase) GetRevdeps(p *types.Package) (types.Packages, error)
- func (db *InMemoryDatabase) RemovePackage(p *types.Package) error
- func (db *InMemoryDatabase) RemovePackageFiles(p *types.Package) error
- func (db *InMemoryDatabase) Retrieve(ID string) ([]byte, error)
- func (db *InMemoryDatabase) Set(k, v string) error
- func (db *InMemoryDatabase) SetPackageFiles(p *types.PackageFile) error
- func (db *InMemoryDatabase) UpdatePackage(p *types.Package) error
- func (db *InMemoryDatabase) World() types.Packages
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound is returned when a raw key lookup misses. ErrKeyNotFound = stderrors.New("no key found") // ErrNoVersionsFound is returned when a package name has no known versions. ErrNoVersionsFound = stderrors.New("no versions found for package") // ErrNoProvider is returned when no package provides the requested one. ErrNoProvider = stderrors.New("no package provides this") )
Sentinel errors for lookup misses.
These are returned on paths that are hit constantly during resolution - getProvide() runs at the top of every FindPackage/FindPackages/ FindPackageVersions, and the overwhelmingly common outcome is "not found", which is a control-flow signal rather than an exceptional condition.
They are deliberately built with the standard library instead of github.com/pkg/errors: the latter's New() calls runtime.Callers to capture a 32-frame stack trace on every invocation, which profiled at ~46% of CPU time during an upgrade. Declaring them once at package level makes a miss free.
Compare with errors.Is - do not match on the message text.
var DBInMemoryInstance = &InMemoryDatabase{ Mutex: &sync.Mutex{}, FileDatabase: map[string][]string{}, Database: map[string]string{}, CacheNoVersion: map[string]map[string]interface{}{}, ProvidesDatabase: map[string]map[string]*types.Package{}, RevDepsDatabase: map[string]map[string]*types.Package{}, cached: map[string]interface{}{}, }
Functions ¶
func NewBoltDatabase ¶
func NewBoltDatabase(path string) types.PackageDatabase
func NewInMemoryDatabase ¶
func NewInMemoryDatabase(singleton bool) types.PackageDatabase
func NewInMemoryDatabaseNoIndex ¶
func NewInMemoryDatabaseNoIndex() types.PackageDatabase
NewInMemoryDatabaseNoIndex returns a database that stores packages but builds none of the lookup indexes.
Populating those indexes is not free: for each requirement of each inserted package it expands a selector across every matching version and deep-copies the result, so inserting into a world with long release histories costs far more than the insert itself. Profiling an upgrade showed it as the largest identifiable cost after garbage collection.
A solver database does not need any of it. It exists so Package.Encode can mint a stable SAT variable name and DecodeModel can map a model back to packages - a key/value store. Reverse dependencies and version lookups are asked of the definition and installed databases, never of this one.
Do NOT use it where FindPackages, FindPackageVersions, GetRevdeps or provides resolution are needed: those return nothing here.
func SortPackages ¶
SortPackages orders packages by name and category ascending, then by version DESCENDING, and is the ordering the solver sees.
This is load-bearing, not cosmetic. The SAT encoding is version-blind: a package becomes an opaque bf.Var("name-category-version") and the at-most-one clauses tying versions together are symmetric, so nothing in the formula says one version is newer. Which version comes back is decided by gophersat's branching, which breaks ties on variable index, which bf assigns in order of first appearance during CNF conversion - i.e. the order the world was walked. Walking a Go map made that order random per run, so the same input could resolve differently, and the solver settled on a needlessly old version most of the time.
The DIRECTION matters as much as the determinism. gophersat's default phase is false-first, so packages are only installed when propagation forces it, and the candidate reached first tends to win. Presenting versions newest-first therefore steers it to the newest satisfiable one. Sorting the composite fingerprint string in reverse would ALSO be deterministic while reversing name order too, which perturbs the CNF onto a different - equally stable - wrong answer. Name ascending, version descending.
This is a heuristic, not a guarantee: there is still no optimisation objective in the encoding. It is covered by the determinism tests in pkg/solver rather than assumed.
Types ¶
type BoltDatabase ¶
type BoltDatabase struct {
sync.Mutex
Path string
ProvidesDatabase map[string]map[string]*types.Package
// contains filtered or unexported fields
}
func (*BoltDatabase) Clean ¶
func (db *BoltDatabase) Clean() error
func (*BoltDatabase) Clone ¶
func (db *BoltDatabase) Clone(to types.PackageDatabase) error
func (*BoltDatabase) Copy ¶
func (db *BoltDatabase) Copy() (types.PackageDatabase, error)
func (*BoltDatabase) CreatePackage ¶
func (db *BoltDatabase) CreatePackage(p *types.Package) (string, error)
Encode encodes the package to string. It returns an ID which can be used to retrieve the package later on.
func (*BoltDatabase) FindPackage ¶
func (*BoltDatabase) FindPackageByFile ¶
func (db *BoltDatabase) FindPackageByFile(pattern string) (types.Packages, error)
func (*BoltDatabase) FindPackageCandidate ¶
func (*BoltDatabase) FindPackageLabel ¶
func (db *BoltDatabase) FindPackageLabel(labelKey string) (types.Packages, error)
func (*BoltDatabase) FindPackageLabelMatch ¶
func (db *BoltDatabase) FindPackageLabelMatch(pattern string) (types.Packages, error)
func (*BoltDatabase) FindPackageMatch ¶
func (db *BoltDatabase) FindPackageMatch(pattern string) (types.Packages, error)
func (*BoltDatabase) FindPackageVersions ¶
FindPackageVersions return the list of the packages beloging to cat/name
func (*BoltDatabase) FindPackages ¶
FindPackages return the list of the packages beloging to cat/name (any versions in requested range) FIXME: Optimize, see inmemorydb
func (*BoltDatabase) GetAllPackages ¶
func (db *BoltDatabase) GetAllPackages(packages chan *types.Package) error
func (*BoltDatabase) GetPackage ¶
func (db *BoltDatabase) GetPackage(ID string) (*types.Package, error)
func (*BoltDatabase) GetPackageFiles ¶
func (db *BoltDatabase) GetPackageFiles(p *types.Package) ([]string, error)
func (*BoltDatabase) GetPackages ¶
func (db *BoltDatabase) GetPackages() []string
func (*BoltDatabase) GetRevdeps ¶
GetRevdeps uses a new inmemory db to calcuate revdeps TODO: Have a memory instance for boltdb, so we don't compute each time we get called as this is REALLY expensive. But we don't perform usually those operations in a file db.
func (*BoltDatabase) RemovePackage ¶
func (db *BoltDatabase) RemovePackage(p *types.Package) error
func (*BoltDatabase) RemovePackageFiles ¶
func (db *BoltDatabase) RemovePackageFiles(p *types.Package) error
func (*BoltDatabase) Set ¶
func (db *BoltDatabase) Set(k, v string) error
func (*BoltDatabase) SetPackageFiles ¶
func (db *BoltDatabase) SetPackageFiles(p *types.PackageFile) error
func (*BoltDatabase) UpdatePackage ¶
func (db *BoltDatabase) UpdatePackage(p *types.Package) error
func (*BoltDatabase) World ¶
func (db *BoltDatabase) World() types.Packages
type InMemoryDatabase ¶
type InMemoryDatabase struct {
*sync.Mutex
Database map[string]string
FileDatabase map[string][]string
CacheNoVersion map[string]map[string]interface{}
ProvidesDatabase map[string]map[string]*types.Package
RevDepsDatabase map[string]map[string]*types.Package
// contains filtered or unexported fields
}
func (*InMemoryDatabase) Clean ¶
func (db *InMemoryDatabase) Clean() error
func (*InMemoryDatabase) Clone ¶
func (db *InMemoryDatabase) Clone(to types.PackageDatabase) error
func (*InMemoryDatabase) Copy ¶
func (db *InMemoryDatabase) Copy() (types.PackageDatabase, error)
func (*InMemoryDatabase) Create ¶
func (db *InMemoryDatabase) Create(id string, v []byte) (string, error)
func (*InMemoryDatabase) CreatePackage ¶
func (db *InMemoryDatabase) CreatePackage(p *types.Package) (string, error)
Encode encodes the package to string. It returns an ID which can be used to retrieve the package later on.
func (*InMemoryDatabase) FindPackage ¶
func (*InMemoryDatabase) FindPackageByFile ¶
func (db *InMemoryDatabase) FindPackageByFile(pattern string) (types.Packages, error)
func (*InMemoryDatabase) FindPackageCandidate ¶
func (*InMemoryDatabase) FindPackageLabel ¶
func (db *InMemoryDatabase) FindPackageLabel(labelKey string) (types.Packages, error)
func (*InMemoryDatabase) FindPackageLabelMatch ¶
func (db *InMemoryDatabase) FindPackageLabelMatch(pattern string) (types.Packages, error)
func (*InMemoryDatabase) FindPackageMatch ¶
func (db *InMemoryDatabase) FindPackageMatch(pattern string) (types.Packages, error)
func (*InMemoryDatabase) FindPackageVersions ¶
FindPackages return the list of the packages beloging to cat/name
func (*InMemoryDatabase) FindPackages ¶
FindPackages return the list of the packages beloging to cat/name (any versions in requested range)
func (*InMemoryDatabase) GetAllPackages ¶
func (db *InMemoryDatabase) GetAllPackages(packages chan *types.Package) error
func (*InMemoryDatabase) GetPackage ¶
func (db *InMemoryDatabase) GetPackage(ID string) (*types.Package, error)
func (*InMemoryDatabase) GetPackageFiles ¶
func (db *InMemoryDatabase) GetPackageFiles(p *types.Package) ([]string, error)
func (*InMemoryDatabase) GetPackages ¶
func (db *InMemoryDatabase) GetPackages() []string
func (*InMemoryDatabase) GetRevdeps ¶
GetRevdeps returns the package reverse dependencies, matching also selectors in versions (>, <, >=, <=) TODO: Code should use db explictly
func (*InMemoryDatabase) RemovePackage ¶
func (db *InMemoryDatabase) RemovePackage(p *types.Package) error
func (*InMemoryDatabase) RemovePackageFiles ¶
func (db *InMemoryDatabase) RemovePackageFiles(p *types.Package) error
func (*InMemoryDatabase) Set ¶
func (db *InMemoryDatabase) Set(k, v string) error
func (*InMemoryDatabase) SetPackageFiles ¶
func (db *InMemoryDatabase) SetPackageFiles(p *types.PackageFile) error
func (*InMemoryDatabase) UpdatePackage ¶
func (db *InMemoryDatabase) UpdatePackage(p *types.Package) error
func (*InMemoryDatabase) World ¶
func (db *InMemoryDatabase) World() types.Packages