store

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2016 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package store implements a content-addressable-store on disk. It leverages the `diskv` package to store items in a simple key-value blob store: https://github.com/peterbourgon/diskv

Index

Constants

View Source
const (
	DbFilename = "ql.db"
)

Variables

View Source
var (
	ErrKeyNotFound = errors.New("no image IDs found")
)

Functions

func FileInfoFromHeader

func FileInfoFromHeader(hdr *tar.Header) *fileInfo

func NewHashWriter

func NewHashWriter(w io.Writer) specaci.ArchiveWriter

func RemoveACIInfo added in v0.5.5

func RemoveACIInfo(tx *sql.Tx, blobKey string) error

RemoveACIInfo removes the ACIInfo with the given blobKey.

func RemoveRemote added in v0.5.5

func RemoveRemote(tx *sql.Tx, blobKey string) error

RemoveRemote removes the remote with the given blobKey.

func WriteACIInfo

func WriteACIInfo(tx *sql.Tx, aciinfo *ACIInfo) error

WriteACIInfo adds or updates the provided aciinfo.

func WriteRemote

func WriteRemote(tx *sql.Tx, remote *Remote) error

WriteRemote adds or updates the provided Remote.

Types

type ACIInfo

type ACIInfo struct {
	// BlobKey is the key in the blob/imageManifest store of the related
	// ACI file and is the db primary key.
	BlobKey string
	// Name is the name of the ACI.
	Name string
	// ImportTime is the time this ACI was imported in the store.
	ImportTime time.Time
	// LastUsed is the last time this image was read
	LastUsed time.Time
	// Size is the size in bytes of this image in the store
	Size int64
	// TreeStoreSize is the size in bytes of this image in the tree store
	TreeStoreSize int64
	// Latest defines if the ACI was imported using the latest pattern (no
	// version label was provided on ACI discovery)
	Latest bool
}

ACIInfo is used to store information about an ACI.

func GetACIInfoWithBlobKey added in v0.5.5

func GetACIInfoWithBlobKey(tx *sql.Tx, blobKey string) (*ACIInfo, bool, error)

GetAciInfosWithBlobKey returns the ACIInfo with the given blobKey. found will be false if no aciinfo exists.

func GetACIInfosWithKeyPrefix

func GetACIInfosWithKeyPrefix(tx *sql.Tx, prefix string) ([]*ACIInfo, error)

GetAciInfosWithKeyPrefix returns all the ACIInfos with a blobkey starting with the given prefix.

func GetACIInfosWithName added in v0.8.1

func GetACIInfosWithName(tx *sql.Tx, name string) ([]*ACIInfo, bool, error)

GetAciInfosWithName returns all the ACIInfos for a given name. found will be false if no aciinfo exists.

func GetAllACIInfos added in v0.5.5

func GetAllACIInfos(tx *sql.Tx, sortfields []string, ascending bool) ([]*ACIInfo, error)

GetAllACIInfos returns all the ACIInfos sorted by optional sortfields and with ascending or descending order.

func NewACIInfo

func NewACIInfo(blobKey string, latest bool, t time.Time, size int64, treeStoreSize int64) *ACIInfo

type ACINotFoundError added in v0.9.0

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

ACINotFoundError is returned when an ACI cannot be found by GetACI Useful to distinguish a generic error from an aci not found.

func (ACINotFoundError) Error added in v0.9.0

func (e ACINotFoundError) Error() string

type DB

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

func NewDB

func NewDB(dbdir string) (*DB, error)

func (*DB) Begin

func (db *DB) Begin() (*sql.Tx, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) Do

func (db *DB) Do(fns ...txfunc) error

Do Opens the db, executes DoTx and then Closes the DB

func (*DB) DoTx

func (db *DB) DoTx(fns ...txfunc) error

DoTx executes the provided txfuncs inside a unique transaction. If one of the functions returns an error the whole transaction is rolled back.

func (*DB) Open

func (db *DB) Open() error

type Remote

type Remote struct {
	ACIURL string
	SigURL string
	ETag   string
	// The key in the blob store under which the ACI has been saved.
	BlobKey      string
	CacheMaxAge  int
	DownloadTime time.Time
}

func GetRemote

func GetRemote(tx *sql.Tx, aciURL string) (remote *Remote, found bool, err error)

