Documentation
¶
Index ¶
- func Ancestors(key string) []string
- func FolderKey(p string) string
- func Key(object *schema.Object) string
- func Link(traceparent string) (trace.Link, bool)
- func MediaType(t string) string
- func ParentKey(key string) string
- func PathOf(key string) (string, bool)
- func PutCacheJSON(ctx context.Context, cache CacheStore, key string, ttl time.Duration, ...) error
- func Revision(object *schema.Object) string
- func Subtree(folder string) (string, string)
- func Traceparent(ctx context.Context) string
- func ValidateFolderKey(key string) error
- func ValidateKey(key string) error
- func ValidateVolume(volume schema.VolumeMeta) error
- func ValidateWork(work Work) error
- type CacheEntry
- type CacheMeta
- type CacheStore
- type Kind
- type ListRequest
- type MetadataStore
- type ObjectStore
- type Opt
- type Opts
- type QueueStore
- type ScanStore
- type SearchStore
- type Seen
- type Store
- type VolumeStore
- type Work
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ancestors ¶
Ancestors returns the keys of the folders above a key, nearest first, so "/a/b.txt" is "/a/" and "/", and the root has none
func Key ¶
Key returns the key of an object, which is its path, or, of a folder, its path with a "/" after it, so the root's is "/". Keys order a folder's objects as S3 does, and as backends list them, so "/a.txt" is before the folder "/a/", which is before "/a0.txt", and a file "/a", and a folder "/a/", which a bucket can have, are two objects.
func Link ¶
Link returns the link to the span of a W3C traceparent, which work which is done is linked to, so it's known what queued it, or false when it's empty, or isn't valid
func MediaType ¶
MediaType returns a type of a listing, without its parameters, in lower case, as schema.MatchType compares it, which has a "/" when it's a media type, and otherwise is a major type, or a subtype, or is empty
func ParentKey ¶
ParentKey returns the key of the folder of a key, which is "/" for the root's objects, and empty for the root
func PathOf ¶
PathOf returns the path of a key, without the "/" after a folder's, unless it's the root, and whether it's a folder's
func PutCacheJSON ¶
func PutCacheJSON(ctx context.Context, cache CacheStore, key string, ttl time.Duration, meta CacheMeta, v any) error
PutCacheJSON stores v, as JSON, as the entry of the key, with its metadata, for the TTL, or until it's replaced, or deleted, when it's zero
func Revision ¶
Revision returns the revision of an object, of a listing: its entity tag, size and modification time, which a listing changes when any of them do, as a bucket's does when only an object's metadata is written, whose entity tag is the same, and whose time is when it was written
func Subtree ¶
Subtree returns the range of the keys beneath a folder's key, which are after it, and before the upper, its path with the byte after "/", which is "0", so "/a/" is to "/a0", which "/ab" isn't in, and "/" is to "0"
func Traceparent ¶
Traceparent returns the W3C traceparent of the context's span, which work which is queued with it keeps, so its work can be linked to it, or empty when it isn't traced
func ValidateFolderKey ¶
ValidateFolderKey returns ErrBadParameter when a key isn't valid (see ValidateKey), or isn't a folder's, which ends with "/"
func ValidateKey ¶
ValidateKey returns ErrBadParameter when a key isn't absolute, and clean, such as "/a/b.txt", or a folder's, "/a/", or the root, "/"
func ValidateVolume ¶
func ValidateVolume(volume schema.VolumeMeta) error
ValidateVolume returns ErrBadParameter when a volume's name isn't an identifier, or it has no URL
func ValidateWork ¶
ValidateWork returns ErrBadParameter when work's key isn't valid (see ValidateKey), its kind is empty, or it's a rescan of a key which isn't a folder's
Types ¶
type CacheEntry ¶
type CacheEntry interface {
io.ReadSeekCloser
io.ReaderAt
// Meta returns what the entry is of
Meta() CacheMeta
// Size returns how many bytes the content is
Size() int64
// Stored returns when it was stored
Stored() time.Time
// Expires returns when it isn't returned, or zero, without a TTL
Expires() time.Time
}
CacheEntry is an entry's content, which can seek, and be read at an offset, as a file can, and what it is
type CacheMeta ¶
type CacheMeta struct {
Version string `json:"version,omitempty"` // Such as a revision, an entity tag, or a page token
Values map[string]string `json:"values,omitempty"` // Small values, such as a feed's Last-Modified
}
CacheMeta is what an entry is of
func GetCacheJSON ¶
GetCacheJSON decodes the entry of the key, which is JSON, into v, and returns what it's of, or ErrNotFound, when there's none, or it expired
type CacheStore ¶
type CacheStore interface {
// Get returns the entry of the key, or ErrNotFound when there's none, or
// it expired. The caller closes it.
Get(ctx context.Context, key string) (CacheEntry, error)
// Put stores the content, as it's read, as the entry of the key, with its
// metadata, for the TTL, or until it's replaced, or deleted, when it's
// zero, replacing any, once it's all read, and returns it, to read back,
// which the caller closes. When the content can't be read, any entry of
// the key is kept.
Put(ctx context.Context, key string, ttl time.Duration, meta CacheMeta, r io.Reader) (CacheEntry, error)
// GetOrCreate is how a backend caches something it fetches, such as a
// Google Doc it exports: it returns the cached entry of the key when
// that's of the version the backend wants, so it isn't fetched again,
// and otherwise fetches it, by calling valuefn, which writes the content
// to w, as it's fetched, and stores it, for the TTL. The entry's
// metadata is what valuefn returns, with the version, unless valuefn
// sets another. When several callers ask for a key at once, valuefn is
// called once, and the others wait for it, so a key is fetched once.
// The caller closes the entry which is returned.
GetOrCreate(ctx context.Context, key, version string, ttl time.Duration, valuefn func(w io.Writer) (CacheMeta, error)) (CacheEntry, error)
// Delete deletes the entry of the key, or every entry beneath it, when it
// ends with "/", such as "export/", which isn't an error when there's
// none. An entry which is being read is deleted once it's closed.
Delete(ctx context.Context, key string) error
}
CacheStore keeps what a volume's backend gets from a service, by key, on disk, so it isn't kept in memory, nor got again after a restart. An entry is kept for its TTL, or until it's replaced, or deleted, or the volume changes, when the registry deletes the store. A backend gets its volume's store as an argument, which it uses, or not, and must work without any of its entries, so an entry is never the only copy of anything. It's safe to use from more than one goroutine.
type ListRequest ¶
type ListRequest struct {
Parent string // The folder's key, such as "/", or "/a/"
Recursive bool // Every object beneath it, rather than its own
After string // The key of the last object returned, or empty
Limit int // The most objects returned, or zero for every one
Type string // Only objects of this type, its major type, or its subtype, or empty for every one
Objects bool // Only objects, without folders, of their keys, whatever their types
}
ListRequest is a request for the objects of a folder
type MetadataStore ¶
type MetadataStore interface {
// SetMetadata replaces what a task found of the object of the volume of
// the key, of the source, which is the task's kind, such as metadata: its
// metadata, the shapes of where it is, and the times of its events, or
// returns ErrNotFound when the object isn't indexed, or ErrBadParameter
// when a shape, or an occurrence, isn't valid. A shape, or occurrence,
// which is the same as another is stored once. When of isn't nil,
// it's of the version of the object which the task read, its
// attributes, so a task which is superseded, as the object changed
// since, returns ErrPreconditionFailed, rather than replacing what a
// later one found.
SetMetadata(ctx context.Context, volume, key, source string, of *schema.ObjectAttr, found schema.TaskMeta) error
// DeleteMetadata removes the metadata of the source, a task's kind, of
// every object of the volume, and its shapes, and events, and the state of
// its task: its work, and
// the revisions it was done of, so it's done of every file again, when
// it's done again, such as when a volume isn't enriched any more
DeleteMetadata(ctx context.Context, volume, source string) error
}
MetadataStore is the metadata which tasks find of the objects of volumes' indexes, such as go-metadata's, of each task's kind, its source, which a read of an object merges with the backend's, replacing the backend's of the same namespace and key
type ObjectStore ¶
type ObjectStore interface {
// GetObject returns the object of the volume of the key, with its metadata,
// the backend's, and its tasks', or ErrNotFound when it isn't indexed
GetObject(ctx context.Context, volume, key string) (*schema.Object, error)
// PutObject stores the objects of the volume, replacing those of their keys,
// and the backend's metadata, but not the metadata, or shapes, of tasks,
// unless an object changed, of its entity tag, size or modification
// time, when they're removed, as they're out of date, until its tasks
// are done of it again, or returns ErrNotFound when the volume isn't
// stored
PutObject(ctx context.Context, volume string, objects ...*schema.Object) error
// DeleteObject removes the object of the volume of the key, and, of a folder's,
// every object beneath it, which isn't an error when there's none
DeleteObject(ctx context.Context, volume, key string) error
// ListObjects returns, in the order of their keys, up to the request's limit
// of the objects of a folder, or every object beneath it when it's
// recursive, after the key it starts after, without the folder, and of
// its type, when it has one (see schema.MatchType)
ListObjects(ctx context.Context, volume string, req ListRequest) ([]*schema.Object, error)
// CountObjects returns how many objects a listing has, of every page, without
// the key it starts after, or its limit
CountObjects(ctx context.Context, volume string, req ListRequest) (uint64, error)
// Kinds returns how many objects, without folders, of a volume are of each
// kind, of their metadata's metadata:kind, a task's rather than the
// backend's, or else of their media type, without its parameters, or "",
// of none
Kinds(ctx context.Context, volume string) (map[string]uint64, error)
// Revisions returns, by their keys, the revisions of the files of a
// folder, or of every file beneath it, when it's recursive, which are
// what the backend's listing said of them (see Revision) when they were
// stored, so a listing which says the same of a file needn't get it
// again. A file which is put again, or deleted, has none, until it's
// set again.
Revisions(ctx context.Context, volume, folder string, recursive bool) (map[string]string, error)
// SetRevisions stores the revisions of the files, by their keys, or
// returns ErrNotFound when the volume isn't stored
SetRevisions(ctx context.Context, volume string, revisions map[string]string) error
}
ObjectStore is the objects of volumes' indexes, by their keys, with the backend's metadata, and the revisions of their listings. Folders are indexed first, and their files later, so an object is a folder, or a file, which a bucket can have of the same path, as their keys differ (see Key).
type Opt ¶
Opt is an option of a store
func WithBroadcaster ¶
func WithBroadcaster(b *broadcaster.Broadcaster) Opt
WithBroadcaster publishes changes to the store's volumes, once they're committed, to the broadcaster: when one is created, updated, which is when its URL, or whether it's enabled, changes, or deleted
func WithTracer ¶
WithTracer traces the store's queries, which a nil tracer doesn't
type Opts ¶
type Opts struct {
// The OpenTelemetry tracer, of a span of each query, or nil
Tracer trace.Tracer
// The broadcaster, which changes to the volumes are published to, so
// they're watched, such as of those added by another server, or nil.
// A store publishes a change when a volume is created, updated or
// deleted, of schema.VolumeChange.
Broadcaster *broadcaster.Broadcaster
}
Opts are the options of a store, which each store's New is given
type QueueStore ¶
type QueueStore interface {
// Push queues work of the volume, which is coalesced: work of the same
// key and kind is queued once, due at the earlier of the two, so work
// which is pushed again and again isn't put off, and an index of a key,
// or a rescan, beneath a rescan of a folder which is queued isn't, as
// the rescan does it, and a rescan of a folder replaces the index and
// rescan work beneath it. A rescan of the root is a catch-up, of changes
// which can have been missed, which doesn't hold up reads (see Pending),
// so it doesn't replace work beneath it, nor is work of it, as the index
// of a change, and a rescan of a folder, which can have absorbed one, do.
// Returns ErrNotFound when the volume isn't stored.
Push(ctx context.Context, volume string, work ...Work) error
// Claim leases, until the lease has passed, the work of the volume, of the
// kinds, which is due, and isn't leased, earliest first: a rescan, on its
// own, or up to max of the other kinds
Claim(ctx context.Context, volume string, kinds []Kind, max int, lease time.Duration) ([]Work, error)
// Done removes the work, which is claimed, unless it's pushed again
// since, when it's kept, so it's claimed again. Work of a task, such as
// KindMetadata, records the revision of the file it was done of, its
// listing's when it was claimed (see Revision), so it isn't done again
// until it changes, and a file which changed while it was done is stale
// (see PushStale). A task's work which has an error is given up, which
// is kept, of the revision, until it changes (see Tasks).
Done(ctx context.Context, volume string, work ...Work) error
// PushStale queues the work of a task, such as KindMetadata, of the
// files beneath the folder's key which are indexed, whose listings'
// revisions aren't those the task was last done of, as they're new, or
// changed, or the task hasn't been done of them, including those which
// have no revision, such as one which is stored of a change, which is
// due now, and isn't queued again when it's queued
PushStale(ctx context.Context, volume, folder string, kind Kind) error
// Tasks returns the state of the work of a task, such as KindMetadata, of
// the volume's files: how many are queued, how many it's done of, and
// of those, how many it gave up, which Done is given the error of, and
// why it last failed
Tasks(ctx context.Context, volume string, kind Kind) (schema.TaskState, error)
// Failed counts an attempt of the work, which is claimed, with why it
// failed, and makes it due again after the retry. A failure of
// gofiler.ErrServiceUnavailable, as the backend is unavailable, is
// counted as an outage, rather than an attempt.
Failed(ctx context.Context, volume string, work Work, err error, retry time.Duration) error
// Pending returns true when the key has work queued, or claimed, which
// would change its index: an index, or a rescan, of it, or of a folder
// above it, so the index of it can be out of date, but not a rescan of
// the root, which is a catch-up, which the index is served while it's
// done
Pending(ctx context.Context, volume, key string) (bool, error)
// PendingBeneath returns true when the folder's key has work queued, or
// claimed, which would change its listing: work which Pending is true
// of, or an index, or a rescan, of a key beneath it, so the index of
// what's beneath it can be out of date
PendingBeneath(ctx context.Context, volume, folder string) (bool, error)
}
QueueStore is the queue of the work of indexing volumes, of their objects' state, which outlasts a restart, so it continues. It's safe to use from more than one goroutine, and process, as work is leased when it's claimed.
type ScanStore ¶
type ScanStore interface {
// Seen records the keys which a scan has seen, with the revisions of
// their listings (see Revision), which a folder's is empty, or returns
// ErrNotFound when the volume isn't stored
Seen(ctx context.Context, volume string, seen map[string]string) error
// Unsee forgets what a scan has seen beneath the folder's key
Unsee(ctx context.Context, volume, folder string) error
// Sweep removes the objects beneath the folder's key, with their
// metadata, which a scan of it hasn't seen
Sweep(ctx context.Context, volume, folder string) error
// Changed returns, in the order of their keys, after the key, up to the
// limit, the files beneath the folder's key which a scan of it has seen,
// which aren't indexed, or whose revisions aren't those they were
// stored of (see Revisions), so they're got again
Changed(ctx context.Context, volume, folder, after string, limit int) ([]Seen, error)
// CountChanged returns how many files Changed returns, of every page
CountChanged(ctx context.Context, volume, folder string) (uint64, error)
}
ScanStore keeps what a scan of a folder of a volume has seen, of the backend's listing, so a volume's objects aren't held in memory while it's scanned, which the scan sweeps the index of, and compares the index's files with. A volume is scanned one folder at a time, by one worker, so what's seen beneath a folder is of its scan: the indexer of a volume is its only worker, as a volume is indexed by one process. A store which is shared by processes, such as Postgres, needs a lock of a volume's scans (#72).
type SearchStore ¶
type SearchStore interface {
// Search returns the objects of the query's volumes, or of every volume,
// without any, which match the request's query, best first, with their
// volumes' names, of its page, and how many match, of every page, which
// is none of a query without terms
Search(ctx context.Context, req schema.SearchRequest) (*schema.SearchResponse, error)
}
SearchStore is the search of the objects of volumes' indexes, of their names, folders, and metadata (see schema.Query)
type Seen ¶
Seen is a file which a scan has seen, which has changed, with the revision of its listing, and whether it's indexed
type Store ¶
type Store interface {
VolumeStore
ObjectStore
MetadataStore
QueueStore
ScanStore
SearchStore
// State returns the state of the volume's index, which is IndexStatusNone
// when it's never been indexed
State(ctx context.Context, volume string) (schema.IndexState, error)
// SetState stores the state of the volume's index, or returns
// ErrNotFound when the volume isn't stored
SetState(ctx context.Context, volume string, state schema.IndexState) error
}
Store is where volumes, and their indexes, are kept: the volumes, the objects of volumes, by their keys, the metadata tasks find of them, the work of indexing them, and the state of each volume's index. A volume's objects, and its state, are stored once it's been created. It's safe to use from more than one goroutine.
type VolumeStore ¶
type VolumeStore interface {
// CreateVolume stores a new volume, and returns it, with when it was
// created, or returns ErrConflict when a volume of its name is stored
CreateVolume(ctx context.Context, volume schema.VolumeMeta) (*schema.Volume, error)
// UpdateVolume replaces a stored volume's URL, and whether it's enabled,
// keeping its index, and returns it, or returns ErrNotFound when it
// isn't stored. It's only modified when they change.
UpdateVolume(ctx context.Context, volume schema.VolumeMeta) (*schema.Volume, error)
// GetVolume returns a volume, or ErrNotFound
GetVolume(ctx context.Context, name string) (*schema.Volume, error)
// ListVolumes returns the volumes, in the order of their names
ListVolumes(ctx context.Context) ([]*schema.Volume, error)
// DeleteVolume removes a volume, with its index, or returns ErrNotFound
DeleteVolume(ctx context.Context, name string) error
}
VolumeStore is where the volumes are kept, so they outlast a restart, which mounts those which are enabled. It's safe to use from more than one goroutine.
type Work ¶
type Work struct {
Key string `json:"key"`
Kind Kind `json:"kind"`
After time.Time `json:"after,omitzero"` // When it's due, which is now when it's pushed without one
Attempts uint `json:"attempts,omitzero"` // How many times it failed, apart from outages
Outages uint `json:"outages,omitzero"` // How many times it failed as its backend was unavailable
Error string `json:"error,omitempty"` // Why it last failed
Leased time.Time `json:"leased,omitzero"` // Until when it's leased, of a claim, which Done and Failed are of
Revision string `json:"revision,omitempty"` // Of a task's work which is claimed, the revision of the file's listing, which it's done of
Trace string `json:"trace,omitempty"` // The W3C traceparent of the span which queued it, of the context it's pushed with by default
}
Work is the work of a key of a volume: of a file, or of a folder, whose key ends with "/"
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pg is an index store in a Postgres database, which isn't implemented yet (#72): each of its methods returns ErrNotImplemented
|
Package pg is an index store in a Postgres database, which isn't implemented yet (#72): each of its methods returns ErrNotImplemented |
|
Package sqlite is a store of volumes, and their indexes, in a SQLite database, which is created when it doesn't exist, or in memory, of sqlite.Memory, such as for tests
|
Package sqlite is a store of volumes, and their indexes, in a SQLite database, which is created when it doesn't exist, or in memory, of sqlite.Memory, such as for tests |
|
schema
Package schema is the schema of the SQLite store: its tables, its queries, and the types which are read from, and written to, them
|
Package schema is the schema of the SQLite store: its tables, its queries, and the types which are read from, and written to, them |
|
Package test is the conformance tests of an index store, which each store runs, so they behave the same
|
Package test is the conformance tests of an index store, which each store runs, so they behave the same |