storage

package
v0.0.0-...-211e212 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package storage implements storage providers for the cache server.

Index

Constants

This section is empty.

Variables

View Source
var ConfigurationError = errors.New("Configuration Error")
View Source
var ForceExpirationFailedErr = errors.New("failed to force expiration of current object")
View Source
var S3StorageError = errors.New("S3 Storage Error")

Functions

This section is empty.

Types

type ChainStorageProvider

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

ChainStorageProvider is a chained/layered storage provider which queries one or more other storage providers as to increase performance when available. It is assumed that the provider list is sorted in order from fastest to slowest.

func (*ChainStorageProvider) CacheHits

func (sp *ChainStorageProvider) CacheHits() *metrics.CacheHits

func (*ChainStorageProvider) Configure

func (sp *ChainStorageProvider) Configure() error

func (*ChainStorageProvider) Get

func (sp *ChainStorageProvider) Get(
	ctx context.Context,
	key *types.CacheKey,
) (object *types.CacheObject, err error)

func (*ChainStorageProvider) Location

func (*ChainStorageProvider) Put

func (sp *ChainStorageProvider) Put(
	ctx context.Context,
	key *types.CacheKey,
	object *types.CacheObject,
) error

func (*ChainStorageProvider) Query

func (sp *ChainStorageProvider) Query(
	ctx context.Context,
	keys []*types.CacheKey,
) ([]*types.CacheObjectMeta, error)

func (*ChainStorageProvider) UsageInfo

func (sp *ChainStorageProvider) UsageInfo() *metrics.CacheUsage

type ExpirationEntry

type ExpirationEntry struct {
	Hash string
	Date time.Time
}

ExpirationEntry is an entry in the ExpirationHeap.

type ExpirationHeap

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

ExpirationHeap implements a heap that stores the expiration dates of objects. The heap is indexed by the hash of the object. The heap is thread-safe.

func NewExpirationHeap

func NewExpirationHeap() *ExpirationHeap

NewExpirationHeap creates a new ExpirationHeap.

func (*ExpirationHeap) Len

func (h *ExpirationHeap) Len() int

Len returns the number of objects in the heap.

func (*ExpirationHeap) Peek

func (h *ExpirationHeap) Peek() (string, time.Time)

Peek returns the next object in the heap.

func (*ExpirationHeap) Pop

func (h *ExpirationHeap) Pop() *ExpirationEntry

Push adds a new object to the heap.

func (*ExpirationHeap) Push

func (h *ExpirationHeap) Push(hash string, expirationDate time.Time)

Push adds a new object to the heap.

func (*ExpirationHeap) UnderlyingArray

func (h *ExpirationHeap) UnderlyingArray() []*ExpirationEntry

UnderlyingArray returns a copy of the underlying array of the heap. This function should only be used for testing.

type ExpirationNotifier

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

ExpirationNotifier provides an efficient way to monitor the expiration of many objects. It stores expiration dates of objects in a binary heap and only waits for the next expiration event. It is used by the localStorageMonitor to monitor the expiration of objects.

func NewExpirationNotifier

func NewExpirationNotifier() *ExpirationNotifier

func (*ExpirationNotifier) Add

func (e *ExpirationNotifier) Add(hash string, expirationDate time.Time)

func (*ExpirationNotifier) ForceExpiration

func (e *ExpirationNotifier) ForceExpiration() error

func (*ExpirationNotifier) Monitor

func (e *ExpirationNotifier) Monitor(ctx context.Context)

func (*ExpirationNotifier) NextExpiration

func (e *ExpirationNotifier) NextExpiration() (string, time.Time)

func (*ExpirationNotifier) Notify

func (e *ExpirationNotifier) Notify() <-chan string

func (*ExpirationNotifier) WaitAll

func (e *ExpirationNotifier) WaitAll(ctx context.Context)

func (*ExpirationNotifier) WaitOne

func (e *ExpirationNotifier) WaitOne(ctx context.Context)

type LocalStorageProvider

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

func (*LocalStorageProvider) CacheHits

func (p *LocalStorageProvider) CacheHits() *metrics.CacheHits

