Documentation
¶
Overview ¶
Package indexer is a filer which wraps another, and keeps an index of its folders, in a Store, which it follows the backend's changes in, so its folder tree is listed from the index, rather than the backend, which can be slow, such as a bucket, or a network mount. With ModeObjects, its files are indexed too, with their attributes, and the backend's metadata, and are got, and listed, from the index, when it's up to date for them, but are read from the backend. The changes are queued in the store, and indexed in the background.
Index ¶
- Constants
- type Indexer
- func (self *Indexer) Actions() []gofiler.Action
- func (self *Indexer) Backend() gofiler.Filer
- func (self *Indexer) Clone(ctx context.Context, patch url.Values) (gofiler.Filer, error)
- func (self *Indexer) Close() error
- func (self *Indexer) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (*schema.Object, error)
- func (self *Indexer) DeleteObjects(ctx context.Context, req schema.DeleteObjectsRequest) (*schema.DeleteObjectsResponse, error)
- func (self *Indexer) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)
- func (self *Indexer) Kinds(ctx context.Context) (map[string]uint64, error)
- func (self *Indexer) ListFolders(ctx context.Context, req schema.ListObjectsRequest) (schema.ListObjectsIterator, error)
- func (self *Indexer) ListObjects(ctx context.Context, req schema.ListObjectsRequest) (schema.ListObjectsIterator, error)
- func (self *Indexer) Metadata(ctx context.Context) (*schema.TaskState, error)
- func (self *Indexer) Mode() Mode
- func (self *Indexer) Readonly() bool
- func (self *Indexer) Revision() uint64
- func (self *Indexer) Run(ctx context.Context, logger *slog.Logger) error
- func (self *Indexer) State(ctx context.Context) (schema.IndexState, error)
- func (self *Indexer) URL() *url.URL
- func (self *Indexer) WatchObjects(ctx context.Context, ch chan<- schema.Event) error
- type MetadataStore
- type Mode
- type Opt
- func WithDebounce(debounce time.Duration) Opt
- func WithMetadataTask(task Task) Opt
- func WithMode(mode Mode) Opt
- func WithRescanInterval(interval time.Duration) Opt
- func WithRescanMinInterval(interval time.Duration) Opt
- func WithRetry(retry time.Duration) Opt
- func WithTaskWorkers(n int) Opt
- func WithTracer(tracer trace.Tracer) Opt
- type Task
Constants ¶
const ( // DefaultRescanInterval is how often a backend which can't be watched, // such as a bucket, is scanned again DefaultRescanInterval = 15 * time.Minute // DefaultDebounce is how long the work of a path waits, for more of it, // which coalesces with it, so a burst of changes is indexed once DefaultDebounce = 250 * time.Millisecond // DefaultRescanMinInterval is how often a folder is rescanned, at most, // so a backend which sends a lot of rescans isn't scanned each time DefaultRescanMinInterval = time.Minute )
const (
// DefaultTaskWorkers is how many workers do the work of tasks
DefaultTaskWorkers = 2
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Indexer ¶
Indexer is a filer of a backend, whose folders are indexed, in a store, by Run, which scans the backend, and follows its changes. Its folders are got, and listed, with ListFolders, from the index, once it's ready. Everything else is the backend's, and writes and deletes through it update the index.
func New ¶
New returns an indexer of the volume's backend, whose index is in the store, which Run builds, and maintains
func (*Indexer) Actions ¶
Actions returns the actions of the backend, which queue the index of the object each creates, changes, or deletes, once it's done, so the index doesn't wait for the backend's watch, or its next scan
func (*Indexer) Clone ¶
Clone returns an indexer of a clone of the backend, with the patch, of the same store, and options, which scans it, when it's run, as an indexer of a backend which is opened again does
func (*Indexer) Close ¶
Close closes the backend, when it holds resources, which its owner, such as the registry, calls, once Run has returned
func (*Indexer) CreateObject ¶
func (self *Indexer) CreateObject(ctx context.Context, req schema.CreateObjectRequest) (*schema.Object, error)
CreateObject writes an object to the backend, and queues the index of it, which updates its folder, and a folder which is created for it
func (*Indexer) DeleteObjects ¶
func (self *Indexer) DeleteObjects(ctx context.Context, req schema.DeleteObjectsRequest) (*schema.DeleteObjectsResponse, error)
DeleteObjects deletes objects of the backend, and queues the index of what's deleted, which updates a folder which is deleted, and its parent
func (*Indexer) GetObject ¶
func (self *Indexer) GetObject(ctx context.Context, req schema.GetObjectRequest) (*schema.Object, error)
GetObject returns an object: a folder, of the index, once it's ready, when the path is a folder's, which ends with "/", or is the root, and a file, of the index, when its files are indexed, and it's up to date, and otherwise the backend's, which resolves a path without one, which can be a file, and a folder, of a bucket. A request which is conditional is the backend's.
func (*Indexer) Kinds ¶
Kinds returns how many of the index's objects, without folders, are of each kind, of their metadata, or else their media type (see store.Store.Kinds), or nil, when its objects aren't indexed, which are counted again only once the index is revised (see Revision), as they're of every object, or kindsRefresh has passed, as they can be changed of another process, such as another server of the store, which doesn't revise it
func (*Indexer) ListFolders ¶
func (self *Indexer) ListFolders(ctx context.Context, req schema.ListObjectsRequest) (schema.ListObjectsIterator, error)
ListFolders lists the folders of a folder, or every folder beneath it, when the request is recursive, after the path it starts after, in the order a backend lists them, from the index, once it's ready, or otherwise from the backend
func (*Indexer) ListObjects ¶
func (self *Indexer) ListObjects(ctx context.Context, req schema.ListObjectsRequest) (schema.ListObjectsIterator, error)
ListObjects lists objects of the index, when its files are indexed, and it's up to date for them (see listIndex), and otherwise of the backend, or, when only its folders are indexed, and the request is only for folders, of their type, inode/directory, or inode, the folders of the index, once it's ready
func (*Indexer) Metadata ¶
Metadata returns the state of the indexing of the metadata of its files, by its task, or nil when it doesn't index them, of index=metadata, with a task (see WithMetadataTask)
func (*Indexer) Revision ¶
Revision returns the revision of the indexer's index, its state, and its queue, of this process, which changes once they're written, so their state needn't be read again while it's the same. It doesn't change when they're written of another process, such as another server of a store.
func (*Indexer) Run ¶
Run indexes the backend's folders, and follows its changes, until the context is cancelled. It watches the backend, and scans it once it's watching, so a change while it scans isn't missed, and scans a folder again when the backend says its changes may have been missed. A backend which can't be watched is scanned again at the rescan interval. When watching fails, it's watched, and scanned, again, after a while, which doubles each time, up to a minute. The changes are queued, in the store, and indexed by a worker, in the background, so the work which is queued when it stops is done when it runs again.
func (*Indexer) WatchObjects ¶
WatchObjects sends the backend's changes, once they're indexed, so the backend is watched once, by Run, until the context is cancelled, or the backend's watch fails, which is its error, so the caller can open it again. The first change is a rescan of the root, and a backend which can't be watched sends one each time it's scanned again.
type MetadataStore ¶
type MetadataStore interface {
// SetMetadata replaces what the task found of the file of the key: its
// metadata, the shapes of where it is, such as where a photo was taken,
// and the times of its events, or returns ErrNotFound when the file
// isn't indexed, or ErrBadParameter when a shape, or an occurrence,
// isn't valid
SetMetadata(ctx context.Context, key string, found schema.TaskMeta) error
}
MetadataStore is where a task stores the metadata it finds of a volume's files, of its kind, which a read of a file merges with the backend's, replacing the backend's of the same namespace and key
type Mode ¶
type Mode string
Mode is what's indexed of a volume
const ( // IndexParam is the option of a volume's URL, of the registry, which is // what's indexed of it, such as index=folders IndexParam = "index" ModeNone Mode = "none" // It isn't indexed ModeFolders Mode = "folders" // Its folders are indexed ModeObjects Mode = "objects" // Its folders, and files, are indexed, with the backend's metadata ModeMetadata Mode = "metadata" // Its folders, and files, are indexed, and its files are enriched with their metadata, of a task (see WithMetadataTask) )
type Opt ¶
type Opt func(*opt) error
Opt is an option of an indexer
func WithDebounce ¶
WithDebounce sets how long the work of a path waits, for more of it, which coalesces with it, which is DefaultDebounce, or zero not to wait
func WithMetadataTask ¶
WithMetadataTask sets the task which enriches a volume's files with their metadata, of ModeMetadata, which reads a file of the backend, and stores what it finds, when it's new, or changed, apart from indexing it
func WithMode ¶
WithMode sets what's indexed, which is ModeFolders, by default, or ModeObjects, of the files too, or ModeMetadata, of the files, which are enriched with their metadata, when a task is set (see WithMetadataTask)
func WithRescanInterval ¶
WithRescanInterval sets how often a backend which can't be watched is scanned again, which is DefaultRescanInterval
func WithRescanMinInterval ¶
WithRescanMinInterval sets how often a folder is rescanned, at most, which is DefaultRescanMinInterval, or zero not to limit it. A rescan which is sooner is deferred until it's due, rather than dropped.
func WithRetry ¶
WithRetry sets how long to wait to watch a backend again, when watching it fails, or to do work again, when it fails, which doubles each time, up to a minute
func WithTaskWorkers ¶
WithTaskWorkers sets how many workers do the work of tasks, which is DefaultTaskWorkers
func WithTracer ¶
WithTracer sets the tracer of the index's work: each change it's told of, each scan it's queued, and each piece of work it does, which is linked to the span which queued it, so it's known where work came from
type Task ¶
type Task func(ctx context.Context, backend gofiler.Filer, store MetadataStore, object *schema.Object) error
Task enriches a file of a volume: it reads the file from the backend, and stores what it finds in the store, of the task's kind, such as its metadata. It returns an error when it fails, when it's done again, after a while, which doubles with each attempt, until it's given up, until the file changes, or ErrBadParameter (of errors.Is) when the file can't be read, as it isn't valid, such as a PDF which is cut short, which is given up at once, as doing it again wouldn't change it. Failures are logged, to the logger which Run is given. The object is the index's.