Documentation
¶
Index ¶
- Variables
- func IsUploadOnly(ctx context.Context) bool
- func MigrateNarInfo(ctx context.Context, locker lock.Locker, db database.Querier, ...) error
- func WithUploadOnly(ctx context.Context) context.Context
- type Cache
- func (c *Cache) AddLRUCronJob(ctx context.Context, schedule cron.Schedule)
- func (c *Cache) AddUpstreamCaches(ctx context.Context, ucs ...*upstream.Cache)
- func (c *Cache) BackgroundMigrateNarToChunks(ctx context.Context, narURL nar.URL)
- func (c *Cache) CheckAndFixNarInfo(ctx context.Context, hash string) error
- func (c *Cache) Close()
- func (c *Cache) DeleteNar(ctx context.Context, narURL nar.URL) error
- func (c *Cache) DeleteNarInfo(ctx context.Context, hash string) error
- func (c *Cache) GetCDCBackgroundWorkers() int
- func (c *Cache) GetCDCLazyChunkingEnabled() bool
- func (c *Cache) GetConfig() *config.Config
- func (c *Cache) GetHealthChecker() *healthcheck.HealthChecker
- func (c *Cache) GetHealthyUpstreamCount() int
- func (c *Cache) GetHealthyUpstreamCountLocked() int
- func (c *Cache) GetHostname() string
- func (c *Cache) GetNar(ctx context.Context, narURL nar.URL) (nar.URL, int64, io.ReadCloser, error)
- func (c *Cache) GetNarFileSize(ctx context.Context, nu nar.URL) (int64, error)
- func (c *Cache) GetNarInfo(ctx context.Context, hash string) (*narinfo.NarInfo, error)
- func (c *Cache) HasNarFileRecord(ctx context.Context, narURL nar.URL) (bool, error)
- func (c *Cache) HasNarInChunks(ctx context.Context, narURL nar.URL) (bool, error)
- func (c *Cache) HasNarInStore(ctx context.Context, narURL nar.URL) bool
- func (c *Cache) MigrateNarInfoToDatabase(ctx context.Context, hash string, ni *narinfo.NarInfo, deleteFromStorage bool) error
- func (c *Cache) MigrateNarToChunks(ctx context.Context, narURL *nar.URL) error
- func (c *Cache) PublicKey() signature.PublicKey
- func (c *Cache) PutNar(ctx context.Context, narURL nar.URL, r io.ReadCloser) error
- func (c *Cache) PutNarInfo(ctx context.Context, hash string, r io.ReadCloser) error
- func (c *Cache) RegisterUpstreamMetrics(m metric.Meter) error
- func (c *Cache) SetCDCConfiguration(enabled bool, minSize, avgSize, maxSize uint32) error
- func (c *Cache) SetCacheSignNarinfo(shouldSignNarinfo bool)
- func (c *Cache) SetChunkStore(cs chunk.Store)
- func (c *Cache) SetMaxSize(maxSize uint64)
- func (c *Cache) SetRecordAgeIgnoreTouch(d time.Duration)
- func (c *Cache) SetTempDir(d string) error
- func (c *Cache) SetupCron(ctx context.Context, timezone *time.Location)
- func (c *Cache) StartCron(ctx context.Context)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrHostnameRequired is returned if the given hostName to New is not given. ErrHostnameRequired = errors.New("hostName is required") // ErrHostnameMustNotContainScheme is returned if the given hostName to New contained a scheme. ErrHostnameMustNotContainScheme = errors.New("hostName must not contain scheme") // ErrHostnameNotValid is returned if the given hostName to New is not valid. ErrHostnameNotValid = errors.New("hostName is not valid") // ErrHostnameMustNotContainPath is returned if the given hostName to New contained a path. ErrHostnameMustNotContainPath = errors.New("hostName must not contain a path") // ErrMigrationInProgress is returned if a migration is already in progress. ErrMigrationInProgress = errors.New("migration is already in progress") // ErrCDCDisabled is returned when CDC is required but not enabled. ErrCDCDisabled = errors.New("CDC must be enabled and chunk store configured for migration") // ErrNarAlreadyChunked is returned when the nar is already chunked. ErrNarAlreadyChunked = errors.New("nar is already chunked") )
Functions ¶
func IsUploadOnly ¶ added in v0.9.0
IsUploadOnly checks if the context specifies skipping upstream checks.
func MigrateNarInfo ¶ added in v0.8.0
func MigrateNarInfo( ctx context.Context, locker lock.Locker, db database.Querier, narInfoStore storage.NarInfoStore, hash string, ni *narinfo.NarInfo, ) error
MigrateNarInfo migrates a single narinfo from storage to the database. It uses distributed locking to coordinate with other instances (if a distributed locker is provided). This function is used both by Cache.MigrateNarInfoToDatabase and the CLI migrate-narinfo command.
Parameters:
- ctx: Context for the operation
- locker: Distributed locker for coordination (can be in-memory for single-instance)
- db: Database querier for storing the narinfo
- narInfoStore: Optional storage backend to delete from after migration (nil to skip deletion)
- hash: The narinfo hash to migrate
- ni: The parsed narinfo to migrate
Returns an error if migration fails. Returns nil if the narinfo is already migrated or if another instance is currently migrating it.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache represents the main cache service.
func New ¶
func New( ctx context.Context, hostName string, db database.Querier, configStore storage.ConfigStore, narInfoStore storage.NarInfoStore, narStore storage.NarStore, secretKeyPath string, downloadLocker lock.Locker, cacheLocker lock.RWLocker, downloadLockTTL time.Duration, downloadPollTimeout time.Duration, cacheLockTTL time.Duration, ) (*Cache, error)
New returns a new Cache.
func (*Cache) AddLRUCronJob ¶ added in v0.0.11
AddLRUCronJob adds a job for LRU.
func (*Cache) AddUpstreamCaches ¶ added in v0.0.11
AddUpstreamCaches adds one or more upstream caches with lazy loading support.
func (*Cache) BackgroundMigrateNarToChunks ¶ added in v0.9.0
BackgroundMigrateNarToChunks migrates a traditional NAR blob to content-defined chunks in the background.
func (*Cache) CheckAndFixNarInfo ¶ added in v0.9.3
checkAndFixNarInfo checks if a NarInfo exists for the given hash, and if so, ensures its FileSize matches the actual NAR size.
func (*Cache) Close ¶ added in v0.8.0
func (c *Cache) Close()
Close waits for all background operations to complete.
func (*Cache) DeleteNarInfo ¶ added in v0.0.4
DeleteNarInfo deletes the narInfo from the store.
func (*Cache) GetCDCBackgroundWorkers ¶ added in v0.9.4
GetCDCBackgroundWorkers returns the number of background workers for lazy chunking. In release 0.9, lazy chunking is not available, so this always returns 0.
func (*Cache) GetCDCLazyChunkingEnabled ¶ added in v0.9.4
GetCDCLazyChunkingEnabled returns whether lazy chunking is enabled. In release 0.9, lazy chunking is not available, so this always returns false.
func (*Cache) GetConfig ¶ added in v0.8.0
GetConfig returns the configuration instance. It's useful for testing the behavior of ncps.
func (*Cache) GetHealthChecker ¶ added in v0.3.0
func (c *Cache) GetHealthChecker() *healthcheck.HealthChecker
GetHealthChecker returns the instance of haelth checker used by the cache. It's useful for testing the behavior of ncps.
func (*Cache) GetHealthyUpstreamCount ¶ added in v0.6.0
GetHealthyUpstreamCount returns the number of healthy upstream caches.
func (*Cache) GetHealthyUpstreamCountLocked ¶ added in v0.9.0
GetHealthyUpstreamCountLocked returns the number of healthy upstream caches. It assumes the caller holds at least a read lock on upstreamCachesMu.
func (*Cache) GetNar ¶
GetNar returns the nar given a hash and compression from the store. If the nar is not found in the store, it's pulled from an upstream, stored in the stored and finally returned. The returned narURL reflects any mutations made during serving (e.g. TransparentZstd cleared when zstd stream not available). NOTE: It's the caller responsibility to close the body.
func (*Cache) GetNarFileSize ¶ added in v0.9.0
GetNarFileSize returns the size of the NAR file from the database if it exists.
func (*Cache) GetNarInfo ¶
GetNarInfo returns the narInfo given a hash from the store. If the narInfo is not found in the store, it's pulled from an upstream, stored in the stored and finally returned.
func (*Cache) HasNarFileRecord ¶ added in v0.9.0
HasNarFileRecord checks if a NAR file record exists in the database, regardless of chunking completion status. This is used for coordination to allow progressive streaming while chunking is in progress.
func (*Cache) HasNarInChunks ¶ added in v0.9.0
HasNarInChunks returns true if the NAR is already in chunks and chunking is complete.
func (*Cache) HasNarInStore ¶ added in v0.9.3
hasNarInStore checks if the NAR exists in the storage, handling the .nar.zst fallback for CompressionTypeNone.
func (*Cache) MigrateNarInfoToDatabase ¶ added in v0.8.0
func (c *Cache) MigrateNarInfoToDatabase( ctx context.Context, hash string, ni *narinfo.NarInfo, deleteFromStorage bool, ) error
MigrateNarInfoToDatabase migrates a single narinfo from storage to the database. It uses distributed locking to coordinate with other instances (if Redis is configured). This is a convenience wrapper around MigrateNarInfo for use within the Cache.
func (*Cache) MigrateNarToChunks ¶ added in v0.9.0
MigrateNarToChunks migrates a traditional NAR blob to content-defined chunks. narURL is taken by pointer because storeNarWithCDC normalizes compression to "none".
func (*Cache) PutNar ¶ added in v0.0.3
PutNar records the NAR (given as an io.Reader) into the store.
func (*Cache) PutNarInfo ¶ added in v0.0.3
PutNarInfo records the narInfo (given as an io.Reader) into the store and signs it.
func (*Cache) RegisterUpstreamMetrics ¶ added in v0.6.0
RegisterUpstreamMetrics register metrics related to upstream caches.
func (*Cache) SetCDCConfiguration ¶ added in v0.9.0
SetCDCConfiguration enables and configures CDC.
func (*Cache) SetCacheSignNarinfo ¶ added in v0.2.0
SetCacheSignNarinfo configure ncps to sign or not sign narinfos.
func (*Cache) SetChunkStore ¶ added in v0.9.0
SetChunkStore sets the chunk store.
func (*Cache) SetMaxSize ¶ added in v0.0.11
SetMaxSize sets the maxsize of the cache. This will be used by the LRU cronjob to automatically clean-up the store.
func (*Cache) SetRecordAgeIgnoreTouch ¶ added in v0.0.6
SetRecordAgeIgnoreTouch changes the duration at which a record is considered up to date and a touch is not invoked.
func (*Cache) SetTempDir ¶ added in v0.3.0
SetTempDir sets the temporary directory.