func (*LocalStorageProvider) Configure

func (p *LocalStorageProvider) Configure() error

func (*LocalStorageProvider) DeleteObjectsClosestToExpiration

func (p *LocalStorageProvider) DeleteObjectsClosestToExpiration()

func (*LocalStorageProvider) Get

func (*LocalStorageProvider) Location

func (*LocalStorageProvider) Put

func (p *LocalStorageProvider) Put(
	ctx context.Context,
	key *types.CacheKey,
	object *types.CacheObject,
) error

func (*LocalStorageProvider) Query

func (p *LocalStorageProvider) Query(
	ctx context.Context,
	keys []*types.CacheKey,
) ([]*types.CacheObjectMeta, error)

func (*LocalStorageProvider) UsageInfo

func (p *LocalStorageProvider) UsageInfo() *metrics.CacheUsage

type S3StorageProvider

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

func (*S3StorageProvider) CacheHits

func (sp *S3StorageProvider) CacheHits() *metrics.CacheHits

func (*S3StorageProvider) Configure

func (sp *S3StorageProvider) Configure() (err error)

func (*S3StorageProvider) Get

func (*S3StorageProvider) Location

func (*S3StorageProvider) Put

func (sp *S3StorageProvider) Put(
	ctx context.Context,
	key *types.CacheKey,
	object *types.CacheObject,
) error

func (*S3StorageProvider) Query

func (sp *S3StorageProvider) Query(
	ctx context.Context,
	keys []*types.CacheKey,
) ([]*types.CacheObjectMeta, error)

func (*S3StorageProvider) UsageInfo

func (sp *S3StorageProvider) UsageInfo() *metrics.CacheUsage

type StorageProvider

type StorageProvider interface {
	// Location should return the location kind of stored data.
	Location() types.StorageLocation
	// Configure should perform any necessary setup procedures that must be
	// completed prior to querying this storage provider.
	Configure() error
	// Put should store the given keyed object.
	Put(context.Context, *types.CacheKey, *types.CacheObject) error
	// Get should return the keyed object if it exists, or return
	// a relevant error if it does not exist.
	Get(context.Context, *types.CacheKey) (*types.CacheObject, error)
	// Query should return object metadata for each key in the provided
	// slice. If any key does not exist, the corresponding element in the
	// resulting slice should be nil. The length of the resulting slice
	// must match exactly with the length of the input slice.
	Query(context.Context, []*types.CacheKey) ([]*types.CacheObjectMeta, error)

	// UsageInfo should calculate and return usage information for the storage
	// provider.
	UsageInfo() *metrics.CacheUsage
	// CacheHits should return information about cache hits and misses.
	CacheHits() *metrics.CacheHits
}

A StorageProvider represents an object capable of storing and retrieving cached data.

func NewChainStorageProvider

func NewChainStorageProvider(
	ctx context.Context,
	providers ...StorageProvider,
) StorageProvider

NewChainStorageProvider creates a new ChainStorageProvider with the given storage providers, which should be sorted in order from fastest to slowest.

func NewLocalStorageProvider

func NewLocalStorageProvider(
	ctx context.Context,
	cfg config.LocalStorageSpec,
) StorageProvider

func NewS3StorageProvider

func NewS3StorageProvider(
	ctx context.Context,
	cfg config.RemoteStorageSpec,
) StorageProvider

func NewVolatileStorageProvider

func NewVolatileStorageProvider(
	ctx context.Context,
	cfg config.VolatileStorageSpec,
) StorageProvider

type VolatileStorageProvider

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

func (*VolatileStorageProvider) CacheHits

func (sp *VolatileStorageProvider) CacheHits() *metrics.CacheHits

func (*VolatileStorageProvider) Configure

func (sp *VolatileStorageProvider) Configure() error

func (*VolatileStorageProvider) Get

func (*VolatileStorageProvider) Location

func (*VolatileStorageProvider) Put

func (*VolatileStorageProvider) Query

func (*VolatileStorageProvider) UsageInfo

func (sp *VolatileStorageProvider) UsageInfo() *metrics.CacheUsage

Jump to

Keyboard shortcuts

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