Documentation ¶
Overview ¶
Package database contains the DistroDB object and its methods. It manages a database of Windows Subsystem for Linux distribution instances (aka distros).
Index ¶
- type DistroDB
- func (db *DistroDB) Close(ctx context.Context)
- func (db *DistroDB) Dump() error
- func (db *DistroDB) Get(name string) (distro *distro.Distro, ok bool)
- func (db *DistroDB) GetAll() (all []*distro.Distro)
- func (db *DistroDB) GetDistroAndUpdateProperties(ctx context.Context, name string, props distro.Properties) (*distro.Distro, error)
- func (db *DistroDB) TriggerCleanup()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistroDB ¶
type DistroDB struct {
// contains filtered or unexported fields
}
DistroDB is a thread-safe single-table database of WSL distribution instances. This database is held in memory and backed in disk. Any write on the database will be instanly followed up by a write-to-disk.
func New ¶
New creates a database and populates it with data in the file located at "storagePath". Changes to the database will be written on this file.
You must call Close to deallocate resources.
Creating multiple databases with the same disk backing will result in undefined behaviour.
Every certain amount of times, the database wil purge all distros that are no longer registered or that have been marked as unreachable. This cleanup can be triggered on demmand with TriggerCleanup.
func (*DistroDB) Close ¶
Close frees up resources allocated to database maintenance and ensures the database contents are written to file.
func (*DistroDB) Dump ¶
Dump stores the current database state to disk, overriding old dumps. Next time we start the agent, the database will be loaded from this dump.
func (*DistroDB) Get ¶
Get searches for the target distro. It returns the distro object and a flag indicating if it was found. TODO: check if useful as public.
func (*DistroDB) GetDistroAndUpdateProperties ¶
func (db *DistroDB) GetDistroAndUpdateProperties(ctx context.Context, name string, props distro.Properties) (*distro.Distro, error)
GetDistroAndUpdateProperties fetches a distro from the database, guranteeing that the returned distro is valid, is in the database, and matches the given properties. If needed: * A pre-existing distro with the same name may be removed from the database. * An existing distro in the database may have their properties updated. * A new distro may be added to the database.
func (*DistroDB) TriggerCleanup ¶
func (db *DistroDB) TriggerCleanup()
TriggerCleanup forces the database cleanup loop to skip its current delay and call autoCleanup immediately. It is blocking until the cleanup starts.