store

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

This package defines the Store interfaces for reading and writing bundles (or any artifact data) to some underlying system, and Store implementations.

Index

Constants

View Source
const (
	// DefaultTTLKey is primarily used for communicating ttl(RFC1123) over http.
	DefaultTTLKey string = "x-scoot-expires"
	// DefaultTTLFormat is to specify the format for parsing ttl(RFC1123).
	DefaultTTLFormat string = time.RFC1123
)
View Source
const DefaultHttpTries = 7 // ~2min total of trying with exponential backoff (0 and 1 both mean 1 try total)

Variables

View Source
var DefaultTTL time.Duration = time.Hour * 24 * 180 //180 days. If zero, no ttl will be applied by default.

Functions

func GetDurationTTL

func GetDurationTTL(t *TTLValue) time.Duration

Return a time.Duration based on Now given a TTLValue specifying a fixed time. Returns a zero duration if TTLValue is nil or if duration would be negative.

func MakePesterClient

func MakePesterClient() *pester.Client

Types

type Client

type Client interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

type FakeStore

type FakeStore struct {
	Files sync.Map // map[string][]byte
	TTL   *TTLValue
}

Implements Store. FakeStore just keeps references to data that would be stored

func (*FakeStore) Exists

func (f *FakeStore) Exists(name string) (bool, error)

func (*FakeStore) OpenForRead

func (f *FakeStore) OpenForRead(name string) (*Resource, error)

func (*FakeStore) Root

func (f *FakeStore) Root() string

func (*FakeStore) Write

func (f *FakeStore) Write(name string, resource *Resource) error

type FileStore

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

func MakeFileStore

func MakeFileStore(dir string) (*FileStore, error)

func MakeFileStoreInTemp

func MakeFileStoreInTemp() (*FileStore, error)

Create a fixed dir in tmp. Note: this implementation does not currently support TTL.

func (*FileStore) Exists

func (s *FileStore) Exists(name string) (bool, error)

func (*FileStore) OpenForRead

func (s *FileStore) OpenForRead(name string) (*Resource, error)

func (*FileStore) Root

func (s *FileStore) Root() string

func (*FileStore) Write

func (s *FileStore) Write(name string, resource *Resource) error

type GroupcacheConfig

type GroupcacheConfig struct {
	Name         string
	Memory_bytes int64
	AddrSelf     string
	Endpoint     string
	NodeReqCh    cluster.NodeReqChType
}

Note: Endpoint is concatenated with Name in groupcache internals, and AddrSelf is expected as HOST:PORT.

type NoopStore

type NoopStore struct {
}

Implements Store with no actions being taken on any methods.

func (*NoopStore) Exists

func (f *NoopStore) Exists(name string) (bool, error)

func (*NoopStore) OpenForRead

func (f *NoopStore) OpenForRead(name string) (*Resource, error)

func (*NoopStore) Root

func (f *NoopStore) Root() string

func (*NoopStore) Write

func (f *NoopStore) Write(name string, resource *Resource) error

type PeerFetcher

type PeerFetcher interface {
	Fetch() ([]cluster.Node, error)
}

Called periodically in a goroutine. Must include the current instance among the fetched nodes.

type Resource

type Resource struct {
	io.ReadCloser
	Length   int64
	TTLValue *TTLValue
}

Resource encapsulates a Store resource and embeds an io.ReadCloser around the data Length: length in bytes of data to be read or written TTLValue: TTL value for the resource, or nil if not supporting TTL

func NewResource

func NewResource(rc io.ReadCloser, l int64, ttlv *TTLValue) *Resource

NewResource constructs a new resource.

type Store

type Store interface {
	StoreRead
	StoreWrite
}

Combines read and write operations on store. This is what most of the code will use.

func MakeCustomHTTPStore

func MakeCustomHTTPStore(rootURI string, client Client, ttlc *TTLConfig) Store

func MakeGroupcacheStore

func MakeGroupcacheStore(underlying Store, cfg *GroupcacheConfig, ttlc *TTLConfig, stat stats.StatsReceiver) (Store, http.Handler, error)

Add in-memory caching to the given store.

func MakeHTTPStore

func MakeHTTPStore(rootURI string) Store

type StoreConfig

type StoreConfig struct {
	Store  Store
	TTLCfg *TTLConfig
	Stat   stats.StatsReceiver
}

Encapsulating struct for instances of Stores and accompanying configurations

type StoreRead

type StoreRead interface {
	// Check if the bundle exists. Not guaranteed to be any cheaper than actually reading the bundle.
	Exists(name string) (bool, error)

	// Open the bundle for streaming read. It is the caller's responsibility to call Close().
	OpenForRead(name string) (*Resource, error)

	// Get the base location, like a directory or base URI that the Store writes to
	Root() string
}

Read-only operations on store, limited for now to a couple essential functions.

type StoreWrite

type StoreWrite interface {
	// Does a streaming write of the given bundle. There is no concept of partial writes (partial=failed).
	Write(name string, resource *Resource) error
}

Write operations on store, limited to a one-shot writing operation since bundles are immutable. If ttl config is nil then the store will use its defaults.

type TTLConfig

type TTLConfig struct {
	TTL       time.Duration
	TTLKey    string
	TTLFormat string
}

TTLConfig configures defaults for stores.

type TTLValue

type TTLValue struct {
	TTL    time.Time
	TTLKey string
}

Stores should generally support TTL, at this time httpStore and groupcacheStore implement it.

func GetTTLValue

func GetTTLValue(c *TTLConfig) *TTLValue

Gets a TTLValue based on Now given a TTLConfig, or nil

Jump to

Keyboard shortcuts

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