Documentation
¶
Index ¶
- func ConfigHash(linkingToKeys map[string]string) string
- func IngestContext(descPath string, lf *Lockfile) (configHash string, linkingToKeys map[string]string, sourceCompiled bool, ...)
- func ParseDCF(path string) (map[string]string, error)
- func PlatformFromLockfile(lf *Lockfile) string
- func ReadPackageManifest(libDir string) (map[string]string, error)
- func ReadStoreManifest(path string) (map[string]string, error)
- func RecoverPlatform(storePath string) string
- func SpawnEvictionSweeper(ctx context.Context, store *Store, retention time.Duration)
- func SplitStoreRef(ref string) (sourceHash, configHash string, err error)
- func StoreKey(entry LockfileEntry) (string, error)
- func StoreRef(sourceHash, configHash string) string
- func UpdatePackageManifest(libDir string, additions map[string]string) error
- func WriteConfigMeta(path string, meta ConfigMeta) error
- func WritePackageManifest(libDir string, manifest map[string]string) error
- func WriteStoreConfigs(path string, sc StoreConfigs) error
- func WriteStoreManifest(dir string, manifest map[string]string) error
- type ConfigMeta
- type Lockfile
- type LockfileEntry
- type LockfileMetadata
- type PopulateStats
- type Store
- func (s *Store) Acquire(ctx context.Context, pkg, sourceHash string, staleThreshold time.Duration) error
- func (s *Store) AssembleLibrary(libDir string, storeManifest map[string]string) (missing []string, err error)
- func (s *Store) CleanupStagingDir(dir string) error
- func (s *Store) CleanupWorkerLib(workerID string) error
- func (s *Store) ConfigMetaPath(pkg, sourceHash, configHash string) string
- func (s *Store) ConfigsPath(pkg, sourceHash string) string
- func (s *Store) CreateStagingDir() (string, error)
- func (s *Store) EvictStale(ctx context.Context, retention time.Duration) (int, error)
- func (s *Store) Has(pkg, sourceHash, configHash string) bool
- func (s *Store) Ingest(pkg, sourceHash, configHash, srcDir string) error
- func (s *Store) IngestPackages(ctx context.Context, lf *Lockfile, lib string, refManifest map[string]string) (map[string]string, error)
- func (s *Store) LockPath(pkg, sourceHash string) string
- func (s *Store) Path(pkg, sourceHash, configHash string) string
- func (s *Store) Platform() string
- func (s *Store) PopulateBuild(lf *Lockfile, lib string, refManifest map[string]string) (PopulateStats, error)
- func (s *Store) PopulateRuntime(lf *Lockfile, lib, refLib string, refManifest map[string]string) (PopulateStats, error)
- func (s *Store) Release(pkg, sourceHash string)
- func (s *Store) ResolveConfig(pkg, sourceHash string, lf *Lockfile) (configHash string, ok bool)
- func (s *Store) Root() string
- func (s *Store) SetPlatform(p string)
- func (s *Store) SourceDir(pkg, sourceHash string) string
- func (s *Store) Touch(pkg, sourceHash, configHash string)
- func (s *Store) WorkerLibDir(workerID string) string
- func (s *Store) WriteIngestMeta(entry LockfileEntry, lf *Lockfile, sourceHash, configHash string, ...) error
- type StoreConfigs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigHash ¶
ConfigHash computes the config hash from a LinkingTo dependency map. Entries are sorted by package name to ensure deterministic output. An empty map produces the canonical empty config hash.
func IngestContext ¶
func IngestContext( descPath string, lf *Lockfile, ) (configHash string, linkingToKeys map[string]string, sourceCompiled bool, linkingToNames []string, err error)
IngestContext extracts compile-time context from an installed package's DESCRIPTION and computes the config hash from the lockfile. Returns the config hash, LinkingTo store key map, source_compiled flag, and sorted LinkingTo package names.
func PlatformFromLockfile ¶
PlatformFromLockfile derives the platform prefix from a pak lockfile. Uses per-package fields (short form) rather than top-level fields (which contain long human-readable strings like "R version 4.5.2 (2025-10-31)").
func ReadPackageManifest ¶
ReadPackageManifest reads the per-worker package manifest.
func ReadStoreManifest ¶
ReadStoreManifest reads a store-manifest from the given path. The path should be the full file path (e.g., "{bundle}/store-manifest.json").
func RecoverPlatform ¶
RecoverPlatform scans the store root for existing platform directories (e.g., "4.5-x86_64-pc-linux-gnu/") to restore the platform after a server restart.
func SpawnEvictionSweeper ¶
SpawnEvictionSweeper starts a background goroutine that periodically evicts stale store entries.
func SplitStoreRef ¶
SplitStoreRef splits a compound store ref "sourceHash/configHash" into its two components. Returns an error if the ref is malformed.
func StoreKey ¶
func StoreKey(entry LockfileEntry) (string, error)
StoreKey computes the curated hash for a pak lockfile entry. The hash is SHA-256 of a NUL-delimited string of identity fields.
Hash input format:
{RemoteType}\0{field1}\0{field2}[...\0{fieldN}]
func StoreRef ¶
StoreRef returns a compound "sourceHash/configHash" string for use in the per-worker package manifest (.packages.json).
func UpdatePackageManifest ¶
UpdatePackageManifest adds entries to the per-worker package manifest. Existing entries are preserved; additions overwrite on key collision.
func WriteConfigMeta ¶
func WriteConfigMeta(path string, meta ConfigMeta) error
WriteConfigMeta writes a per-config sidecar file.
func WritePackageManifest ¶
WritePackageManifest writes a per-worker package manifest to libDir.
func WriteStoreConfigs ¶
func WriteStoreConfigs(path string, sc StoreConfigs) error
WriteStoreConfigs atomically writes configs.json via write-to-temp + rename.
Types ¶
type ConfigMeta ¶
ConfigMeta represents the per-config sidecar file.
type Lockfile ¶
type Lockfile struct {
LockfileVersion int `json:"lockfile_version"`
RVersion string `json:"r_version"` // "R version 4.5.2 (2025-10-31)"
OS string `json:"os"` // "Ubuntu 24.04.2 LTS" (human-readable)
Platform string `json:"platform"` // "x86_64-pc-linux-gnu" (R triple)
Packages []LockfileEntry `json:"packages"`
}
Lockfile is the top-level pak lockfile structure.
func ReadLockfile ¶
ReadLockfile reads and validates a pak lockfile from the given path.
type LockfileEntry ¶
type LockfileEntry struct {
Package string `json:"package"`
Version string `json:"version"`
Type string `json:"type"` // "standard", "github", etc.
NeedsCompilation bool `json:"needscompilation"`
Metadata LockfileMetadata `json:"metadata"`
SHA256 string `json:"sha256"` // archive hash (top-level)
Platform string `json:"platform"` // per-pkg R triple, e.g. "x86_64-pc-linux-gnu"
RVersion string `json:"rversion"` // per-pkg short R version, e.g. "4.5"
}
LockfileEntry is a single package record from the pak lockfile.
func (LockfileEntry) IsMetaEntry ¶
func (e LockfileEntry) IsMetaEntry() bool
IsMetaEntry reports whether this lockfile entry is a pak pseudo-package (e.g. "deps::/app") rather than a real package. Meta-entries are skipped during validation and store operations.
func (LockfileEntry) Validate ¶
func (e LockfileEntry) Validate() error
Validate checks that a lockfile entry has the fields needed for store key computation and platform detection. Meta-entries (deps, local, installed) are skipped.
type LockfileMetadata ¶
type LockfileMetadata struct {
RemoteType string `json:"RemoteType"`
RemoteSha string `json:"RemoteSha"`
RemoteSubdir string `json:"RemoteSubdir,omitempty"`
}
LockfileMetadata holds the nested metadata object from a pak lockfile entry. Only the fields needed for store key computation are mapped.
type PopulateStats ¶
PopulateStats reports cache hit/miss counts from a populate run.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a content-addressable package store keyed by {platform}/{package}/{source_hash}/{config_hash}.
func (*Store) Acquire ¶
func (s *Store) Acquire(ctx context.Context, pkg, sourceHash string, staleThreshold time.Duration) error
Acquire takes a file-based lock for a package source hash. Blocks with jittered backoff until the lock is acquired or the context is cancelled. Stale locks older than staleThreshold are removed and re-attempted.
func (*Store) AssembleLibrary ¶
func (s *Store) AssembleLibrary( libDir string, storeManifest map[string]string, ) (missing []string, err error)
AssembleLibrary creates a library directory by hard-linking packages from the store based on a pre-computed store-manifest. After linking, it writes a .packages.json manifest initialized as a copy of the store-manifest.
func (*Store) CleanupStagingDir ¶
CleanupStagingDir removes a staging directory.
func (*Store) CleanupWorkerLib ¶
CleanupWorkerLib removes a worker's library directory.
func (*Store) ConfigMetaPath ¶
ConfigMetaPath returns the config sidecar file path.
func (*Store) ConfigsPath ¶
ConfigsPath returns the path to configs.json for a source hash.
func (*Store) CreateStagingDir ¶
CreateStagingDir creates a staging directory under the store root. Used by runtime package installation to provide a working directory on the same filesystem as the store (enabling atomic rename and hardlinks).
func (*Store) EvictStale ¶
EvictStale removes config entries whose sidecar mtime is older than the retention cutoff. Returns the number of configs removed.
func (*Store) Ingest ¶
Ingest atomically moves an installed package tree into the store as a config entry. No-op if the config already exists. srcDir must be on the same filesystem as the store (for atomic rename).
func (*Store) IngestPackages ¶
func (s *Store) IngestPackages(ctx context.Context, lf *Lockfile, lib string, refManifest map[string]string) (map[string]string, error)
IngestPackages iterates over lockfile entries, ingests any new or changed packages into the store, and returns the complete store-manifest map. Packages already present in refManifest with matching compound refs are skipped. Remaining refManifest entries are carried forward so the manifest is complete for container transfer.
func (*Store) PopulateBuild ¶
func (s *Store) PopulateBuild( lf *Lockfile, lib string, refManifest map[string]string, ) (PopulateStats, error)
PopulateBuild is the standard build-time populate: for each lockfile entry, check the store for a matching config and hardlink hits into the build library.
func (*Store) PopulateRuntime ¶
func (s *Store) PopulateRuntime( lf *Lockfile, lib, refLib string, refManifest map[string]string, ) (PopulateStats, error)
PopulateRuntime extends the build-time populate with worker library pre-population and the reverse-LinkingTo ABI check. After this function, the staging directory contains a complete library minus packages that need ABI recompilation.
func (*Store) ResolveConfig ¶
ResolveConfig reads configs.json for a package's source hash and returns the config hash that matches the current lockfile's LinkingTo store keys. Returns ("", false) if no matching config exists (miss) or if configs.json doesn't exist (never seen).
func (*Store) SetPlatform ¶
func (*Store) Touch ¶
Touch updates the mtime of a config's sidecar file. Used for last-accessed tracking — the eviction sweeper removes config entries whose sidecar mtime exceeds the retention window.
func (*Store) WorkerLibDir ¶
WorkerLibDir returns the host-side library directory for a worker.
func (*Store) WriteIngestMeta ¶
func (s *Store) WriteIngestMeta( entry LockfileEntry, lf *Lockfile, sourceHash, configHash string, linkingToKeys map[string]string, sourceCompiled bool, linkingToNames []string, ) error
WriteIngestMeta writes the config sidecar and updates configs.json for a newly ingested package config.
type StoreConfigs ¶
type StoreConfigs struct {
SourceCompiled bool `json:"source_compiled"`
LinkingTo []string `json:"linkingto"`
Configs map[string]map[string]string `json:"configs"`
}
StoreConfigs represents the configs.json file at the source-hash level.
func ReadStoreConfigs ¶
func ReadStoreConfigs(path string) (StoreConfigs, error)
ReadStoreConfigs reads a configs.json file.