Documentation
¶
Index ¶
- Constants
- Variables
- func InitLocalCache(dir string) error
- func WriteCacheVersion(dir, ver string) error
- func WriteCacheVersionIfNotPresent(dir string) error
- type CacheOpt
- func BypassCompatCheckOpt() CacheOpt
- func CompressOpt(c Compressor) CacheOpt
- func CreateIfNotExistOpt() CacheOpt
- func ExclusiveLockOpt() CacheOpt
- func FsyncOpt(fsync bool) CacheOpt
- func LevelsOpt(levels int) CacheOpt
- func LogRefStoreOpt() CacheOpt
- func MapStoreOpt() CacheOpt
- func NoObjectCompressionOpt() CacheOpt
- func NotifyPutBlobOpt(f NotifyFunc) CacheOpt
- func NotifyReadOpt(f NotifyFunc) CacheOpt
- func NotifyWriteOpt(f NotifyFunc) CacheOpt
- func PlainEmptyObjectsOpt() CacheOpt
- func ValidateGitHashOpt() CacheOpt
- type CompressMode
- type Compressor
- type Folder
- type LocalCache
- func (c *LocalCache) AddMapResult(ctx context.Context, from entities.Hash, to entities.Hash) error
- func (c *LocalCache) Close() error
- func (c *LocalCache) CompatibleExistingCache() bool
- func (c *LocalCache) GetObject(ctx context.Context, key entities.Hash) ([]byte, error)
- func (c *LocalCache) GetRefs(server string, project string, refs []string) ([]entities.Hash, error)
- func (c *LocalCache) GetTempDir() string
- func (c *LocalCache) GetTree(ctx context.Context, key entities.Hash) ([]byte, entities.TreeMeta, error)
- func (c *LocalCache) HasARI(ctx context.Context, key entities.Hash) (bool, error)
- func (c *LocalCache) HasBlob(ctx context.Context, key entities.Hash) (bool, error)
- func (c *LocalCache) HasCASBlob(ctx context.Context, sha256Hex string) (bool, error)
- func (c *LocalCache) HasObject(ctx context.Context, key entities.Hash) (bool, error)
- func (c *LocalCache) Lock() error
- func (c *LocalCache) MapResults(ctx context.Context, id entities.Hash) ([]entities.Hash, error)
- func (c *LocalCache) MetaPath(ctx context.Context, key entities.Hash, meta string) string
- func (c *LocalCache) MetaSize(ctx context.Context, treeHash entities.Hash) (int64, error)
- func (c *LocalCache) ObjectHeader(ctx context.Context, objectHash entities.Hash) (entities.ObjectHeader, error)
- func (c *LocalCache) OpenARI(ctx context.Context, key entities.Hash) (io.ReadCloser, error)
- func (c *LocalCache) OpenBlob(ctx context.Context, key entities.Hash) (io.ReadCloser, error)
- func (c *LocalCache) OpenObjectFile(ctx context.Context, key entities.Hash) (io.ReadCloser, error)
- func (c *LocalCache) PutObject(ctx context.Context, key entities.Hash, content []byte) error
- func (c *LocalCache) PutRefs(server string, project string, refs []entities.RefHash) error
- func (c *LocalCache) PutTree(ctx context.Context, key entities.Hash, content []byte, meta entities.TreeMeta) error
- func (c *LocalCache) RLock() error
- func (c *LocalCache) ReadExistingCacheVersion() string
- func (c *LocalCache) RefreshMapResults(ctx context.Context, id entities.Hash) error
- func (c *LocalCache) RemoveARI(ctx context.Context, key entities.Hash) error
- func (c *LocalCache) RemoveBlob(ctx context.Context, key entities.Hash) error
- func (c *LocalCache) RemoveMeta(ctx context.Context, key entities.Hash, meta string) error
- func (c *LocalCache) RemoveObject(ctx context.Context, key entities.Hash) error
- func (c *LocalCache) SearchRefs(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)
- func (c *LocalCache) Stat(ctx context.Context, hash entities.Hash) (entities.StatInfo, error)
- func (c *LocalCache) Unlock() error
- func (c *LocalCache) WriteARI(ctx context.Context, key entities.Hash, reader io.Reader) error
- func (c *LocalCache) WriteBlob(ctx context.Context, key entities.Hash, reader io.Reader) error
- func (c *LocalCache) WriteCASBlob(ctx context.Context, sha256Hex string, reader io.Reader) error
- func (c *LocalCache) WriteObject(ctx context.Context, key entities.Hash, reader io.Reader) error
- type LocalStore
- func (c *LocalStore) Get(ctx context.Context, key entities.Hash) (content []byte, retErr error)
- func (c *LocalStore) GetMeta(ctx context.Context, key entities.Hash, meta string) (content []byte, retErr error)
- func (c *LocalStore) GetXAttr(ctx context.Context, key entities.Hash, attr string) (string, error)
- func (c *LocalStore) Has(key entities.Hash) (bool, error)
- func (c *LocalStore) HasHex(hexStr string) bool
- func (c *LocalStore) MetaSize(ctx context.Context, key entities.Hash, meta string) (int64, error)
- func (c *LocalStore) NotifyRead(ctx context.Context, key entities.Hash) error
- func (c *LocalStore) NotifyWrite(ctx context.Context, key entities.Hash) error
- func (c *LocalStore) ObjectHeader(ctx context.Context, key entities.Hash) (hdr entities.ObjectHeader, retErr error)
- func (c *LocalStore) OpenFile(ctx context.Context, id entities.Hash) (io.ReadCloser, error)
- func (c *LocalStore) Path(id entities.Hash) string
- func (c *LocalStore) PathHex(str string) string
- func (c *LocalStore) PathMeta(id entities.Hash, meta string) string
- func (c *LocalStore) Put(ctx context.Context, key entities.Hash, content []byte) error
- func (c *LocalStore) PutFile(ctx context.Context, key entities.Hash, filename string) error
- func (c *LocalStore) PutMeta(ctx context.Context, key entities.Hash, meta string, content []byte) error
- func (c *LocalStore) Remove(key entities.Hash) error
- func (c *LocalStore) RemoveMeta(key entities.Hash, meta string) error
- func (c *LocalStore) Size(ctx context.Context, key entities.Hash) (int64, error)
- func (c *LocalStore) Stat(ctx context.Context, key entities.Hash) (entities.StatInfo, error)
- func (c *LocalStore) Write(ctx context.Context, id entities.Hash, r io.Reader, ...) error
- func (c *LocalStore) WriteHex(ctx context.Context, hexStr string, r io.Reader, ...) error
- type LocalStoreOpts
- type LogRefStore
- func (s *LogRefStore) Close() error
- func (s *LogRefStore) Get(server string, project string, refs []string) ([]entities.Hash, error)
- func (s *LogRefStore) Put(server string, project string, refs []entities.RefHash) error
- func (s *LogRefStore) Search(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)
- type MapStore
- type Notify
- type NotifyFunc
- type RefStore
Constants ¶
const ( CacheVersion = "0.0.5" CacheLockFile = "cache.lock" VersionFile = "version" TreeMetaTag = "tree" )
const ( BlobPrefix = "blobs/" ObjectPrefix = "objects/" MapPrefix = "map/" )
Variables ¶
var ErrHashMismatch = errors.New("content hash did not match provided hash")
var ErrIncompatibleExisting = errors.New("existing cache is not compatible with current version")
Functions ¶
func InitLocalCache ¶
func WriteCacheVersion ¶
Types ¶
type CacheOpt ¶
type CacheOpt interface{}
func BypassCompatCheckOpt ¶
func BypassCompatCheckOpt() CacheOpt
func CompressOpt ¶
func CompressOpt(c Compressor) CacheOpt
CompressOpt also stores blob sizes in an xattr since the size can't be obtained from stat
func CreateIfNotExistOpt ¶
func CreateIfNotExistOpt() CacheOpt
func ExclusiveLockOpt ¶
func ExclusiveLockOpt() CacheOpt
func LogRefStoreOpt ¶
func LogRefStoreOpt() CacheOpt
func MapStoreOpt ¶
func MapStoreOpt() CacheOpt
func NoObjectCompressionOpt ¶
func NoObjectCompressionOpt() CacheOpt
func NotifyPutBlobOpt ¶
func NotifyPutBlobOpt(f NotifyFunc) CacheOpt
func NotifyReadOpt ¶
func NotifyReadOpt(f NotifyFunc) CacheOpt
func NotifyWriteOpt ¶
func NotifyWriteOpt(f NotifyFunc) CacheOpt
func PlainEmptyObjectsOpt ¶
func PlainEmptyObjectsOpt() CacheOpt
func ValidateGitHashOpt ¶
func ValidateGitHashOpt() CacheOpt
type CompressMode ¶
type CompressMode bool
const ( Compressed CompressMode = true Uncompressed CompressMode = false )
type Compressor ¶
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
func (*LocalCache) AddMapResult ¶
AddMapResult implements entities.MapStore
func (*LocalCache) Close ¶
func (c *LocalCache) Close() error
func (*LocalCache) CompatibleExistingCache ¶
func (c *LocalCache) CompatibleExistingCache() bool
func (*LocalCache) GetTempDir ¶
func (c *LocalCache) GetTempDir() string
func (*LocalCache) HasCASBlob ¶
HasCASBlob checks if a CAS blob is already stored locally on disk under the blobs/ directory (e.g. blobs/<sha256[:3]>/<sha256[3:]>) using its 64-character SHA-256 hex string. This fast disk probe avoids redundant network fetch roundtrips to RBE.
func (*LocalCache) Lock ¶
func (c *LocalCache) Lock() error
func (*LocalCache) MapResults ¶
MapResults implements entities.MapStore
func (*LocalCache) ObjectHeader ¶
func (c *LocalCache) ObjectHeader(ctx context.Context, objectHash entities.Hash) (entities.ObjectHeader, error)
func (*LocalCache) OpenARI ¶
func (c *LocalCache) OpenARI(ctx context.Context, key entities.Hash) (io.ReadCloser, error)
func (*LocalCache) OpenBlob ¶
func (c *LocalCache) OpenBlob(ctx context.Context, key entities.Hash) (io.ReadCloser, error)
OpenBlob implements entities.BlobStore
func (*LocalCache) OpenObjectFile ¶
func (c *LocalCache) OpenObjectFile(ctx context.Context, key entities.Hash) (io.ReadCloser, error)
OpenObjectFile implements entities.Object
func (*LocalCache) RLock ¶
func (c *LocalCache) RLock() error
func (*LocalCache) ReadExistingCacheVersion ¶
func (c *LocalCache) ReadExistingCacheVersion() string
func (*LocalCache) RefreshMapResults ¶
func (*LocalCache) RemoveBlob ¶
func (*LocalCache) RemoveMeta ¶
func (*LocalCache) RemoveObject ¶
func (*LocalCache) SearchRefs ¶
func (c *LocalCache) SearchRefs(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)
SearchRefs implements entities.CASStore.
func (*LocalCache) Unlock ¶
func (c *LocalCache) Unlock() error
func (*LocalCache) WriteCASBlob ¶
WriteCASBlob streams and writes a CAS blob directly under the local cache's blobs/ directory using its native SHA-256 hex string (e.g. blobs/<sha256[:3]>/<sha256[3:]>). Storing CAS blobs under this layout lets other consumers (e.g. FUSE passthrough) read them directly, eliminating the need for synthetic SHA-1 derivation, BadgerDB identity-store translation, or dual-key disk probing.
func (*LocalCache) WriteObject ¶
Write implements entities.ObjectStore
type LocalStore ¶
type LocalStore struct {
// contains filtered or unexported fields
}
func NewLocalStore ¶
func NewLocalStore(opts LocalStoreOpts) (*LocalStore, error)
func (*LocalStore) HasHex ¶
func (c *LocalStore) HasHex(hexStr string) bool
HasHex checks if a file exists on disk for the given hex-encoded key.
func (*LocalStore) NotifyRead ¶
func (*LocalStore) NotifyWrite ¶
func (*LocalStore) ObjectHeader ¶
func (c *LocalStore) ObjectHeader(ctx context.Context, key entities.Hash) (hdr entities.ObjectHeader, retErr error)
func (*LocalStore) OpenFile ¶
func (c *LocalStore) OpenFile(ctx context.Context, id entities.Hash) (io.ReadCloser, error)
OpenFile returns a file corresponding to the blob, opened for reading.
func (*LocalStore) Path ¶
func (c *LocalStore) Path(id entities.Hash) string
Path returns the local path from where the file can be read.
func (*LocalStore) PathHex ¶
func (c *LocalStore) PathHex(str string) string
PathHex returns the sharded on-disk filesystem path for a hex-encoded key (supporting arbitrary lengths, such as a 40-character SHA-1 or 64-character SHA-256).
Sharding divides cached files across subdirectories to prevent large directory scaling bottlenecks (e.g., filesystem lookup overhead with hundreds of thousands of files in a single directory).
Examples for levels = 2:
- SHA-1: <dir>/e69/de29bb2d1d6434b8b29ae775ad8c2e48c5391
- SHA-256: <dir>/e3b/0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
func (*LocalStore) RemoveMeta ¶
func (c *LocalStore) RemoveMeta(key entities.Hash, meta string) error
func (*LocalStore) Write ¶
func (c *LocalStore) Write(ctx context.Context, id entities.Hash, r io.Reader, beforeRename func(string) error) error
Write uses the provided reader to write the file contents into the cache at the provided hash. `beforeRename` allows callers to modify the file before it is renamed to its final location.
type LocalStoreOpts ¶
type LocalStoreOpts struct {
Dir string
Levels int
Notify Notify
CompressMode CompressMode
Fsync bool
}
type LogRefStore ¶
type LogRefStore struct {
// contains filtered or unexported fields
}
func NewLogRefStore ¶
func NewLogRefStore(dir string) (*LogRefStore, error)
func (*LogRefStore) Close ¶
func (s *LogRefStore) Close() error
func (*LogRefStore) Search ¶
func (s *LogRefStore) Search(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)
type MapStore ¶
type MapStore struct {
// contains filtered or unexported fields
}
func (*MapStore) AddMapResult ¶
AddMapResult is NOT safe to be run concurrently
type Notify ¶
type Notify struct {
PutFile NotifyFunc
Write NotifyFunc
Read NotifyFunc
}