GetRemote tries to retrieve a remote with the given aciURL. found will be false if remote doesn't exist.

func NewRemote

func NewRemote(aciurl, sigurl string) *Remote

type Store

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

Store encapsulates a content-addressable-storage for storing ACIs on disk.

func NewStore

func NewStore(baseDir string) (*Store, error)

func (*Store) CheckTreeStore

func (s *Store) CheckTreeStore(id string) (string, error)

CheckTreeStore verifies the treestore consistency for the specified id.

func (*Store) Close added in v0.11.0

func (s *Store) Close() error

Close closes a Store opened with NewStore().

func (*Store) Dump

func (s *Store) Dump(hex bool)

func (*Store) GetACI

func (s *Store) GetACI(name types.ACIdentifier, labels types.Labels) (string, error)

GetACI retrieves the ACI that best matches the provided app name and labels. The returned value is the blob store key of the retrieved ACI. If there are multiple matching ACIs choose the latest one (defined as the last one imported in the store). If no version label is requested, ACIs marked as latest in the ACIInfo are preferred.

func (*Store) GetACIInfoWithBlobKey added in v0.10.0

func (s *Store) GetACIInfoWithBlobKey(blobKey string) (*ACIInfo, error)

func (*Store) GetAllACIInfos added in v0.5.5

func (s *Store) GetAllACIInfos(sortfields []string, ascending bool) ([]*ACIInfo, error)

func (*Store) GetImageManifest

func (s *Store) GetImageManifest(key string) (*schema.ImageManifest, error)

GetImageManifest gets the ImageManifest with the specified key.

func (*Store) GetImageManifestJSON added in v0.9.0

func (s *Store) GetImageManifestJSON(key string) ([]byte, error)

GetImageManifestJSON gets the ImageManifest JSON bytes with the specified key.

func (*Store) GetRemote

func (s *Store) GetRemote(aciURL string) (*Remote, bool, error)

GetRemote tries to retrieve a remote with the given ACIURL. found will be false if remote doesn't exist.

func (*Store) GetTreeStoreID added in v0.9.0

func (s *Store) GetTreeStoreID(key string) (string, error)

GetTreeStoreID calculates the treestore ID for the given image key. The treeStoreID is computed as an hash of the flattened dependency tree image keys. In this way the ID may change for the same key if the image's dependencies change.

func (*Store) GetTreeStoreIDs added in v0.9.0

func (s *Store) GetTreeStoreIDs() ([]string, error)

GetTreeStoreIDs returns a slice containing all the treeStore's IDs available (both fully or partially rendered).

func (*Store) GetTreeStorePath

func (s *Store) GetTreeStorePath(id string) string

GetTreeStorePath returns the absolute path of the treestore for the specified id. It doesn't ensure that the path exists and is fully rendered. This should be done calling IsRendered()

func (*Store) GetTreeStoreRootFS

func (s *Store) GetTreeStoreRootFS(id string) string

GetTreeStoreRootFS returns the absolute path of the rootfs in the treestore for specified id. It doesn't ensure that the rootfs exists and is fully rendered. This should be done calling IsRendered()

func (*Store) HashToKey

func (s *Store) HashToKey(h hash.Hash) string

HashToKey takes a hash.Hash (which currently _MUST_ represent a full SHA512), calculates its sum, and returns a string which should be used as the key to store the data matching the hash.

func (*Store) ReadStream

func (s *Store) ReadStream(key string) (io.ReadCloser, error)

func (*Store) RemoveACI added in v0.5.5

func (s *Store) RemoveACI(key string) error

RemoveACI removes the ACI with the given key. It firstly removes the aci infos inside the db, then it tries to remove the non transactional data. If some error occurs removing some non transactional data a StoreRemovalError is returned.

func (*Store) RemoveTreeStore added in v0.5.5

func (s *Store) RemoveTreeStore(id string) error

RemoveTreeStore removes the rendered image in tree store with the given id.

func (*Store) RenderTreeStore

func (s *Store) RenderTreeStore(key string, rebuild bool) (id string, hash string, err error)

RenderTreeStore renders a treestore for the given image key if it's not already fully rendered. Users of treestore should call s.RenderTreeStore before using it to ensure that the treestore is completely rendered. Returns the id and hash of the rendered treestore if it is newly rendered, and only the id if it is already rendered.

