indexer

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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
)
View Source
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

type Indexer struct {
	gofiler.Filer
	// contains filtered or unexported fields
}

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

func New(name string, backend gofiler.Filer, s store.Store, opts ...Opt) (*Indexer, error)

New returns an indexer of the volume's backend, whose index is in the store, which Run builds, and maintains

func (*Indexer) Actions

func (self *Indexer) Actions() []gofiler.Action

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) Backend

func (self *Indexer) Backend() gofiler.Filer

Backend returns the filer which is indexed

func (*Indexer) Clone

func (self *Indexer) Clone(ctx context.Context, patch url.Values) (gofiler.Filer, error)

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

func (self *Indexer) Close() error

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

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

func (self *Indexer) Kinds(ctx context.Context) (map[string]uint64, error)

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

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

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

func (self *Indexer) Metadata(ctx context.Context) (*schema.TaskState, error)

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) Mode

func (self *Indexer) Mode() Mode

Mode returns what's indexed, such as ModeFolders

func (*Indexer) Readonly

func (self *Indexer) Readonly() bool

Readonly returns true when the backend says its objects can't be written

func (*Indexer) Revision

func (self *Indexer) Revision() uint64

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

func (self *Indexer) Run(ctx context.Context, logger *slog.Logger) error

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) State

func (self *Indexer) State(ctx context.Context) (schema.IndexState, error)

State returns the state of the index

func (*Indexer) URL

func (self *Indexer) URL() *url.URL

URL returns the backend's URL, with index=folders, as its folders are indexed

func (*Indexer) WatchObjects

func (self *Indexer) WatchObjects(ctx context.Context, ch chan<- schema.Event) error

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)
)

func ParseMode

func ParseMode(value string) (Mode, error)

ParseMode returns the mode of the index option, which is ModeNone when it's empty

func (Mode) Files

func (m Mode) Files() bool

Files returns true when the mode indexes files, as well as folders: of objects, or more

func (Mode) Level

func (m Mode) Level() int

Level returns how much the mode indexes, of each mode including what the one below it does: none is 0, folders 1, objects 2, and metadata 3

type Opt

type Opt func(*opt) error

Opt is an option of an indexer

func WithDebounce

func WithDebounce(debounce time.Duration) Opt

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

func WithMetadataTask(task Task) Opt

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

func WithMode(mode Mode) Opt

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

func WithRescanInterval(interval time.Duration) Opt

WithRescanInterval sets how often a backend which can't be watched is scanned again, which is DefaultRescanInterval

func WithRescanMinInterval

func WithRescanMinInterval(interval time.Duration) Opt

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

func WithRetry(retry time.Duration) Opt

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

func WithTaskWorkers(n int) Opt

WithTaskWorkers sets how many workers do the work of tasks, which is DefaultTaskWorkers

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

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.

Jump to

Keyboard shortcuts

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