func (*Store) ResolveKey

func (s *Store) ResolveKey(key string) (string, error)

ResolveKey resolves a partial key (of format `sha512-0c45e8c0ab2`) to a full key by considering the key a prefix and using the store for resolution. If the key is longer than the full key length, it is first truncated.

func (*Store) ResolveName added in v0.15.0

func (s *Store) ResolveName(name string) ([]string, bool, error)

ResolveName resolves an image name to a list of full keys and using the store for resolution.

func (*Store) TmpDir

func (s *Store) TmpDir() (string, error)

TmpDir creates and returns dir local to the same filesystem as the Store, or any error encountered

func (*Store) TmpFile

func (s *Store) TmpFile() (*os.File, error)

TmpFile returns an *os.File local to the same filesystem as the Store, or any error encountered

func (Store) TmpNamedFile added in v0.11.0

func (s Store) TmpNamedFile(name string) (*os.File, error)

TmpNamedFile returns an *os.File with the specified name local to the same filesystem as the Store, or any error encountered. If the file already exists it will return the existing file in read/write mode with the cursor at the end of the file.

func (*Store) UpdateSize added in v0.14.0

func (s *Store) UpdateSize(key string, newSize int64) error

func (*Store) UpdateTreeStoreSize added in v0.14.0

func (s *Store) UpdateTreeStoreSize(key string, newSize int64) error

func (*Store) WriteACI

func (s *Store) WriteACI(r io.ReadSeeker, latest bool) (string, error)

WriteACI takes an ACI encapsulated in an io.Reader, decompresses it if necessary, and then stores it in the store under a key based on the image ID (i.e. the hash of the uncompressed ACI) latest defines if the aci has to be marked as the latest. For example an ACI discovered without asking for a specific version (latest pattern).

func (*Store) WriteRemote

func (s *Store) WriteRemote(remote *Remote) error

WriteRemote adds or updates the provided Remote.

type StoreRemovalError added in v0.5.5

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

StoreRemovalError defines an error removing a non transactional store (like a diskv store or the tree store). When this happen there's the possibility that the store is left in an unclean state (for example with some stale files).

func (*StoreRemovalError) Error added in v0.5.5

func (e *StoreRemovalError) Error() string

type TreeStore

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

TreeStore represents a store of rendered ACIs

func (*TreeStore) Check

func (ts *TreeStore) Check(id string) (string, error)

Check calculates the actual rendered ACI's hash and verifies that it matches the saved value. Returns the calculated hash.

func (*TreeStore) GetImageHash added in v0.14.0

func (ts *TreeStore) GetImageHash(id string) (string, error)

GetImageHash returns the hash of the image that uses the tree store identified by id.

func (*TreeStore) GetPath

func (ts *TreeStore) GetPath(id string) string

GetPath returns the absolute path of the treestore for the provided id. It doesn't ensure that the path exists and is fully rendered. This should be done calling IsRendered()

func (*TreeStore) GetRootFS

func (ts *TreeStore) GetRootFS(id string) string

GetRootFS returns the absolute path of the rootfs for the provided id. It doesn't ensure that the rootfs exists and is fully rendered. This should be done calling IsRendered()

func (*TreeStore) Hash

func (ts *TreeStore) Hash(id string) (string, error)

Hash calculates an hash of the rendered ACI. It uses the same functions used to create a tar but instead of writing the full archive is just computes the sha512 sum of the file infos and contents.

func (*TreeStore) IsRendered

func (ts *TreeStore) IsRendered(id string) (bool, error)

IsRendered checks if the tree store with the provided id is fully rendered

func (*TreeStore) Remove

func (ts *TreeStore) Remove(id string, s *Store) error

Remove cleans the directory for the provided id

func (*TreeStore) Size added in v0.14.0

func (ts *TreeStore) Size(id string) (int64, error)

Size returns the size of the rootfs for the provided id. It is a relatively expensive operation, it goes through all the files and adds up their size.

func (*TreeStore) Write

func (ts *TreeStore) Write(id string, key string, s *Store) (string, error)

Write renders the ACI with the provided key in the treestore. id references that specific tree store rendered image. Write, to avoid having a rendered ACI with old stale files, requires that the destination directory doesn't exist (usually Remove should be called before Write)

Jump to

Keyboard shortcuts

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